Merge branch 'issue/1276-2' into 'develop'
[#1276] added an endpoint for getting unread notification count See merge request pleroma/pleroma!2392
This commit is contained in:
commit
0cf43391f2
13 changed files with 237 additions and 26 deletions
|
|
@ -8,12 +8,39 @@ 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_last_read_id(
|
||||
Ecto.Multi.new(),
|
||||
user,
|
||||
"notifications"
|
||||
)
|
||||
end
|
||||
|
||||
test "return empty multi" do
|
||||
user = insert(:user)
|
||||
multi = Ecto.Multi.new()
|
||||
assert Marker.multi_set_last_read_id(multi, user, "home") == multi
|
||||
end
|
||||
end
|
||||
|
||||
describe "get_markers/2" do
|
||||
test "returns user markers" do
|
||||
user = insert(:user)
|
||||
marker = insert(:marker, user: user)
|
||||
insert(:notification, user: user)
|
||||
insert(:notification, user: user)
|
||||
insert(:marker, timeline: "home", user: user)
|
||||
assert Marker.get_markers(user, ["notifications"]) == [refresh_record(marker)]
|
||||
|
||||
assert Marker.get_markers(
|
||||
user,
|
||||
["notifications"]
|
||||
) == [%Marker{refresh_record(marker) | unread_count: 2}]
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -47,6 +47,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
|
||||
|
|
@ -466,6 +469,16 @@ defmodule Pleroma.NotificationTest do
|
|||
assert n1.seen == true
|
||||
assert n2.seen == true
|
||||
assert n3.seen == false
|
||||
|
||||
assert %Pleroma.Marker{} =
|
||||
m =
|
||||
Pleroma.Repo.get_by(
|
||||
Pleroma.Marker,
|
||||
user_id: other_user.id,
|
||||
timeline: "notifications"
|
||||
)
|
||||
|
||||
assert m.last_read_id == to_string(n2.id)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1196,12 +1196,15 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
describe "verify_credentials" do
|
||||
test "verify_credentials" do
|
||||
%{user: user, conn: conn} = oauth_access(["read:accounts"])
|
||||
[notification | _] = insert_list(7, :notification, user: user)
|
||||
Pleroma.Notification.set_read_up_to(user, notification.id)
|
||||
conn = get(conn, "/api/v1/accounts/verify_credentials")
|
||||
|
||||
response = json_response_and_validate_schema(conn, 200)
|
||||
|
||||
assert %{"id" => id, "source" => %{"privacy" => "public"}} = response
|
||||
assert response["pleroma"]["chat_token"]
|
||||
assert response["pleroma"]["unread_notifications_count"] == 6
|
||||
assert id == to_string(user.id)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ defmodule Pleroma.Web.MastodonAPI.MarkerControllerTest do
|
|||
test "gets markers with correct scopes", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
token = insert(:oauth_token, user: user, scopes: ["read:statuses"])
|
||||
insert_list(7, :notification, user: user)
|
||||
|
||||
{:ok, %{"notifications" => marker}} =
|
||||
Pleroma.Marker.upsert(
|
||||
|
|
@ -29,7 +30,8 @@ defmodule Pleroma.Web.MastodonAPI.MarkerControllerTest do
|
|||
"notifications" => %{
|
||||
"last_read_id" => "69420",
|
||||
"updated_at" => NaiveDateTime.to_iso8601(marker.updated_at),
|
||||
"version" => 0
|
||||
"version" => 0,
|
||||
"pleroma" => %{"unread_count" => 7}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
|
@ -71,7 +73,8 @@ defmodule Pleroma.Web.MastodonAPI.MarkerControllerTest do
|
|||
"notifications" => %{
|
||||
"last_read_id" => "69420",
|
||||
"updated_at" => _,
|
||||
"version" => 0
|
||||
"version" => 0,
|
||||
"pleroma" => %{"unread_count" => 0}
|
||||
}
|
||||
} = response
|
||||
end
|
||||
|
|
@ -101,7 +104,8 @@ defmodule Pleroma.Web.MastodonAPI.MarkerControllerTest do
|
|||
"notifications" => %{
|
||||
"last_read_id" => "69888",
|
||||
"updated_at" => NaiveDateTime.to_iso8601(marker.updated_at),
|
||||
"version" => 0
|
||||
"version" => 0,
|
||||
"pleroma" => %{"unread_count" => 0}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
|
|
|||
|
|
@ -466,6 +466,24 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
:unread_conversation_count
|
||||
] == 1
|
||||
end
|
||||
|
||||
test "shows unread_count only to the account owner" do
|
||||
user = insert(:user)
|
||||
insert_list(7, :notification, user: user)
|
||||
other_user = insert(:user)
|
||||
|
||||
user = User.get_cached_by_ap_id(user.ap_id)
|
||||
|
||||
assert AccountView.render(
|
||||
"show.json",
|
||||
%{user: user, for: other_user}
|
||||
)[:pleroma][:unread_notifications_count] == nil
|
||||
|
||||
assert AccountView.render(
|
||||
"show.json",
|
||||
%{user: user, for: user}
|
||||
)[:pleroma][:unread_notifications_count] == 7
|
||||
end
|
||||
end
|
||||
|
||||
describe "follow requests counter" do
|
||||
|
|
|
|||
|
|
@ -8,19 +8,21 @@ 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",
|
||||
updated_at: NaiveDateTime.to_iso8601(marker2.updated_at),
|
||||
version: 0
|
||||
version: 0,
|
||||
pleroma: %{unread_count: 0}
|
||||
},
|
||||
"notifications" => %{
|
||||
last_read_id: "17",
|
||||
updated_at: NaiveDateTime.to_iso8601(marker1.updated_at),
|
||||
version: 0
|
||||
version: 0,
|
||||
pleroma: %{unread_count: 5}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue