defmodule BerrypodWeb.FaviconControllerTest do
use BerrypodWeb.ConnCase, async: false
alias Berrypod.Media
# Minimal valid PNG (1x1 transparent)
@test_png <<137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 1, 0, 0, 0,
1, 8, 6, 0, 0, 0, 31, 21, 196, 137, 0, 0, 0, 10, 73, 68, 65, 84, 120, 156, 98, 0, 0,
0, 2, 0, 1, 226, 33, 188, 51, 0, 0, 0, 0, 73, 69, 78, 68, 174, 66, 96, 130>>
@test_svg ~s()
defp create_source_image do
{:ok, image} =
Media.upload_image(%{
image_type: "icon",
filename: "icon.svg",
content_type: "image/svg+xml",
file_size: byte_size(@test_svg),
data: @test_svg
})
image
end
defp create_favicon_variants(_context) do
image = create_source_image()
{:ok, variants} =
Media.store_favicon_variants(%{
source_image_id: image.id,
png_32: @test_png,
png_180: @test_png,
png_192: @test_png,
png_512: @test_png,
svg: @test_svg
})
%{variants: variants}
end
describe "favicon routes with variants" do
setup [:create_favicon_variants]
test "serves favicon SVG", %{conn: conn} do
conn = get(conn, ~p"/favicon.svg")
assert response_content_type(conn, :xml) =~ "image/svg+xml"
assert conn.status == 200
assert conn.resp_body =~ "