1 defmodule Pleroma.Web.TwitterAPI.UserViewTest do
5 alias Pleroma.Web.TwitterAPI.UserView
6 alias Pleroma.Web.CommonAPI.Utils
7 alias Pleroma.Builders.UserBuilder
12 user = insert(:user, bio: "<span>Here's some html</span>")
16 test "A user with an avatar object", %{user: user} do
18 user = %{ user | avatar: %{ "url" => [%{"href" => image}] }}
19 represented = UserView.render("show.json", %{user: user})
20 assert represented["profile_image_url"] == image
24 note_activity = insert(:note_activity)
25 user = User.get_cached_by_ap_id(note_activity.data["actor"])
26 {:ok, user} = User.update_note_count(user)
27 follower = insert(:user)
28 second_follower = insert(:user)
30 User.follow(follower, user)
31 User.follow(second_follower, user)
32 User.follow(user, follower)
33 {:ok, user} = User.update_follower_count(user)
34 Cachex.set(:user_cache, "user_info:#{user.id}", User.user_info(Repo.get!(User, user.id)))
36 image = "https://placehold.it/48x48"
41 "screen_name" => user.nickname,
42 "description" => HtmlSanitizeEx.strip_tags(user.bio),
43 "created_at" => user.inserted_at |> Utils.format_naive_asctime,
44 "favourites_count" => 0,
45 "statuses_count" => 1,
47 "followers_count" => 2,
48 "profile_image_url" => image,
49 "profile_image_url_https" => image,
50 "profile_image_url_profile_size" => image,
51 "profile_image_url_original" => image,
53 "follows_you" => false,
54 "statusnet_blocking" => false,
56 "statusnet_profile_url" => user.ap_id,
58 "background_image" => nil
61 assert represented == UserView.render("show.json", %{user: user})
64 test "A user for a given other follower", %{user: user} do
65 {:ok, follower} = UserBuilder.insert(%{following: [User.ap_followers(user)]})
66 {:ok, user} = User.update_follower_count(user)
67 image = "https://placehold.it/48x48"
71 "screen_name" => user.nickname,
72 "description" => HtmlSanitizeEx.strip_tags(user.bio),
73 "created_at" => user.inserted_at |> Utils.format_naive_asctime,
74 "favourites_count" => 0,
75 "statuses_count" => 0,
77 "followers_count" => 1,
78 "profile_image_url" => image,
79 "profile_image_url_https" => image,
80 "profile_image_url_profile_size" => image,
81 "profile_image_url_original" => image,
83 "follows_you" => false,
84 "statusnet_blocking" => false,
86 "statusnet_profile_url" => user.ap_id,
88 "background_image" => nil
91 assert represented == UserView.render("show.json", %{user: user, for: follower})
94 test "A user that follows you", %{user: user} do
95 follower = insert(:user)
96 {:ok, follower} = User.follow(follower, user)
97 {:ok, user} = User.update_follower_count(user)
98 image = "https://placehold.it/48x48"
101 "name" => follower.name,
102 "screen_name" => follower.nickname,
103 "description" => HtmlSanitizeEx.strip_tags(follower.bio),
104 "created_at" => follower.inserted_at |> Utils.format_naive_asctime,
105 "favourites_count" => 0,
106 "statuses_count" => 0,
107 "friends_count" => 1,
108 "followers_count" => 0,
109 "profile_image_url" => image,
110 "profile_image_url_https" => image,
111 "profile_image_url_profile_size" => image,
112 "profile_image_url_original" => image,
113 "following" => false,
114 "follows_you" => true,
115 "statusnet_blocking" => false,
117 "statusnet_profile_url" => follower.ap_id,
118 "cover_photo" => nil,
119 "background_image" => nil
122 assert represented == UserView.render("show.json", %{user: follower, for: user})
125 test "A blocked user for the blocker", %{user: user} do
127 blocker = insert(:user)
128 User.block(blocker, user)
129 image = "https://placehold.it/48x48"
133 "screen_name" => user.nickname,
134 "description" => HtmlSanitizeEx.strip_tags(user.bio),
135 "created_at" => user.inserted_at |> Utils.format_naive_asctime,
136 "favourites_count" => 0,
137 "statuses_count" => 0,
138 "friends_count" => 0,
139 "followers_count" => 0,
140 "profile_image_url" => image,
141 "profile_image_url_https" => image,
142 "profile_image_url_profile_size" => image,
143 "profile_image_url_original" => image,
144 "following" => false,
145 "follows_you" => false,
146 "statusnet_blocking" => true,
148 "statusnet_profile_url" => user.ap_id,
149 "cover_photo" => nil,
150 "background_image" => nil
153 blocker = Repo.get(User, blocker.id)
154 assert represented == UserView.render("show.json", %{user: user, for: blocker})