Support arbitrary resizing in cover controller

This commit is contained in:
Claudio Ortolina
2024-12-31 11:57:56 +00:00
parent 6a51251d55
commit 97533416f7
5 changed files with 49 additions and 2 deletions
@@ -2,6 +2,7 @@ defmodule MusicLibraryWeb.CoverControllerTest do
use MusicLibraryWeb.ConnCase
import MusicLibrary.RecordsFixtures
alias MusicLibrary.Records.Cover
defp create_record(_) do
%{record: record_fixture()}
@@ -55,5 +56,19 @@ defmodule MusicLibraryWeb.CoverControllerTest do
assert conn.resp_body == <<>>
end
test "accepts a size attribute for resizing", %{conn: conn, record: record} do
conn = get(conn, ~p"/covers/#{record.id}?size=480")
thumb = File.read!(marbles_thumb_fixture())
hash = Cover.hash(thumb)
assert conn.status == 200
assert get_resp_header(conn, "content-type") == ["image/jpeg; charset=utf-8"]
assert get_resp_header(conn, "cache-control") == ["public, max-age=86400"]
assert get_resp_header(conn, "etag") == [hash]
assert conn.resp_body == thumb
end
end
end