diff --git a/lib/pleroma/web/mastodon_api/controllers/announcement_controller.ex b/lib/pleroma/web/mastodon_api/controllers/announcement_controller.ex index f3ec78265..a2179f934 100644 --- a/lib/pleroma/web/mastodon_api/controllers/announcement_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/announcement_controller.ex @@ -46,7 +46,7 @@ defmodule Pleroma.Web.MastodonAPI.AnnouncementController do end defp all_visible do - Announcement.list_all() + Announcement.list_all_visible() end @doc "POST /api/v1/announcements/:id/dismiss" diff --git a/test/pleroma/web/mastodon_api/controllers/announcement_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/announcement_controller_test.exs index aa056be6e..e9ee1141c 100644 --- a/test/pleroma/web/mastodon_api/controllers/announcement_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/announcement_controller_test.exs @@ -23,6 +23,30 @@ defmodule Pleroma.Web.MastodonAPI.AnnouncementControllerTest do refute Map.has_key?(Enum.at(response, 0), "read") 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 %{id: id} = insert(:announcement)