fd253b530f2399a5e9dbfdcc684944c1274393aa
[akkoma] / test / pleroma / migration_helper / notification_backfill_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.MigrationHelper.NotificationBackfillTest do
6 use Pleroma.DataCase, async: true
7
8 alias Pleroma.Activity
9 alias Pleroma.MigrationHelper.NotificationBackfill
10 alias Pleroma.Notification
11 alias Pleroma.Repo
12 alias Pleroma.Web.CommonAPI
13
14 import Pleroma.Factory
15
16 describe "fill_in_notification_types" do
17 test "it fills in missing notification types" do
18 user = insert(:user)
19 other_user = insert(:user)
20
21 {:ok, post} = CommonAPI.post(user, %{status: "yeah, @#{other_user.nickname}"})
22 {:ok, chat} = CommonAPI.post_chat_message(user, other_user, "yo")
23 {:ok, react} = CommonAPI.react_with_emoji(post.id, other_user, "☕")
24 {:ok, like} = CommonAPI.favorite(other_user, post.id)
25 {:ok, react_2} = CommonAPI.react_with_emoji(post.id, other_user, "☕")
26
27 data =
28 react_2.data
29 |> Map.put("type", "EmojiReaction")
30
31 {:ok, react_2} =
32 react_2
33 |> Activity.change(%{data: data})
34 |> Repo.update()
35
36 assert {5, nil} = Repo.update_all(Notification, set: [type: nil])
37
38 NotificationBackfill.fill_in_notification_types()
39
40 assert %{type: "mention"} =
41 Repo.get_by(Notification, user_id: other_user.id, activity_id: post.id)
42
43 assert %{type: "favourite"} =
44 Repo.get_by(Notification, user_id: user.id, activity_id: like.id)
45
46 assert %{type: "pleroma:emoji_reaction"} =
47 Repo.get_by(Notification, user_id: user.id, activity_id: react.id)
48
49 assert %{type: "pleroma:emoji_reaction"} =
50 Repo.get_by(Notification, user_id: user.id, activity_id: react_2.id)
51
52 assert %{type: "pleroma:chat_mention"} =
53 Repo.get_by(Notification, user_id: other_user.id, activity_id: chat.id)
54 end
55 end
56 end