061fc2693544fa596bcd56381c9d95e10db57287
[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 = insert(:user, %{info: %{"note_count" => 5, "follower_count" => 3}, nickname: "shp@shitposter.club", inserted_at: ~N[2017-08-15 15:47:06.597036]})
9
10 expected = %{
11 id: to_string(user.id),
12 username: "shp",
13 acct: user.nickname,
14 display_name: user.name,
15 locked: false,
16 created_at: "2017-08-15T15:47:06.000Z",
17 followers_count: 3,
18 following_count: 0,
19 statuses_count: 5,
20 note: user.bio,
21 url: user.ap_id,
22 avatar: "http://localhost:4001/static/avi.png",
23 avatar_static: "http://localhost:4001/static/avi.png",
24 header: "http://localhost:4001/static/banner.png",
25 header_static: "http://localhost:4001/static/banner.png",
26 source: %{
27 note: "",
28 privacy: "public",
29 sensitive: "false"
30 }
31 }
32
33 assert expected == AccountView.render("account.json", %{user: user})
34 end
35
36 test "Represent a smaller mention" do
37 user = insert(:user)
38
39 expected = %{
40 id: to_string(user.id),
41 acct: user.nickname,
42 username: user.nickname,
43 url: user.ap_id
44 }
45
46 assert expected == AccountView.render("mention.json", %{user: user})
47 end
48
49 test "represent a relationship" do
50 user = insert(:user)
51 other_user = insert(:user)
52
53 {:ok, user} = User.follow(user, other_user)
54 {:ok, user} = User.block(user, other_user)
55
56 expected = %{
57 id: to_string(other_user.id),
58 following: true,
59 followed_by: false,
60 blocking: true,
61 muting: false,
62 requested: false,
63 domain_blocking: false
64 }
65
66 assert expected == AccountView.render("relationship.json", %{user: user, target: other_user})
67 end
68 end