Add /api/collection endpoint
This commit is contained in:
@@ -28,6 +28,7 @@ defmodule MusicLibraryWeb.CollectionControllerTest do
|
||||
|> get(~p"/api/collection/latest")
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
"id" => record.id,
|
||||
"artists" => ["Steven Wilson"],
|
||||
"title" => record.title,
|
||||
"cover_url" =>
|
||||
@@ -55,6 +56,7 @@ defmodule MusicLibraryWeb.CollectionControllerTest do
|
||||
|> get(~p"/api/collection/random")
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
"id" => record.id,
|
||||
"artists" => ["Steven Wilson"],
|
||||
"title" => record.title,
|
||||
"cover_url" =>
|
||||
@@ -64,4 +66,38 @@ defmodule MusicLibraryWeb.CollectionControllerTest do
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /api/collection" do
|
||||
setup [:create_record]
|
||||
|
||||
test "it requires authentication", %{conn: conn} do
|
||||
conn = get(conn, ~p"/api/collection")
|
||||
|
||||
assert conn.status == 401
|
||||
end
|
||||
|
||||
test "it returns a paginated list of records", %{conn: conn, record: record} do
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("authorization", "Bearer #{api_token()}")
|
||||
|> get(~p"/api/collection")
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
"total" => 1,
|
||||
"limit" => 20,
|
||||
"offset" => 0,
|
||||
"records" => [
|
||||
%{
|
||||
"id" => record.id,
|
||||
"artists" => ["Steven Wilson"],
|
||||
"title" => record.title,
|
||||
"cover_url" =>
|
||||
"http://localhost:4002/api/covers/#{record.id}?vsn=#{record.cover_hash}",
|
||||
"thumb_url" =>
|
||||
"http://localhost:4002/api/covers/#{record.id}?vsn=#{record.cover_hash}&size=480"
|
||||
}
|
||||
]
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user