fix(mastodon-api): finish preview card compatibility

This commit is contained in:
Lain Soykaf 2026-07-26 13:55:57 +04:00
commit c591ca518c
No known key found for this signature in database
6 changed files with 174 additions and 115 deletions

View file

@ -2430,6 +2430,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
describe "cards" do
setup do
clear_config([:rich_media, :enabled], true)
Mox.stub_with(Pleroma.CachexMock, Pleroma.NullCache)
Pleroma.StaticStubbedConfigMock
|> stub(:get, fn
[:rich_media, :enabled] -> true
@ -2443,6 +2446,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
{:ok, activity} = CommonAPI.post(user, %{status: "https://example.com/ogp"})
ObanHelpers.perform_all()
card_data = %{
"image" => "http://ia.media-imdb.com/images/rock.jpg",
@ -2465,10 +2469,14 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
},
"author_name" => "",
"author_url" => "",
"authors" => [],
"blurhash" => nil,
"embed_url" => "",
"height" => 0,
"html" => "",
"image_description" => "",
"language" => nil,
"published_at" => nil,
"width" => 0
}
@ -2495,6 +2503,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
{:ok, activity} = CommonAPI.post(user, %{status: "https://example.com/ogp-missing-data"})
ObanHelpers.perform_all()
response =
conn
@ -2518,10 +2527,14 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
},
"author_name" => "",
"author_url" => "",
"authors" => [],
"blurhash" => nil,
"embed_url" => "",
"height" => 0,
"html" => "",
"image_description" => "",
"language" => nil,
"published_at" => nil,
"width" => 0
}
end

View file

@ -845,15 +845,31 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
fields = %{
"url" => page_url,
"site_name" => "Example site name",
"type" => "photo",
"title" => "Example website",
"image" => page_url <> "/example.jpg",
"description" => "Example description"
"description" => "Example description",
"author_name" => "Example author",
"author_url" => page_url <> "/author",
"provider_name" => "Example provider",
"provider_url" => page_url <> "/provider",
"html" => "<img src=\"#{page_url}/example.jpg\">",
"width" => "1024",
"height" => 768
}
{:ok, card} = Card.create(page_url, fields)
assert match?(%{provider_name: "example.com"}, StatusView.render("card.json", card))
assert %{
type: "photo",
author_name: "Example author",
author_url: "https://example.com/author",
provider_name: "Example provider",
provider_url: "https://example.com/provider",
html: "<img src=\"https://example.com/example.jpg\">",
width: 1024,
height: 768
} = StatusView.render("card.json", card)
end
test "a rich media card has all media proxied" do