1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.MigrationHelper.NotificationBackfillTest do
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, 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, "☕")
29 |> Map.put("type", "EmojiReaction")
33 |> Activity.change(%{data: data})
36 assert {5, nil} = Repo.update_all(Notification, set: [type: nil])
38 NotificationBackfill.fill_in_notification_types()
40 assert %{type: "mention"} =
41 Repo.get_by(Notification, user_id: other_user.id, activity_id: post.id)
43 assert %{type: "favourite"} =
44 Repo.get_by(Notification, user_id: user.id, activity_id: like.id)
46 assert %{type: "pleroma:emoji_reaction"} =
47 Repo.get_by(Notification, user_id: user.id, activity_id: react.id)
49 assert %{type: "pleroma:emoji_reaction"} =
50 Repo.get_by(Notification, user_id: user.id, activity_id: react_2.id)
52 assert %{type: "pleroma:chat_mention"} =
53 Repo.get_by(Notification, user_id: other_user.id, activity_id: chat.id)