Merge branch 'fix/mutes.json-emptyarray' into 'develop'
[akkoma] / test / web / mastodon_api / account_view_test.exs
1 defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
2 use Pleroma.DataCase
3 import Pleroma.Factory
4 alias Pleroma.Web.MastodonAPI.AccountView
5 alias Pleroma.User
6
7 test "Represent a user account" do
8 user =
9 insert(:user, %{
10 info: %{"note_count" => 5, "follower_count" => 3},
11 nickname: "shp@shitposter.club",
12 inserted_at: ~N[2017-08-15 15:47:06.597036]
13 })
14
15 expected = %{
16 id: to_string(user.id),
17 username: "shp",
18 acct: user.nickname,
19 display_name: user.name,
20 locked: false,
21 created_at: "2017-08-15T15:47:06.000Z",
22 followers_count: 3,
23 following_count: 0,
24 statuses_count: 5,
25 note: user.bio,
26 url: user.ap_id,
27 avatar: "http://localhost:4001/images/avi.png",
28 avatar_static: "http://localhost:4001/images/avi.png",
29 header: "http://localhost:4001/images/banner.png",
30 header_static: "http://localhost:4001/images/banner.png",
31 emojis: [],
32 fields: [],
33 source: %{
34 note: "",
35 privacy: "public",
36 sensitive: "false"
37 }
38 }
39
40 assert expected == AccountView.render("account.json", %{user: user})
41 end
42
43 test "Represent a smaller mention" do
44 user = insert(:user)
45
46 expected = %{
47 id: to_string(user.id),
48 acct: user.nickname,
49 username: user.nickname,
50 url: user.ap_id
51 }
52
53 assert expected == AccountView.render("mention.json", %{user: user})
54 end
55
56 test "represent a relationship" do
57 user = insert(:user)
58 other_user = insert(:user)
59
60 {:ok, user} = User.follow(user, other_user)
61 {:ok, user} = User.block(user, other_user)
62
63 expected = %{
64 id: to_string(other_user.id),
65 following: false,
66 followed_by: false,
67 blocking: true,
68 muting: false,
69 requested: false,
70 domain_blocking: false
71 }
72
73 assert expected == AccountView.render("relationship.json", %{user: user, target: other_user})
74 end
75 end