logo

pleroma

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

marker_test.exs (2176B)


  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.MarkerTest do
  5. use Pleroma.DataCase
  6. alias Pleroma.Marker
  7. import Pleroma.Factory
  8. describe "multi_set_unread_count/3" do
  9. test "returns multi" do
  10. user = insert(:user)
  11. assert %Ecto.Multi{
  12. operations: [marker: {:run, _}, counters: {:run, _}]
  13. } =
  14. Marker.multi_set_last_read_id(
  15. Ecto.Multi.new(),
  16. user,
  17. "notifications"
  18. )
  19. end
  20. test "return empty multi" do
  21. user = insert(:user)
  22. multi = Ecto.Multi.new()
  23. assert Marker.multi_set_last_read_id(multi, user, "home") == multi
  24. end
  25. end
  26. describe "get_markers/2" do
  27. test "returns user markers" do
  28. user = insert(:user)
  29. marker = insert(:marker, user: user)
  30. insert(:notification, user: user, activity: insert(:note_activity))
  31. insert(:notification, user: user, activity: insert(:note_activity))
  32. insert(:marker, timeline: "home", user: user)
  33. assert Marker.get_markers(
  34. user,
  35. ["notifications"]
  36. ) == [%Marker{refresh_record(marker) | unread_count: 2}]
  37. end
  38. end
  39. describe "upsert/2" do
  40. test "creates a marker" do
  41. user = insert(:user)
  42. {:ok, %{"notifications" => %Marker{} = marker}} =
  43. Marker.upsert(
  44. user,
  45. %{"notifications" => %{"last_read_id" => "34"}}
  46. )
  47. assert marker.timeline == "notifications"
  48. assert marker.last_read_id == "34"
  49. assert marker.lock_version == 0
  50. end
  51. test "updates exist marker" do
  52. user = insert(:user)
  53. marker = insert(:marker, user: user, last_read_id: "8909")
  54. {:ok, %{"notifications" => %Marker{}}} =
  55. Marker.upsert(
  56. user,
  57. %{"notifications" => %{"last_read_id" => "9909"}}
  58. )
  59. marker = refresh_record(marker)
  60. assert marker.timeline == "notifications"
  61. assert marker.last_read_id == "9909"
  62. assert marker.lock_version == 0
  63. end
  64. end
  65. end