aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/marker_test.exs21
-rw-r--r--test/notification_test.exs10
-rw-r--r--test/web/mastodon_api/controllers/marker_controller_test.exs7
-rw-r--r--test/web/mastodon_api/views/marker_view_test.exs4
4 files changed, 39 insertions, 3 deletions
diff --git a/test/marker_test.exs b/test/marker_test.exs
index 04bd67fe6..5d03db48e 100644
--- a/test/marker_test.exs
+++ b/test/marker_test.exs
@@ -8,6 +8,27 @@ defmodule Pleroma.MarkerTest do
import Pleroma.Factory
+ describe "multi_set_unread_count/3" do
+ test "returns multi" do
+ user = insert(:user)
+
+ assert %Ecto.Multi{
+ operations: [marker: {:run, _}, counters: {:run, _}]
+ } =
+ Marker.multi_set_unread_count(
+ Ecto.Multi.new(),
+ user,
+ "notifications"
+ )
+ end
+
+ test "return empty multi" do
+ user = insert(:user)
+ multi = Ecto.Multi.new()
+ assert Marker.multi_set_unread_count(multi, user, "home") == multi
+ end
+ end
+
describe "get_markers/2" do
test "returns user markers" do
user = insert(:user)
diff --git a/test/notification_test.exs b/test/notification_test.exs
index f8d429223..d358e433f 100644
--- a/test/notification_test.exs
+++ b/test/notification_test.exs
@@ -31,6 +31,9 @@ defmodule Pleroma.NotificationTest do
assert notified_ids == [other_user.id, third_user.id]
assert notification.activity_id == activity.id
assert other_notification.activity_id == activity.id
+
+ assert [%Pleroma.Marker{unread_count: 2}] =
+ Pleroma.Marker.get_markers(other_user, ["notifications"])
end
test "it creates a notification for subscribed users" do
@@ -310,6 +313,13 @@ defmodule Pleroma.NotificationTest do
assert n1.seen == true
assert n2.seen == true
assert n3.seen == false
+
+ assert %Pleroma.Marker{unread_count: 1} =
+ Pleroma.Repo.get_by(
+ Pleroma.Marker,
+ user_id: other_user.id,
+ timeline: "notifications"
+ )
end
end
diff --git a/test/web/mastodon_api/controllers/marker_controller_test.exs b/test/web/mastodon_api/controllers/marker_controller_test.exs
index 1fcad873d..5e7b4001f 100644
--- a/test/web/mastodon_api/controllers/marker_controller_test.exs
+++ b/test/web/mastodon_api/controllers/marker_controller_test.exs
@@ -15,7 +15,7 @@ defmodule Pleroma.Web.MastodonAPI.MarkerControllerTest do
{:ok, %{"notifications" => marker}} =
Pleroma.Marker.upsert(
user,
- %{"notifications" => %{"last_read_id" => "69420"}}
+ %{"notifications" => %{"last_read_id" => "69420", "unread_count" => 7}}
)
response =
@@ -28,6 +28,7 @@ defmodule Pleroma.Web.MastodonAPI.MarkerControllerTest do
assert response == %{
"notifications" => %{
"last_read_id" => "69420",
+ "unread_count" => 7,
"updated_at" => NaiveDateTime.to_iso8601(marker.updated_at),
"version" => 0
}
@@ -70,7 +71,8 @@ defmodule Pleroma.Web.MastodonAPI.MarkerControllerTest do
"notifications" => %{
"last_read_id" => "69420",
"updated_at" => _,
- "version" => 0
+ "version" => 0,
+ "unread_count" => 0
}
} = response
end
@@ -98,6 +100,7 @@ defmodule Pleroma.Web.MastodonAPI.MarkerControllerTest do
assert response == %{
"notifications" => %{
"last_read_id" => "69888",
+ "unread_count" => 0,
"updated_at" => NaiveDateTime.to_iso8601(marker.updated_at),
"version" => 0
}
diff --git a/test/web/mastodon_api/views/marker_view_test.exs b/test/web/mastodon_api/views/marker_view_test.exs
index 8a5c89d56..3ce794617 100644
--- a/test/web/mastodon_api/views/marker_view_test.exs
+++ b/test/web/mastodon_api/views/marker_view_test.exs
@@ -8,17 +8,19 @@ defmodule Pleroma.Web.MastodonAPI.MarkerViewTest do
import Pleroma.Factory
test "returns markers" do
- marker1 = insert(:marker, timeline: "notifications", last_read_id: "17")
+ marker1 = insert(:marker, timeline: "notifications", last_read_id: "17", unread_count: 5)
marker2 = insert(:marker, timeline: "home", last_read_id: "42")
assert MarkerView.render("markers.json", %{markers: [marker1, marker2]}) == %{
"home" => %{
last_read_id: "42",
+ unread_count: 0,
updated_at: NaiveDateTime.to_iso8601(marker2.updated_at),
version: 0
},
"notifications" => %{
last_read_id: "17",
+ unread_count: 5,
updated_at: NaiveDateTime.to_iso8601(marker1.updated_at),
version: 0
}