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