[Pleroma.Web.MastodonAPI.AccountView]: Add bot field
[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 source_data = %{
9 "tag" => [
10 %{
11 "type" => "Emoji",
12 "icon" => %{"url" => "/file.png"},
13 "name" => ":karjalanpiirakka:"
14 }
15 ]
16 }
17
18 user =
19 insert(:user, %{
20 info: %{"note_count" => 5, "follower_count" => 3, "source_data" => source_data},
21 nickname: "shp@shitposter.club",
22 name: ":karjalanpiirakka: shp",
23 bio: "<script src=\"invalid-html\"></script><span>valid html</span>",
24 inserted_at: ~N[2017-08-15 15:47:06.597036]
25 })
26
27 expected = %{
28 id: to_string(user.id),
29 username: "shp",
30 acct: user.nickname,
31 display_name: user.name,
32 locked: false,
33 created_at: "2017-08-15T15:47:06.000Z",
34 followers_count: 3,
35 following_count: 0,
36 statuses_count: 5,
37 note: "<span>valid html</span>",
38 url: user.ap_id,
39 avatar: "http://localhost:4001/images/avi.png",
40 avatar_static: "http://localhost:4001/images/avi.png",
41 header: "http://localhost:4001/images/banner.png",
42 header_static: "http://localhost:4001/images/banner.png",
43 emojis: [
44 %{
45 "static_url" => "/file.png",
46 "url" => "/file.png",
47 "shortcode" => "karjalanpiirakka",
48 "visible_in_picker" => false
49 }
50 ],
51 fields: [],
52 bot: false,
53 source: %{
54 note: "",
55 privacy: "public",
56 sensitive: "false"
57 }
58 }
59
60 assert expected == AccountView.render("account.json", %{user: user})
61 end
62
63 test "Represent a Service(bot) account" do
64 user =
65 insert(:user, %{
66 info: %{"note_count" => 5, "follower_count" => 3, "source_data" => %{"type" => "Service"}},
67 nickname: "shp@shitposter.club",
68 inserted_at: ~N[2017-08-15 15:47:06.597036]
69 })
70
71 expected = %{
72 id: to_string(user.id),
73 username: "shp",
74 acct: user.nickname,
75 display_name: user.name,
76 locked: false,
77 created_at: "2017-08-15T15:47:06.000Z",
78 followers_count: 3,
79 following_count: 0,
80 statuses_count: 5,
81 note: user.bio,
82 url: user.ap_id,
83 avatar: "http://localhost:4001/images/avi.png",
84 avatar_static: "http://localhost:4001/images/avi.png",
85 header: "http://localhost:4001/images/banner.png",
86 header_static: "http://localhost:4001/images/banner.png",
87 emojis: [],
88 fields: [],
89 bot: true,
90 source: %{
91 note: "",
92 privacy: "public",
93 sensitive: "false"
94 }
95 }
96
97 assert expected == AccountView.render("account.json", %{user: user})
98 end
99
100 test "Represent a smaller mention" do
101 user = insert(:user)
102
103 expected = %{
104 id: to_string(user.id),
105 acct: user.nickname,
106 username: user.nickname,
107 url: user.ap_id
108 }
109
110 assert expected == AccountView.render("mention.json", %{user: user})
111 end
112
113 test "represent a relationship" do
114 user = insert(:user)
115 other_user = insert(:user)
116
117 {:ok, user} = User.follow(user, other_user)
118 {:ok, user} = User.block(user, other_user)
119
120 expected = %{
121 id: to_string(other_user.id),
122 following: false,
123 followed_by: false,
124 blocking: true,
125 muting: false,
126 requested: false,
127 domain_blocking: false
128 }
129
130 assert expected == AccountView.render("relationship.json", %{user: user, target: other_user})
131 end
132 end