logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

notification_backfill_test.exs (1933B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.MigrationHelper.NotificationBackfillTest do
  5. use Pleroma.DataCase
  6. alias Pleroma.Activity
  7. alias Pleroma.MigrationHelper.NotificationBackfill
  8. alias Pleroma.Notification
  9. alias Pleroma.Repo
  10. alias Pleroma.Web.CommonAPI
  11. import Pleroma.Factory
  12. describe "fill_in_notification_types" do
  13. test "it fills in missing notification types" do
  14. user = insert(:user)
  15. other_user = insert(:user)
  16. {:ok, post} = CommonAPI.post(user, %{status: "yeah, @#{other_user.nickname}"})
  17. {:ok, chat} = CommonAPI.post_chat_message(user, other_user, "yo")
  18. {:ok, react} = CommonAPI.react_with_emoji(post.id, other_user, "☕")
  19. {:ok, like} = CommonAPI.favorite(other_user, post.id)
  20. {:ok, react_2} = CommonAPI.react_with_emoji(post.id, other_user, "☕")
  21. data =
  22. react_2.data
  23. |> Map.put("type", "EmojiReaction")
  24. {:ok, react_2} =
  25. react_2
  26. |> Activity.change(%{data: data})
  27. |> Repo.update()
  28. assert {5, nil} = Repo.update_all(Notification, set: [type: nil])
  29. NotificationBackfill.fill_in_notification_types()
  30. assert %{type: "mention"} =
  31. Repo.get_by(Notification, user_id: other_user.id, activity_id: post.id)
  32. assert %{type: "favourite"} =
  33. Repo.get_by(Notification, user_id: user.id, activity_id: like.id)
  34. assert %{type: "pleroma:emoji_reaction"} =
  35. Repo.get_by(Notification, user_id: user.id, activity_id: react.id)
  36. assert %{type: "pleroma:emoji_reaction"} =
  37. Repo.get_by(Notification, user_id: user.id, activity_id: react_2.id)
  38. assert %{type: "pleroma:chat_mention"} =
  39. Repo.get_by(Notification, user_id: other_user.id, activity_id: chat.id)
  40. end
  41. end
  42. end