mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-12-17 23:38:19 +00:00
add tests
This commit is contained in:
parent
aa64b3108b
commit
d3fb9e02cc
|
@ -58,7 +58,8 @@ defmodule Pleroma.Marker do
|
|||
timeline: "notifications",
|
||||
user_id: type(^user.id, :string),
|
||||
unread_count: fragment("SUM( CASE WHEN seen = false THEN 1 ELSE 0 END )"),
|
||||
last_read_id: type(fragment("MAX( CASE WHEN seen = true THEN id ELSE null END )"), :string)
|
||||
last_read_id:
|
||||
type(fragment("MAX( CASE WHEN seen = true THEN id ELSE null END )"), :string)
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -77,11 +78,7 @@ defmodule Pleroma.Marker do
|
|||
)
|
||||
end
|
||||
|
||||
def set_unread_count(%User{} = user, timeline) do
|
||||
Multi.new()
|
||||
|> multi_set_unread_count(user, timeline)
|
||||
|> Repo.transaction()
|
||||
end
|
||||
def multi_set_unread_count(multi, _, _), do: multi
|
||||
|
||||
defp get_marker(user, timeline) do
|
||||
case Repo.find_resource(get_query(user, timeline)) do
|
||||
|
|
|
@ -26,7 +26,8 @@ defmodule Pleroma.Repo.Migrations.AddUnreadToMarker do
|
|||
timeline: "notifications",
|
||||
user_id: q.user_id,
|
||||
unread_count: fragment("SUM( CASE WHEN seen = false THEN 1 ELSE 0 END )"),
|
||||
last_read_id: type(fragment("MAX( CASE WHEN seen = true THEN id ELSE null END )"), :string)
|
||||
last_read_id:
|
||||
type(fragment("MAX( CASE WHEN seen = true THEN id ELSE null END )"), :string)
|
||||
},
|
||||
group_by: [q.user_id]
|
||||
)
|
||||
|
|
|
@ -8,6 +8,21 @@ 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
|
||||
end
|
||||
|
||||
describe "get_markers/2" do
|
||||
test "returns user markers" do
|
||||
user = insert(:user)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue