Add translation module for Argos Translate (#351)
[akkoma] / test / pleroma / marker_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.MarkerTest do
6 use Pleroma.DataCase, async: true
7 alias Pleroma.Marker
8
9 import Pleroma.Factory
10
11 describe "multi_set_unread_count/3" do
12 test "returns multi" do
13 user = insert(:user)
14
15 assert %Ecto.Multi{
16 operations: [marker: {:run, _}, counters: {:run, _}]
17 } =
18 Marker.multi_set_last_read_id(
19 Ecto.Multi.new(),
20 user,
21 "notifications"
22 )
23 end
24
25 test "return empty multi" do
26 user = insert(:user)
27 multi = Ecto.Multi.new()
28 assert Marker.multi_set_last_read_id(multi, user, "home") == multi
29 end
30 end
31
32 describe "get_markers/2" do
33 test "returns user markers" do
34 user = insert(:user)
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)
39
40 assert Marker.get_markers(
41 user,
42 ["notifications"]
43 ) == [%Marker{refresh_record(marker) | unread_count: 2}]
44 end
45 end
46
47 describe "upsert/2" do
48 test "creates a marker" do
49 user = insert(:user)
50
51 {:ok, %{"notifications" => %Marker{} = marker}} =
52 Marker.upsert(
53 user,
54 %{"notifications" => %{"last_read_id" => "34"}}
55 )
56
57 assert marker.timeline == "notifications"
58 assert marker.last_read_id == "34"
59 assert marker.lock_version == 0
60 end
61
62 test "updates exist marker" do
63 user = insert(:user)
64 marker = insert(:marker, user: user, last_read_id: "8909")
65
66 {:ok, %{"notifications" => %Marker{}}} =
67 Marker.upsert(
68 user,
69 %{"notifications" => %{"last_read_id" => "9909"}}
70 )
71
72 marker = refresh_record(marker)
73 assert marker.timeline == "notifications"
74 assert marker.last_read_id == "9909"
75 assert marker.lock_version == 0
76 end
77 end
78 end