Show only visible announcements in MastodonAPI

This commit is contained in:
Tusooa Zhu 2022-03-08 19:17:49 -05:00
parent cf8334dbc1
commit d569694ae9
No known key found for this signature in database
GPG Key ID: 7B467EDE43A08224
2 changed files with 25 additions and 1 deletions

View File

@ -46,7 +46,7 @@ defmodule Pleroma.Web.MastodonAPI.AnnouncementController do
end end
defp all_visible do defp all_visible do
Announcement.list_all() Announcement.list_all_visible()
end end
@doc "POST /api/v1/announcements/:id/dismiss" @doc "POST /api/v1/announcements/:id/dismiss"

View File

@ -23,6 +23,30 @@ defmodule Pleroma.Web.MastodonAPI.AnnouncementControllerTest do
refute Map.has_key?(Enum.at(response, 0), "read") refute Map.has_key?(Enum.at(response, 0), "read")
end end
test "it does not list announcements starting after current time" do
time = NaiveDateTime.utc_now() |> NaiveDateTime.add(999999, :second)
insert(:announcement, starts_at: time)
response =
build_conn()
|> get("/api/v1/announcements")
|> json_response_and_validate_schema(:ok)
assert [] = response
end
test "it does not list announcements ending before current time" do
time = NaiveDateTime.utc_now() |> NaiveDateTime.add(-999999, :second)
insert(:announcement, ends_at: time)
response =
build_conn()
|> get("/api/v1/announcements")
|> json_response_and_validate_schema(:ok)
assert [] = response
end
test "when authenticated, also expose read property" do test "when authenticated, also expose read property" do
%{id: id} = insert(:announcement) %{id: id} = insert(:announcement)