diff options
author | Maksim Pechnikov <parallel588@gmail.com> | 2019-10-24 09:50:41 +0300 |
---|---|---|
committer | Maksim Pechnikov <parallel588@gmail.com> | 2019-10-24 12:17:50 +0300 |
commit | 922e3d082c38ccd108710e21d4bda8e65b551f9c (patch) | |
tree | ec507af94b47050efb8f263dd74ede0f72bf9514 | |
parent | 99cf1ef9be93ebab04d088848804369e6295a76d (diff) | |
download | pleroma-922e3d082c38ccd108710e21d4bda8e65b551f9c.tar.gz |
add test
-rw-r--r-- | lib/pleroma/marker.ex | 14 | ||||
-rw-r--r-- | lib/pleroma/notification.ex | 14 | ||||
-rw-r--r-- | test/marker_test.exs | 6 |
3 files changed, 21 insertions, 13 deletions
diff --git a/lib/pleroma/marker.ex b/lib/pleroma/marker.ex index 5f6a47f38..a7ea542dd 100644 --- a/lib/pleroma/marker.ex +++ b/lib/pleroma/marker.ex @@ -51,19 +51,7 @@ defmodule Pleroma.Marker do def multi_set_unread_count(multi, %User{} = user, "notifications") do multi |> Multi.run(:counters, fn _repo, _changes -> - query = - from(q in Pleroma.Notification, - where: q.user_id == ^user.id, - select: %{ - 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) - } - ) - - {:ok, Repo.one(query)} + {:ok, Repo.one(Pleroma.Notification.notifications_info_query(user))} end) |> Multi.insert( :marker, diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index af56cc667..373f9b06a 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -36,6 +36,20 @@ defmodule Pleroma.Notification do |> cast(attrs, [:seen]) end + @spec notifications_info_query(User.t()) :: Ecto.Queryable.t() + def notifications_info_query(user) do + from(q in Pleroma.Notification, + where: q.user_id == ^user.id, + select: %{ + 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) + } + ) + end + def for_user_query(user, opts \\ []) do Notification |> where(user_id: ^user.id) diff --git a/test/marker_test.exs b/test/marker_test.exs index 1900ed08b..5d03db48e 100644 --- a/test/marker_test.exs +++ b/test/marker_test.exs @@ -21,6 +21,12 @@ defmodule Pleroma.MarkerTest do "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 |