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.MastodonAPI.NotificationViewTest do
9 alias Pleroma.Notification
12 alias Pleroma.Web.CommonAPI
13 alias Pleroma.Web.CommonAPI.Utils
14 alias Pleroma.Web.MastodonAPI.AccountView
15 alias Pleroma.Web.MastodonAPI.NotificationView
16 alias Pleroma.Web.MastodonAPI.StatusView
17 import Pleroma.Factory
19 test "Mention notification" do
21 mentioned_user = insert(:user)
22 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{mentioned_user.nickname}"})
23 {:ok, [notification]} = Notification.create_notifications(activity)
24 user = User.get_by_id(user.id)
27 id: to_string(notification.id),
28 pleroma: %{is_seen: false},
30 account: AccountView.render("account.json", %{user: user, for: mentioned_user}),
31 status: StatusView.render("status.json", %{activity: activity, for: mentioned_user}),
32 created_at: Utils.to_masto_date(notification.inserted_at)
36 NotificationView.render("index.json", %{notifications: [notification], for: mentioned_user})
38 assert [expected] == result
41 test "Favourite notification" do
43 another_user = insert(:user)
44 {:ok, create_activity} = CommonAPI.post(user, %{"status" => "hey"})
45 {:ok, favorite_activity, _object} = CommonAPI.favorite(create_activity.id, another_user)
46 {:ok, [notification]} = Notification.create_notifications(favorite_activity)
47 create_activity = Activity.get_by_id(create_activity.id)
50 id: to_string(notification.id),
51 pleroma: %{is_seen: false},
53 account: AccountView.render("account.json", %{user: another_user, for: user}),
54 status: StatusView.render("status.json", %{activity: create_activity, for: user}),
55 created_at: Utils.to_masto_date(notification.inserted_at)
58 result = NotificationView.render("index.json", %{notifications: [notification], for: user})
60 assert [expected] == result
63 test "Reblog notification" do
65 another_user = insert(:user)
66 {:ok, create_activity} = CommonAPI.post(user, %{"status" => "hey"})
67 {:ok, reblog_activity, _object} = CommonAPI.repeat(create_activity.id, another_user)
68 {:ok, [notification]} = Notification.create_notifications(reblog_activity)
69 reblog_activity = Activity.get_by_id(create_activity.id)
72 id: to_string(notification.id),
73 pleroma: %{is_seen: false},
75 account: AccountView.render("account.json", %{user: another_user, for: user}),
76 status: StatusView.render("status.json", %{activity: reblog_activity, for: user}),
77 created_at: Utils.to_masto_date(notification.inserted_at)
80 result = NotificationView.render("index.json", %{notifications: [notification], for: user})
82 assert [expected] == result
85 test "Follow notification" do
86 follower = insert(:user)
87 followed = insert(:user)
88 {:ok, follower, followed, _activity} = CommonAPI.follow(follower, followed)
89 notification = Notification |> Repo.one() |> Repo.preload(:activity)
92 id: to_string(notification.id),
93 pleroma: %{is_seen: false},
95 account: AccountView.render("account.json", %{user: follower, for: followed}),
96 created_at: Utils.to_masto_date(notification.inserted_at)
100 NotificationView.render("index.json", %{notifications: [notification], for: followed})
102 assert [expected] == result