summaryrefslogtreecommitdiff
path: root/test/pleroma/migration_helper/notification_backfill_test.exs
blob: 6d47bb6a84d33b893938b397172bfbf34b4071aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Pleroma: A lightweight social networking server
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only

defmodule Pleroma.MigrationHelper.NotificationBackfillTest do
  use Pleroma.DataCase, async: true

  alias Pleroma.Activity
  alias Pleroma.MigrationHelper.NotificationBackfill
  alias Pleroma.Notification
  alias Pleroma.Repo
  alias Pleroma.Web.CommonAPI

  import Pleroma.Factory

  describe "fill_in_notification_types" do
    test "it fills in missing notification types" do
      user = insert(:user)
      other_user = insert(:user)

      {:ok, post} = CommonAPI.post(user, %{status: "yeah, @#{other_user.nickname}"})
      {:ok, chat} = CommonAPI.post_chat_message(user, other_user, "yo")
      {:ok, react} = CommonAPI.react_with_emoji(post.id, other_user, "☕")
      {:ok, like} = CommonAPI.favorite(other_user, post.id)
      {:ok, react_2} = CommonAPI.react_with_emoji(post.id, other_user, "☕")

      data =
        react_2.data
        |> Map.put("type", "EmojiReaction")

      {:ok, react_2} =
        react_2
        |> Activity.change(%{data: data})
        |> Repo.update()

      assert {5, nil} = Repo.update_all(Notification, set: [type: nil])

      NotificationBackfill.fill_in_notification_types()

      assert %{type: "mention"} =
               Repo.get_by(Notification, user_id: other_user.id, activity_id: post.id)

      assert %{type: "favourite"} =
               Repo.get_by(Notification, user_id: user.id, activity_id: like.id)

      assert %{type: "pleroma:emoji_reaction"} =
               Repo.get_by(Notification, user_id: user.id, activity_id: react.id)

      assert %{type: "pleroma:emoji_reaction"} =
               Repo.get_by(Notification, user_id: user.id, activity_id: react_2.id)

      assert %{type: "pleroma:chat_mention"} =
               Repo.get_by(Notification, user_id: other_user.id, activity_id: chat.id)
    end
  end
end