Merge branch 'bugfix/block-follow-relationships' 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 source: %{
32 note: "",
33 privacy: "public",
34 sensitive: "false"
35 }
36 }
37
38 assert expected == AccountView.render("account.json", %{user: user})
39 end
40
41 test "Represent a smaller mention" do
42 user = insert(:user)
43
44 expected = %{
45 id: to_string(user.id),
46 acct: user.nickname,
47 username: user.nickname,
48 url: user.ap_id
49 }
50
51 assert expected == AccountView.render("mention.json", %{user: user})
52 end
53
54 test "represent a relationship" do
55 user = insert(:user)
56 other_user = insert(:user)
57
58 {:ok, user} = User.follow(user, other_user)
59 {:ok, user} = User.block(user, other_user)
60
61 expected = %{
62 id: to_string(other_user.id),
63 following: false,
64 followed_by: false,
65 blocking: true,
66 muting: false,
67 requested: false,
68 domain_blocking: false
69 }
70
71 assert expected == AccountView.render("relationship.json", %{user: user, target: other_user})
72 end
73 end