Merge branch 'fix/blocked-user-boosts' into 'develop'
[akkoma] / test / web / twitter_api / views / notification_view_test.exs
1 defmodule Pleroma.Web.TwitterAPI.NotificationViewTest do
2 use Pleroma.DataCase
3
4 alias Pleroma.{User, Notification}
5 alias Pleroma.Web.TwitterAPI.TwitterAPI
6 alias Pleroma.Web.TwitterAPI.NotificationView
7 alias Pleroma.Web.TwitterAPI.UserView
8 alias Pleroma.Web.TwitterAPI.ActivityView
9 alias Pleroma.Web.CommonAPI.Utils
10 alias Pleroma.Web.ActivityPub.ActivityPub
11 alias Pleroma.Builders.UserBuilder
12
13 import Pleroma.Factory
14
15 setup do
16 user = insert(:user, bio: "<span>Here's some html</span>")
17 [user: user]
18 end
19
20 test "A follow notification" do
21 note_activity = insert(:note_activity)
22 user = User.get_cached_by_ap_id(note_activity.data["actor"])
23 follower = insert(:user)
24
25 {:ok, follower} = User.follow(follower, user)
26 {:ok, activity} = ActivityPub.follow(follower, user)
27 Cachex.set(:user_cache, "user_info:#{user.id}", User.user_info(Repo.get!(User, user.id)))
28 [follow_notif] = Notification.for_user(user)
29
30 represented = %{
31 "created_at" => follow_notif.inserted_at |> Utils.format_naive_asctime(),
32 "from_profile" => UserView.render("show.json", %{user: follower, for: user}),
33 "id" => follow_notif.id,
34 "is_seen" => 0,
35 "notice" => ActivityView.render("activity.json", %{activity: activity, for: user}),
36 "ntype" => "follow"
37 }
38
39 assert represented ==
40 NotificationView.render("notification.json", %{notification: follow_notif, for: user})
41 end
42
43 test "A mention notification" do
44 user = insert(:user)
45 other_user = insert(:user)
46
47 {:ok, activity} =
48 TwitterAPI.create_status(other_user, %{"status" => "Päivää, @#{user.nickname}"})
49
50 [notification] = Notification.for_user(user)
51
52 represented = %{
53 "created_at" => notification.inserted_at |> Utils.format_naive_asctime(),
54 "from_profile" => UserView.render("show.json", %{user: other_user, for: user}),
55 "id" => notification.id,
56 "is_seen" => 0,
57 "notice" => ActivityView.render("activity.json", %{activity: activity, for: user}),
58 "ntype" => "mention"
59 }
60
61 assert represented ==
62 NotificationView.render("notification.json", %{notification: notification, for: user})
63 end
64
65 test "A retweet notification" do
66 note_activity = insert(:note_activity)
67 user = User.get_cached_by_ap_id(note_activity.data["actor"])
68 repeater = insert(:user)
69
70 {:ok, activity} = TwitterAPI.repeat(repeater, note_activity.id)
71 [notification] = Notification.for_user(user)
72
73 represented = %{
74 "created_at" => notification.inserted_at |> Utils.format_naive_asctime(),
75 "from_profile" => UserView.render("show.json", %{user: repeater, for: user}),
76 "id" => notification.id,
77 "is_seen" => 0,
78 "notice" =>
79 ActivityView.render("activity.json", %{activity: notification.activity, for: user}),
80 "ntype" => "repeat"
81 }
82
83 assert represented ==
84 NotificationView.render("notification.json", %{notification: notification, for: user})
85 end
86
87 test "A like notification" do
88 note_activity = insert(:note_activity)
89 user = User.get_cached_by_ap_id(note_activity.data["actor"])
90 liker = insert(:user)
91
92 {:ok, activity} = TwitterAPI.fav(liker, note_activity.id)
93 [notification] = Notification.for_user(user)
94
95 represented = %{
96 "created_at" => notification.inserted_at |> Utils.format_naive_asctime(),
97 "from_profile" => UserView.render("show.json", %{user: liker, for: user}),
98 "id" => notification.id,
99 "is_seen" => 0,
100 "notice" =>
101 ActivityView.render("activity.json", %{activity: notification.activity, for: user}),
102 "ntype" => "like"
103 }
104
105 assert represented ==
106 NotificationView.render("notification.json", %{notification: notification, for: user})
107 end
108 end