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