Merge remote-tracking branch 'pleroma/develop' into feature/disable-account
[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: "",
59 privacy: "public",
60 sensitive: false
61 },
62 pleroma: %{
63 confirmation_pending: false,
64 tags: [],
65 is_admin: false,
66 is_moderator: false,
67 relationship: %{}
68 }
69 }
70
71 assert expected == AccountView.render("account.json", %{user: user})
72 end
73
74 test "Represent the user account for the account owner" do
75 user = insert(:user)
76
77 notification_settings = %{
78 "remote" => true,
79 "local" => true,
80 "followers" => true,
81 "follows" => true
82 }
83
84 assert %{pleroma: %{notification_settings: ^notification_settings}} =
85 AccountView.render("account.json", %{user: user, for: user})
86 end
87
88 test "Represent a Service(bot) account" do
89 user =
90 insert(:user, %{
91 info: %{note_count: 5, follower_count: 3, source_data: %{"type" => "Service"}},
92 nickname: "shp@shitposter.club",
93 inserted_at: ~N[2017-08-15 15:47:06.597036]
94 })
95
96 expected = %{
97 id: to_string(user.id),
98 username: "shp",
99 acct: user.nickname,
100 display_name: user.name,
101 locked: false,
102 created_at: "2017-08-15T15:47:06.000Z",
103 followers_count: 3,
104 following_count: 0,
105 statuses_count: 5,
106 note: user.bio,
107 url: user.ap_id,
108 avatar: "http://localhost:4001/images/avi.png",
109 avatar_static: "http://localhost:4001/images/avi.png",
110 header: "http://localhost:4001/images/banner.png",
111 header_static: "http://localhost:4001/images/banner.png",
112 emojis: [],
113 fields: [],
114 bot: true,
115 source: %{
116 note: "",
117 privacy: "public",
118 sensitive: false
119 },
120 pleroma: %{
121 confirmation_pending: false,
122 tags: [],
123 is_admin: false,
124 is_moderator: false,
125 relationship: %{}
126 }
127 }
128
129 assert expected == AccountView.render("account.json", %{user: user})
130 end
131
132 test "Represent a smaller mention" do
133 user = insert(:user)
134
135 expected = %{
136 id: to_string(user.id),
137 acct: user.nickname,
138 username: user.nickname,
139 url: user.ap_id
140 }
141
142 assert expected == AccountView.render("mention.json", %{user: user})
143 end
144
145 test "represent a relationship" do
146 user = insert(:user)
147 other_user = insert(:user)
148
149 {:ok, user} = User.follow(user, other_user)
150 {:ok, user} = User.block(user, other_user)
151
152 expected = %{
153 id: to_string(other_user.id),
154 following: false,
155 followed_by: false,
156 blocking: true,
157 muting: false,
158 muting_notifications: false,
159 subscribing: false,
160 requested: false,
161 domain_blocking: false,
162 showing_reblogs: true,
163 endorsed: false
164 }
165
166 assert expected == AccountView.render("relationship.json", %{user: user, target: other_user})
167 end
168
169 test "represent an embedded relationship" do
170 user =
171 insert(:user, %{
172 info: %{note_count: 5, follower_count: 3, source_data: %{"type" => "Service"}},
173 nickname: "shp@shitposter.club",
174 inserted_at: ~N[2017-08-15 15:47:06.597036]
175 })
176
177 other_user = insert(:user)
178
179 {:ok, other_user} = User.follow(other_user, user)
180 {:ok, other_user} = User.block(other_user, user)
181
182 expected = %{
183 id: to_string(user.id),
184 username: "shp",
185 acct: user.nickname,
186 display_name: user.name,
187 locked: false,
188 created_at: "2017-08-15T15:47:06.000Z",
189 followers_count: 3,
190 following_count: 0,
191 statuses_count: 5,
192 note: user.bio,
193 url: user.ap_id,
194 avatar: "http://localhost:4001/images/avi.png",
195 avatar_static: "http://localhost:4001/images/avi.png",
196 header: "http://localhost:4001/images/banner.png",
197 header_static: "http://localhost:4001/images/banner.png",
198 emojis: [],
199 fields: [],
200 bot: true,
201 source: %{
202 note: "",
203 privacy: "public",
204 sensitive: false
205 },
206 pleroma: %{
207 confirmation_pending: false,
208 tags: [],
209 is_admin: false,
210 is_moderator: false,
211 relationship: %{
212 id: to_string(user.id),
213 following: false,
214 followed_by: false,
215 blocking: true,
216 subscribing: false,
217 muting: false,
218 muting_notifications: false,
219 requested: false,
220 domain_blocking: false,
221 showing_reblogs: true,
222 endorsed: false
223 }
224 }
225 }
226
227 assert expected == AccountView.render("account.json", %{user: user, for: other_user})
228 end
229 end