1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.MarkerTest do
11 describe "multi_set_unread_count/3" do
12 test "returns multi" do
16 operations: [marker: {:run, _}, counters: {:run, _}]
18 Marker.multi_set_unread_count(
25 test "return empty multi" do
27 multi = Ecto.Multi.new()
28 assert Marker.multi_set_unread_count(multi, user, "home") == multi
32 describe "get_markers/2" do
33 test "returns user markers" do
35 marker = insert(:marker, user: user)
36 insert(:marker, timeline: "home", user: user)
37 assert Marker.get_markers(user, ["notifications"]) == [refresh_record(marker)]
40 test "returns user markers with recount unread notifications" do
42 marker = insert(:marker, user: user)
43 insert(:notification, user: user)
44 insert(:notification, user: user)
45 insert(:marker, timeline: "home", user: user)
47 assert Marker.get_markers(
50 %{recount_unread: true}
51 ) == [%Marker{refresh_record(marker) | unread_count: 2}]
55 describe "upsert/2" do
56 test "creates a marker" do
59 {:ok, %{"notifications" => %Marker{} = marker}} =
62 %{"notifications" => %{"last_read_id" => "34"}}
65 assert marker.timeline == "notifications"
66 assert marker.last_read_id == "34"
67 assert marker.lock_version == 0
70 test "updates exist marker" do
72 marker = insert(:marker, user: user, last_read_id: "8909")
74 {:ok, %{"notifications" => %Marker{}}} =
77 %{"notifications" => %{"last_read_id" => "9909"}}
80 marker = refresh_record(marker)
81 assert marker.timeline == "notifications"
82 assert marker.last_read_id == "9909"
83 assert marker.lock_version == 0