Add PUT /api/pleroma/notification_settings endpoint
[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 requested: false,
160 domain_blocking: false,
161 showing_reblogs: true,
162 endorsed: false
163 }
164
165 assert expected == AccountView.render("relationship.json", %{user: user, target: other_user})
166 end
167
168 test "represent an embedded relationship" do
169 user =
170 insert(:user, %{
171 info: %{note_count: 5, follower_count: 3, source_data: %{"type" => "Service"}},
172 nickname: "shp@shitposter.club",
173 inserted_at: ~N[2017-08-15 15:47:06.597036]
174 })
175
176 other_user = insert(:user)
177
178 {:ok, other_user} = User.follow(other_user, user)
179 {:ok, other_user} = User.block(other_user, user)
180
181 expected = %{
182 id: to_string(user.id),
183 username: "shp",
184 acct: user.nickname,
185 display_name: user.name,
186 locked: false,
187 created_at: "2017-08-15T15:47:06.000Z",
188 followers_count: 3,
189 following_count: 0,
190 statuses_count: 5,
191 note: user.bio,
192 url: user.ap_id,
193 avatar: "http://localhost:4001/images/avi.png",
194 avatar_static: "http://localhost:4001/images/avi.png",
195 header: "http://localhost:4001/images/banner.png",
196 header_static: "http://localhost:4001/images/banner.png",
197 emojis: [],
198 fields: [],
199 bot: true,
200 source: %{
201 note: "",
202 privacy: "public",
203 sensitive: false
204 },
205 pleroma: %{
206 confirmation_pending: false,
207 tags: [],
208 is_admin: false,
209 is_moderator: false,
210 relationship: %{
211 id: to_string(user.id),
212 following: false,
213 followed_by: false,
214 blocking: true,
215 muting: false,
216 muting_notifications: false,
217 requested: false,
218 domain_blocking: false,
219 showing_reblogs: true,
220 endorsed: false
221 }
222 }
223 }
224
225 assert expected == AccountView.render("account.json", %{user: user, for: other_user})
226 end
227 end