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