RichMedia: Add support for disabling wss streaming out on backfill

This commit is contained in:
Phantasm 2026-05-20 20:16:19 +02:00
commit 678fe8a064
No known key found for this signature in database
GPG key ID: 2669E588BCC634C8
4 changed files with 79 additions and 16 deletions

View file

@ -5,12 +5,20 @@
defmodule Pleroma.Web.RichMedia.BackfillTest do
use Pleroma.DataCase
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.RichMedia.Backfill
alias Pleroma.Web.RichMedia.Card
import Mox
import Pleroma.Factory
setup_all do: clear_config([:rich_media, :enabled], true)
setup do
clear_config([:rich_media, :enabled], true)
Mox.stub_with(Pleroma.CachexMock, Pleroma.NullCache)
:ok
end
test "sets a negative cache entry for an error" do
url = "https://bad.example.com/"
@ -45,4 +53,50 @@ defmodule Pleroma.Web.RichMedia.BackfillTest do
Backfill.run(%{"url" => url})
end
test "streams out update when stream == true" do
url = "https://example.com"
user = insert(:user)
Tesla.Mock.mock(fn %{url: ^url} ->
{:ok,
%Tesla.Env{
status: 200,
body: "<head><meta name=\"twitter:title\" content=\"Cofe\"></head>"
}}
end)
{:ok, activity} = CommonAPI.post(user, %{status: "#cofe #{url}"})
Pleroma.CachexMock
|> expect(:put, fn :rich_media_cache, _, _ -> {:ok, true} end)
Pleroma.Web.ActivityPub.ActivityPubMock
|> expect(:stream_out, fn _ -> :ok end)
Backfill.run(%{"url" => url, "activity_id" => "#{activity.data["id"]}", "stream" => true})
end
test "does not stream out update when stream == false" do
url = "https://example.com"
user = insert(:user)
Tesla.Mock.mock(fn %{url: ^url} ->
{:ok,
%Tesla.Env{
status: 200,
body: "<head><meta name=\"twitter:title\" content=\"Cofe\"></head>"
}}
end)
{:ok, activity} = CommonAPI.post(user, %{status: "#cofe #{url}"})
Pleroma.CachexMock
|> expect(:put, fn :rich_media_cache, _, _ -> {:ok, true} end)
Pleroma.Web.ActivityPub.ActivityPubMock
|> deny(:stream_out, 1)
Backfill.run(%{"url" => url, "activity_id" => "#{activity.data["id"]}", "stream" => false})
end
end