[#1427] Reworked admin scopes support.
[akkoma] / test / marker_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.MarkerTest do
6 use Pleroma.DataCase
7 alias Pleroma.Marker
8
9 import Pleroma.Factory
10
11 describe "get_markers/2" do
12 test "returns user markers" do
13 user = insert(:user)
14 marker = insert(:marker, user: user)
15 insert(:marker, timeline: "home", user: user)
16 assert Marker.get_markers(user, ["notifications"]) == [refresh_record(marker)]
17 end
18 end
19
20 describe "upsert/2" do
21 test "creates a marker" do
22 user = insert(:user)
23
24 {:ok, %{"notifications" => %Marker{} = marker}} =
25 Marker.upsert(
26 user,
27 %{"notifications" => %{"last_read_id" => "34"}}
28 )
29
30 assert marker.timeline == "notifications"
31 assert marker.last_read_id == "34"
32 assert marker.lock_version == 0
33 end
34
35 test "updates exist marker" do
36 user = insert(:user)
37 marker = insert(:marker, user: user, last_read_id: "8909")
38
39 {:ok, %{"notifications" => %Marker{}}} =
40 Marker.upsert(
41 user,
42 %{"notifications" => %{"last_read_id" => "9909"}}
43 )
44
45 marker = refresh_record(marker)
46 assert marker.timeline == "notifications"
47 assert marker.last_read_id == "9909"
48 assert marker.lock_version == 0
49 end
50 end
51 end