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 = "http://localhost:4001/static/avi.png"
37 banner = "http://localhost:4001/static/banner.png"
42 "screen_name" => user.nickname,
43 "description" => HtmlSanitizeEx.strip_tags(user.bio),
44 "created_at" => user.inserted_at |> Utils.format_naive_asctime,
45 "favourites_count" => 0,
46 "statuses_count" => 1,
48 "followers_count" => 2,
49 "profile_image_url" => image,
50 "profile_image_url_https" => image,
51 "profile_image_url_profile_size" => image,
52 "profile_image_url_original" => image,
54 "follows_you" => false,
55 "statusnet_blocking" => false,
57 "statusnet_profile_url" => user.ap_id,
58 "cover_photo" => banner,
59 "background_image" => nil
62 assert represented == UserView.render("show.json", %{user: user})
65 test "A user for a given other follower", %{user: user} do
66 {:ok, follower} = UserBuilder.insert(%{following: [User.ap_followers(user)]})
67 {:ok, user} = User.update_follower_count(user)
68 image = "http://localhost:4001/static/avi.png"
69 banner = "http://localhost:4001/static/banner.png"
74 "screen_name" => user.nickname,
75 "description" => HtmlSanitizeEx.strip_tags(user.bio),
76 "created_at" => user.inserted_at |> Utils.format_naive_asctime,
77 "favourites_count" => 0,
78 "statuses_count" => 0,
80 "followers_count" => 1,
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 "statusnet_profile_url" => user.ap_id,
90 "cover_photo" => banner,
91 "background_image" => nil
94 assert represented == UserView.render("show.json", %{user: user, for: follower})
97 test "A user that follows you", %{user: user} do
98 follower = insert(:user)
99 {:ok, follower} = User.follow(follower, user)
100 {:ok, user} = User.update_follower_count(user)
101 image = "http://localhost:4001/static/avi.png"
102 banner = "http://localhost:4001/static/banner.png"
106 "name" => follower.name,
107 "screen_name" => follower.nickname,
108 "description" => HtmlSanitizeEx.strip_tags(follower.bio),
109 "created_at" => follower.inserted_at |> Utils.format_naive_asctime,
110 "favourites_count" => 0,
111 "statuses_count" => 0,
112 "friends_count" => 1,
113 "followers_count" => 0,
114 "profile_image_url" => image,
115 "profile_image_url_https" => image,
116 "profile_image_url_profile_size" => image,
117 "profile_image_url_original" => image,
118 "following" => false,
119 "follows_you" => true,
120 "statusnet_blocking" => false,
122 "statusnet_profile_url" => follower.ap_id,
123 "cover_photo" => banner,
124 "background_image" => nil
127 assert represented == UserView.render("show.json", %{user: follower, for: user})
130 test "A blocked user for the blocker", %{user: user} do
132 blocker = insert(:user)
133 User.block(blocker, user)
134 image = "http://localhost:4001/static/avi.png"
135 banner = "http://localhost:4001/static/banner.png"
140 "screen_name" => user.nickname,
141 "description" => HtmlSanitizeEx.strip_tags(user.bio),
142 "created_at" => user.inserted_at |> Utils.format_naive_asctime,
143 "favourites_count" => 0,
144 "statuses_count" => 0,
145 "friends_count" => 0,
146 "followers_count" => 0,
147 "profile_image_url" => image,
148 "profile_image_url_https" => image,
149 "profile_image_url_profile_size" => image,
150 "profile_image_url_original" => image,
151 "following" => false,
152 "follows_you" => false,
153 "statusnet_blocking" => true,
155 "statusnet_profile_url" => user.ap_id,
156 "cover_photo" => banner,
157 "background_image" => nil
160 blocker = Repo.get(User, blocker.id)
161 assert represented == UserView.render("show.json", %{user: user, for: blocker})