1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.MigrationHelper.NotificationBackfillTest do
6 use Pleroma.DataCase, async: true
9 alias Pleroma.MigrationHelper.NotificationBackfill
10 alias Pleroma.Notification
12 alias Pleroma.Web.CommonAPI
14 import Pleroma.Factory
16 describe "fill_in_notification_types" do
17 test "it fills in missing notification types" do
19 other_user = insert(:user)
21 {:ok, post} = CommonAPI.post(user, %{status: "yeah, @#{other_user.nickname}"})
22 {:ok, react} = CommonAPI.react_with_emoji(post.id, other_user, "☕")
23 {:ok, like} = CommonAPI.favorite(other_user, post.id)
24 {:ok, react_2} = CommonAPI.react_with_emoji(post.id, other_user, "☕")
28 |> Map.put("type", "EmojiReaction")
32 |> Activity.change(%{data: data})
35 assert {4, nil} = Repo.update_all(Notification, set: [type: nil])
37 NotificationBackfill.fill_in_notification_types()
39 assert %{type: "mention"} =
40 Repo.get_by(Notification, user_id: other_user.id, activity_id: post.id)
42 assert %{type: "favourite"} =
43 Repo.get_by(Notification, user_id: user.id, activity_id: like.id)
45 assert %{type: "pleroma:emoji_reaction"} =
46 Repo.get_by(Notification, user_id: user.id, activity_id: react.id)
48 assert %{type: "pleroma:emoji_reaction"} =
49 Repo.get_by(Notification, user_id: user.id, activity_id: react_2.id)