1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.MarkerTest do
6 use Pleroma.DataCase, async: true
11 describe "multi_set_unread_count/3" do
12 test "returns multi" do
16 operations: [marker: {:run, _}, counters: {:run, _}]
18 Marker.multi_set_last_read_id(
25 test "return empty multi" do
27 multi = Ecto.Multi.new()
28 assert Marker.multi_set_last_read_id(multi, user, "home") == multi
32 describe "get_markers/2" do
33 test "returns user markers" do
35 marker = insert(:marker, user: user)
36 insert(:notification, user: user, activity: insert(:note_activity))
37 insert(:notification, user: user, activity: insert(:note_activity))
38 insert(:marker, timeline: "home", user: user)
40 assert Marker.get_markers(
43 ) == [%Marker{refresh_record(marker) | unread_count: 2}]
47 describe "upsert/2" do
48 test "creates a marker" do
51 {:ok, %{"notifications" => %Marker{} = marker}} =
54 %{"notifications" => %{"last_read_id" => "34"}}
57 assert marker.timeline == "notifications"
58 assert marker.last_read_id == "34"
59 assert marker.lock_version == 0
62 test "updates exist marker" do
64 marker = insert(:marker, user: user, last_read_id: "8909")
66 {:ok, %{"notifications" => %Marker{}}} =
69 %{"notifications" => %{"last_read_id" => "9909"}}
72 marker = refresh_record(marker)
73 assert marker.timeline == "notifications"
74 assert marker.last_read_id == "9909"
75 assert marker.lock_version == 0