Merge branch 'align-mastodon-conversations' into 'develop'
[akkoma] / test / web / mastodon_api / account_view_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
6 use Pleroma.DataCase
7 import Pleroma.Factory
8 alias Pleroma.User
9 alias Pleroma.Web.MastodonAPI.AccountView
10
11 test "Represent a user account" do
12 source_data = %{
13 "tag" => [
14 %{
15 "type" => "Emoji",
16 "icon" => %{"url" => "/file.png"},
17 "name" => ":karjalanpiirakka:"
18 }
19 ]
20 }
21
22 user =
23 insert(:user, %{
24 info: %{note_count: 5, follower_count: 3, source_data: source_data},
25 nickname: "shp@shitposter.club",
26 name: ":karjalanpiirakka: shp",
27 bio: "<script src=\"invalid-html\"></script><span>valid html</span>",
28 inserted_at: ~N[2017-08-15 15:47:06.597036]
29 })
30
31 expected = %{
32 id: to_string(user.id),
33 username: "shp",
34 acct: user.nickname,
35 display_name: user.name,
36 locked: false,
37 created_at: "2017-08-15T15:47:06.000Z",
38 followers_count: 3,
39 following_count: 0,
40 statuses_count: 5,
41 note: "<span>valid html</span>",
42 url: user.ap_id,
43 avatar: "http://localhost:4001/images/avi.png",
44 avatar_static: "http://localhost:4001/images/avi.png",
45 header: "http://localhost:4001/images/banner.png",
46 header_static: "http://localhost:4001/images/banner.png",
47 emojis: [
48 %{
49 "static_url" => "/file.png",
50 "url" => "/file.png",
51 "shortcode" => "karjalanpiirakka",
52 "visible_in_picker" => false
53 }
54 ],
55 fields: [],
56 bot: false,
57 source: %{
58 note: "valid html",
59 sensitive: false,
60 pleroma: %{}
61 },
62 pleroma: %{
63 confirmation_pending: false,
64 tags: [],
65 is_admin: false,
66 is_moderator: false,
67 hide_favorites: true,
68 hide_followers: false,
69 hide_follows: false,
70 relationship: %{}
71 }
72 }
73
74 assert expected == AccountView.render("account.json", %{user: user})
75 end
76
77 test "Represent the user account for the account owner" do
78 user = insert(:user)
79
80 notification_settings = %{
81 "followers" => true,
82 "follows" => true,
83 "non_follows" => true,
84 "non_followers" => true
85 }
86
87 privacy = user.info.default_scope
88
89 assert %{
90 pleroma: %{notification_settings: ^notification_settings},
91 source: %{privacy: ^privacy}
92 } = AccountView.render("account.json", %{user: user, for: user})
93 end
94
95 test "Represent a Service(bot) account" do
96 user =
97 insert(:user, %{
98 info: %{note_count: 5, follower_count: 3, source_data: %{"type" => "Service"}},
99 nickname: "shp@shitposter.club",
100 inserted_at: ~N[2017-08-15 15:47:06.597036]
101 })
102
103 expected = %{
104 id: to_string(user.id),
105 username: "shp",
106 acct: user.nickname,
107 display_name: user.name,
108 locked: false,
109 created_at: "2017-08-15T15:47:06.000Z",
110 followers_count: 3,
111 following_count: 0,
112 statuses_count: 5,
113 note: user.bio,
114 url: user.ap_id,
115 avatar: "http://localhost:4001/images/avi.png",
116 avatar_static: "http://localhost:4001/images/avi.png",
117 header: "http://localhost:4001/images/banner.png",
118 header_static: "http://localhost:4001/images/banner.png",
119 emojis: [],
120 fields: [],
121 bot: true,
122 source: %{
123 note: user.bio,
124 sensitive: false,
125 pleroma: %{}
126 },
127 pleroma: %{
128 confirmation_pending: false,
129 tags: [],
130 is_admin: false,
131 is_moderator: false,
132 hide_favorites: true,
133 hide_followers: false,
134 hide_follows: false,
135 relationship: %{}
136 }
137 }
138
139 assert expected == AccountView.render("account.json", %{user: user})
140 end
141
142 test "Represent a smaller mention" do
143 user = insert(:user)
144
145 expected = %{
146 id: to_string(user.id),
147 acct: user.nickname,
148 username: user.nickname,
149 url: user.ap_id
150 }
151
152 assert expected == AccountView.render("mention.json", %{user: user})
153 end
154
155 test "represent a relationship" do
156 user = insert(:user)
157 other_user = insert(:user)
158
159 {:ok, user} = User.follow(user, other_user)
160 {:ok, user} = User.block(user, other_user)
161
162 expected = %{
163 id: to_string(other_user.id),
164 following: false,
165 followed_by: false,
166 blocking: true,
167 muting: false,
168 muting_notifications: false,
169 subscribing: false,
170 requested: false,
171 domain_blocking: false,
172 showing_reblogs: true,
173 endorsed: false
174 }
175
176 assert expected == AccountView.render("relationship.json", %{user: user, target: other_user})
177 end
178
179 test "represent an embedded relationship" do
180 user =
181 insert(:user, %{
182 info: %{note_count: 5, follower_count: 0, source_data: %{"type" => "Service"}},
183 nickname: "shp@shitposter.club",
184 inserted_at: ~N[2017-08-15 15:47:06.597036]
185 })
186
187 other_user = insert(:user)
188 {:ok, other_user} = User.follow(other_user, user)
189 {:ok, other_user} = User.block(other_user, user)
190 {:ok, _} = User.follow(insert(:user), user)
191
192 expected = %{
193 id: to_string(user.id),
194 username: "shp",
195 acct: user.nickname,
196 display_name: user.name,
197 locked: false,
198 created_at: "2017-08-15T15:47:06.000Z",
199 followers_count: 1,
200 following_count: 0,
201 statuses_count: 5,
202 note: user.bio,
203 url: user.ap_id,
204 avatar: "http://localhost:4001/images/avi.png",
205 avatar_static: "http://localhost:4001/images/avi.png",
206 header: "http://localhost:4001/images/banner.png",
207 header_static: "http://localhost:4001/images/banner.png",
208 emojis: [],
209 fields: [],
210 bot: true,
211 source: %{
212 note: user.bio,
213 sensitive: false,
214 pleroma: %{}
215 },
216 pleroma: %{
217 confirmation_pending: false,
218 tags: [],
219 is_admin: false,
220 is_moderator: false,
221 hide_favorites: true,
222 hide_followers: false,
223 hide_follows: false,
224 relationship: %{
225 id: to_string(user.id),
226 following: false,
227 followed_by: false,
228 blocking: true,
229 subscribing: false,
230 muting: false,
231 muting_notifications: false,
232 requested: false,
233 domain_blocking: false,
234 showing_reblogs: true,
235 endorsed: false
236 }
237 }
238 }
239
240 assert expected == AccountView.render("account.json", %{user: user, for: other_user})
241 end
242 end