1 defmodule Pleroma.Web.TwitterAPI.NotificationViewTest do
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
13 import Pleroma.Factory
16 user = insert(:user, bio: "<span>Here's some html</span>")
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)
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)
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,
35 "notice" => ActivityView.render("activity.json", %{activity: activity, for: user}),
40 NotificationView.render("notification.json", %{notification: follow_notif, for: user})
43 test "A mention notification" do
45 other_user = insert(:user)
48 TwitterAPI.create_status(other_user, %{"status" => "Päivää, @#{user.nickname}"})
50 [notification] = Notification.for_user(user)
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,
57 "notice" => ActivityView.render("activity.json", %{activity: activity, for: user}),
62 NotificationView.render("notification.json", %{notification: notification, for: user})
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)
70 {:ok, activity} = TwitterAPI.repeat(repeater, note_activity.id)
71 [notification] = Notification.for_user(user)
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,
79 ActivityView.render("activity.json", %{activity: notification.activity, for: user}),
84 NotificationView.render("notification.json", %{notification: notification, for: user})
87 test "A like notification" do
88 note_activity = insert(:note_activity)
89 user = User.get_cached_by_ap_id(note_activity.data["actor"])
92 {:ok, activity} = TwitterAPI.fav(liker, note_activity.id)
93 [notification] = Notification.for_user(user)
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,
101 ActivityView.render("activity.json", %{activity: notification.activity, for: user}),
105 assert represented ==
106 NotificationView.render("notification.json", %{notification: notification, for: user})