1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.TwitterAPI.NotificationViewTest do
8 alias Pleroma.Notification
10 alias Pleroma.Web.ActivityPub.ActivityPub
11 alias Pleroma.Web.CommonAPI.Utils
12 alias Pleroma.Web.TwitterAPI.ActivityView
13 alias Pleroma.Web.TwitterAPI.NotificationView
14 alias Pleroma.Web.TwitterAPI.TwitterAPI
15 alias Pleroma.Web.TwitterAPI.UserView
17 import Pleroma.Factory
20 user = insert(:user, bio: "<span>Here's some html</span>")
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)
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)
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,
39 "notice" => ActivityView.render("activity.json", %{activity: activity, for: user}),
44 NotificationView.render("notification.json", %{notification: follow_notif, for: user})
47 test "A mention notification" do
49 other_user = insert(:user)
52 TwitterAPI.create_status(other_user, %{"status" => "Päivää, @#{user.nickname}"})
54 [notification] = Notification.for_user(user)
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,
61 "notice" => ActivityView.render("activity.json", %{activity: activity, for: user}),
66 NotificationView.render("notification.json", %{notification: notification, for: user})
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)
74 {:ok, _activity} = TwitterAPI.repeat(repeater, note_activity.id)
75 [notification] = Notification.for_user(user)
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,
83 ActivityView.render("activity.json", %{activity: notification.activity, for: user}),
88 NotificationView.render("notification.json", %{notification: notification, for: user})
91 test "A like notification" do
92 note_activity = insert(:note_activity)
93 user = User.get_cached_by_ap_id(note_activity.data["actor"])
96 {:ok, _activity} = TwitterAPI.fav(liker, note_activity.id)
97 [notification] = Notification.for_user(user)
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,
105 ActivityView.render("activity.json", %{activity: notification.activity, for: user}),
109 assert represented ==
110 NotificationView.render("notification.json", %{notification: notification, for: user})