1 defmodule Pleroma.Web.TwitterAPI.UserViewTest do
5 alias Pleroma.Web.TwitterAPI.UserView
6 alias Pleroma.Web.CommonAPI.Utils
11 user = insert(:user, bio: "<span>Here's some html</span>")
15 test "A user with only a nickname", %{user: user} do
16 user = %{user | name: nil, nickname: "scarlett@catgirl.science"}
17 represented = UserView.render("show.json", %{user: user})
18 assert represented["name"] == user.nickname
19 assert represented["name_html"] == user.nickname
22 test "A user with an avatar object", %{user: user} do
24 user = %{user | avatar: %{"url" => [%{"href" => image}]}}
25 represented = UserView.render("show.json", %{user: user})
26 assert represented["profile_image_url"] == image
29 test "A user with emoji in username" do
31 "<img height=\"32px\" width=\"32px\" alt=\"karjalanpiirakka\" title=\"karjalanpiirakka\" src=\"/file.png\" /> man"
40 "icon" => %{"url" => "/file.png"},
41 "name" => ":karjalanpiirakka:"
46 name: ":karjalanpiirakka: man"
49 represented = UserView.render("show.json", %{user: user})
50 assert represented["name_html"] == expected
54 note_activity = insert(:note_activity)
55 user = User.get_cached_by_ap_id(note_activity.data["actor"])
56 {:ok, user} = User.update_note_count(user)
57 follower = insert(:user)
58 second_follower = insert(:user)
60 User.follow(follower, user)
61 User.follow(second_follower, user)
62 User.follow(user, follower)
63 {:ok, user} = User.update_follower_count(user)
64 Cachex.put(:user_cache, "user_info:#{user.id}", User.user_info(Repo.get!(User, user.id)))
66 image = "http://localhost:4001/images/avi.png"
67 banner = "http://localhost:4001/images/banner.png"
72 "screen_name" => user.nickname,
73 "name_html" => user.name,
74 "description" => HtmlSanitizeEx.strip_tags(user.bio |> String.replace("<br>", "\n")),
75 "description_html" => HtmlSanitizeEx.basic_html(user.bio),
76 "created_at" => user.inserted_at |> Utils.format_naive_asctime(),
77 "favourites_count" => 0,
78 "statuses_count" => 1,
80 "followers_count" => 2,
81 "profile_image_url" => image,
82 "profile_image_url_https" => image,
83 "profile_image_url_profile_size" => image,
84 "profile_image_url_original" => image,
86 "follows_you" => false,
87 "statusnet_blocking" => false,
89 "delete_others_notice" => false
91 "statusnet_profile_url" => user.ap_id,
92 "cover_photo" => banner,
93 "background_image" => nil,
96 "default_scope" => "public",
97 "no_rich_text" => false,
100 "confirmation_pending" => false,
105 assert represented == UserView.render("show.json", %{user: user})
108 test "A user for a given other follower", %{user: user} do
109 follower = insert(:user, %{following: [User.ap_followers(user)]})
110 {:ok, user} = User.update_follower_count(user)
111 image = "http://localhost:4001/images/avi.png"
112 banner = "http://localhost:4001/images/banner.png"
117 "screen_name" => user.nickname,
118 "name_html" => user.name,
119 "description" => HtmlSanitizeEx.strip_tags(user.bio |> String.replace("<br>", "\n")),
120 "description_html" => HtmlSanitizeEx.basic_html(user.bio),
121 "created_at" => user.inserted_at |> Utils.format_naive_asctime(),
122 "favourites_count" => 0,
123 "statuses_count" => 0,
124 "friends_count" => 0,
125 "followers_count" => 1,
126 "profile_image_url" => image,
127 "profile_image_url_https" => image,
128 "profile_image_url_profile_size" => image,
129 "profile_image_url_original" => image,
131 "follows_you" => false,
132 "statusnet_blocking" => false,
134 "delete_others_notice" => false
136 "statusnet_profile_url" => user.ap_id,
137 "cover_photo" => banner,
138 "background_image" => nil,
141 "default_scope" => "public",
142 "no_rich_text" => false,
145 "confirmation_pending" => false,
150 assert represented == UserView.render("show.json", %{user: user, for: follower})
153 test "A user that follows you", %{user: user} do
154 follower = insert(:user)
155 {:ok, follower} = User.follow(follower, user)
156 {:ok, user} = User.update_follower_count(user)
157 image = "http://localhost:4001/images/avi.png"
158 banner = "http://localhost:4001/images/banner.png"
162 "name" => follower.name,
163 "screen_name" => follower.nickname,
164 "name_html" => follower.name,
165 "description" => HtmlSanitizeEx.strip_tags(follower.bio |> String.replace("<br>", "\n")),
166 "description_html" => HtmlSanitizeEx.basic_html(follower.bio),
167 "created_at" => follower.inserted_at |> Utils.format_naive_asctime(),
168 "favourites_count" => 0,
169 "statuses_count" => 0,
170 "friends_count" => 1,
171 "followers_count" => 0,
172 "profile_image_url" => image,
173 "profile_image_url_https" => image,
174 "profile_image_url_profile_size" => image,
175 "profile_image_url_original" => image,
176 "following" => false,
177 "follows_you" => true,
178 "statusnet_blocking" => false,
180 "delete_others_notice" => false
182 "statusnet_profile_url" => follower.ap_id,
183 "cover_photo" => banner,
184 "background_image" => nil,
187 "default_scope" => "public",
188 "no_rich_text" => false,
191 "confirmation_pending" => false,
196 assert represented == UserView.render("show.json", %{user: follower, for: user})
199 test "a user that is a moderator" do
200 user = insert(:user, %{info: %{is_moderator: true}})
201 represented = UserView.render("show.json", %{user: user, for: user})
203 assert represented["rights"]["delete_others_notice"]
206 test "A blocked user for the blocker" do
208 blocker = insert(:user)
209 User.block(blocker, user)
210 image = "http://localhost:4001/images/avi.png"
211 banner = "http://localhost:4001/images/banner.png"
216 "screen_name" => user.nickname,
217 "name_html" => user.name,
218 "description" => HtmlSanitizeEx.strip_tags(user.bio |> String.replace("<br>", "\n")),
219 "description_html" => HtmlSanitizeEx.basic_html(user.bio),
220 "created_at" => user.inserted_at |> Utils.format_naive_asctime(),
221 "favourites_count" => 0,
222 "statuses_count" => 0,
223 "friends_count" => 0,
224 "followers_count" => 0,
225 "profile_image_url" => image,
226 "profile_image_url_https" => image,
227 "profile_image_url_profile_size" => image,
228 "profile_image_url_original" => image,
229 "following" => false,
230 "follows_you" => false,
231 "statusnet_blocking" => true,
233 "delete_others_notice" => false
235 "statusnet_profile_url" => user.ap_id,
236 "cover_photo" => banner,
237 "background_image" => nil,
240 "default_scope" => "public",
241 "no_rich_text" => false,
244 "confirmation_pending" => false,
249 blocker = Repo.get(User, blocker.id)
250 assert represented == UserView.render("show.json", %{user: user, for: blocker})
253 test "a user with mastodon fields" do
256 "name" => "Pronouns",
261 "value" => "https://example.org/"
270 Enum.map(fields, fn field -> Map.put(field, "type", "PropertyValue") end)
275 userview = UserView.render("show.json", %{user: user})
276 assert userview["fields"] == fields