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
12 import Pleroma.Factory
15 user = insert(:user, bio: "<span>Here's some html</span>")
19 test "A follow notification" do
20 note_activity = insert(:note_activity)
21 user = User.get_cached_by_ap_id(note_activity.data["actor"])
22 follower = insert(:user)
24 {:ok, follower} = User.follow(follower, user)
25 {:ok, activity} = ActivityPub.follow(follower, user)
26 Cachex.put(:user_cache, "user_info:#{user.id}", User.user_info(Repo.get!(User, user.id)))
27 [follow_notif] = Notification.for_user(user)
30 "created_at" => follow_notif.inserted_at |> Utils.format_naive_asctime(),
31 "from_profile" => UserView.render("show.json", %{user: follower, for: user}),
32 "id" => follow_notif.id,
34 "notice" => ActivityView.render("activity.json", %{activity: activity, for: user}),
39 NotificationView.render("notification.json", %{notification: follow_notif, for: user})
42 test "A mention notification" do
44 other_user = insert(:user)
47 TwitterAPI.create_status(other_user, %{"status" => "Päivää, @#{user.nickname}"})
49 [notification] = Notification.for_user(user)
52 "created_at" => notification.inserted_at |> Utils.format_naive_asctime(),
53 "from_profile" => UserView.render("show.json", %{user: other_user, for: user}),
54 "id" => notification.id,
56 "notice" => ActivityView.render("activity.json", %{activity: activity, for: user}),
61 NotificationView.render("notification.json", %{notification: notification, for: user})
64 test "A retweet notification" do
65 note_activity = insert(:note_activity)
66 user = User.get_cached_by_ap_id(note_activity.data["actor"])
67 repeater = insert(:user)
69 {:ok, _activity} = TwitterAPI.repeat(repeater, note_activity.id)
70 [notification] = Notification.for_user(user)
73 "created_at" => notification.inserted_at |> Utils.format_naive_asctime(),
74 "from_profile" => UserView.render("show.json", %{user: repeater, for: user}),
75 "id" => notification.id,
78 ActivityView.render("activity.json", %{activity: notification.activity, for: user}),
83 NotificationView.render("notification.json", %{notification: notification, for: user})
86 test "A like notification" do
87 note_activity = insert(:note_activity)
88 user = User.get_cached_by_ap_id(note_activity.data["actor"])
91 {:ok, _activity} = TwitterAPI.fav(liker, note_activity.id)
92 [notification] = Notification.for_user(user)
95 "created_at" => notification.inserted_at |> Utils.format_naive_asctime(),
96 "from_profile" => UserView.render("show.json", %{user: liker, for: user}),
97 "id" => notification.id,
100 ActivityView.render("activity.json", %{activity: notification.activity, for: user}),
104 assert represented ==
105 NotificationView.render("notification.json", %{notification: notification, for: user})