2020-06-06 07:33:02 -06:00
|
|
|
# Pleroma: A lightweight social networking server
|
2022-02-25 23:11:42 -07:00
|
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
2020-06-06 07:33:02 -06:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-06-09 01:20:55 -06:00
|
|
|
defmodule Pleroma.MigrationHelper.NotificationBackfillTest do
|
2020-12-21 04:21:40 -07:00
|
|
|
use Pleroma.DataCase, async: true
|
2020-06-06 07:33:02 -06:00
|
|
|
|
|
|
|
alias Pleroma.Activity
|
2020-06-09 01:20:55 -06:00
|
|
|
alias Pleroma.MigrationHelper.NotificationBackfill
|
2020-06-06 07:33:02 -06:00
|
|
|
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])
|
|
|
|
|
2020-06-09 01:20:55 -06:00
|
|
|
NotificationBackfill.fill_in_notification_types()
|
2020-06-06 07:33:02 -06:00
|
|
|
|
|
|
|
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
|