giant massive dep upgrade and dialyxir-found error emporium (#371)
[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, 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, "☕")
25
26 data =
27 react_2.data
28 |> Map.put("type", "EmojiReaction")
29
30 {:ok, react_2} =
31 react_2
32 |> Activity.change(%{data: data})
33 |> Repo.update()
34
35 assert {4, nil} = Repo.update_all(Notification, set: [type: nil])
36
37 NotificationBackfill.fill_in_notification_types()
38
39 assert %{type: "mention"} =
40 Repo.get_by(Notification, user_id: other_user.id, activity_id: post.id)
41
42 assert %{type: "favourite"} =
43 Repo.get_by(Notification, user_id: user.id, activity_id: like.id)
44
45 assert %{type: "pleroma:emoji_reaction"} =
46 Repo.get_by(Notification, user_id: user.id, activity_id: react.id)
47
48 assert %{type: "pleroma:emoji_reaction"} =
49 Repo.get_by(Notification, user_id: user.id, activity_id: react_2.id)
50 end
51 end
52 end