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.{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
16 import Pleroma.Factory
19 user = insert(:user, bio: "<span>Here's some html</span>")
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)
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)
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,
38 "notice" => ActivityView.render("activity.json", %{activity: activity, for: user}),
43 NotificationView.render("notification.json", %{notification: follow_notif, for: user})
46 test "A mention notification" do
48 other_user = insert(:user)
51 TwitterAPI.create_status(other_user, %{"status" => "Päivää, @#{user.nickname}"})
53 [notification] = Notification.for_user(user)
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,
60 "notice" => ActivityView.render("activity.json", %{activity: activity, for: user}),
65 NotificationView.render("notification.json", %{notification: notification, for: user})
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)
73 {:ok, _activity} = TwitterAPI.repeat(repeater, note_activity.id)
74 [notification] = Notification.for_user(user)
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,
82 ActivityView.render("activity.json", %{activity: notification.activity, for: user}),
87 NotificationView.render("notification.json", %{notification: notification, for: user})
90 test "A like notification" do
91 note_activity = insert(:note_activity)
92 user = User.get_cached_by_ap_id(note_activity.data["actor"])
95 {:ok, _activity} = TwitterAPI.fav(liker, note_activity.id)
96 [notification] = Notification.for_user(user)
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,
104 ActivityView.render("activity.json", %{activity: notification.activity, for: user}),
108 assert represented ==
109 NotificationView.render("notification.json", %{notification: notification, for: user})