1
0
Fork 0
mirror of https://framagit.org/framasoft/mobilizon.git synced 2024-12-23 00:14:48 +00:00
mobilizon/test/federation/activity_stream/converter/utils_test.exs
André Menrath 0d7462de06
Improve the detection of a banner image.
- Also accept attachments of type Image
- Prefer the key "image" if it is set as the banner image (https://www.w3.org/TR/activitystreams-vocabulary/#dfn-object)
- solves #1399

Co-authored-by: Thomas Citharel <tcit@tcit.fr>
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
2024-02-08 16:55:35 +01:00

76 lines
2.5 KiB
Elixir

defmodule Mobilizon.Federation.ActivityStream.Converter.UtilsTest do
@moduledoc """
Module to test converting from EventMetadata to AS
"""
use Mobilizon.DataCase
import Mobilizon.Factory
alias Mobilizon.Federation.ActivityStream.Converter.Utils
describe "get_medias/1" do
test "getting banner from Document attachment" do
data =
File.read!("test/fixtures/mobilizon-post-activity-media.json")
|> Jason.decode!()
|> Map.get("object")
assert Utils.get_medias(data) ==
{%{
"blurhash" => "U5SY?Z00nOxu7ORP.8-pU^kVS#NGXyxbMxM{",
"mediaType" => "image/png",
"name" => nil,
"type" => "Document",
"url" => "https://mobilizon.fr/some-image"
}, []}
end
test "getting banner from image property" do
data =
File.read!("test/fixtures/mobilizon-post-activity-media-1.json")
|> Jason.decode!()
|> Map.get("object")
assert Utils.get_medias(data) ==
{%{
"blurhash" => "U5SY?Z00nOxu7ORP.8-pU^kVS#NGXyxbMxM{",
"mediaType" => "image/png",
"name" => nil,
"type" => "Image",
"url" => "https://mobilizon.fr/some-image-1"
},
[
%{
"blurhash" => "U5SY?Z00nOxu7ORP.8-pU^kVS#NGXyxbMxM{",
"mediaType" => "image/png",
"name" => nil,
"type" => "Document",
"url" => "https://mobilizon.fr/some-image"
}
]}
end
test "getting banner from attachment named \"Banner\"" do
data =
File.read!("test/fixtures/mobilizon-post-activity-media-2.json")
|> Jason.decode!()
|> Map.get("object")
assert Utils.get_medias(data) ==
{%{
"blurhash" => "U5SY?Z00nOxu7ORP.8-pU^kVS#NGXyxbMxM{",
"mediaType" => "image/png",
"name" => "Banner",
"type" => "Document",
"url" => "https://mobilizon.fr/some-image-2"
},
[
%{
"blurhash" => "U5SY?Z00nOxu7ORP.8-pU^kVS#NGXyxbMxM{",
"mediaType" => "image/png",
"name" => nil,
"type" => "Document",
"url" => "https://mobilizon.fr/some-image-1"
}
]}
end
end
end