From 1fdf36ea8ac76232f3f818e447ab6c141a52c972 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Thu, 10 Oct 2024 09:21:35 +0100 Subject: [PATCH] Include artists in record test fixture --- .../controllers/stats_controller_test.exs | 2 +- .../live/record_index_test.exs | 2 +- .../live/record_show_test.exs | 2 +- test/support/fixtures/records_fixtures.ex | 31 ++++++++++++++++--- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/test/music_library_web/controllers/stats_controller_test.exs b/test/music_library_web/controllers/stats_controller_test.exs index 7fadb55c..492455ca 100644 --- a/test/music_library_web/controllers/stats_controller_test.exs +++ b/test/music_library_web/controllers/stats_controller_test.exs @@ -41,7 +41,7 @@ defmodule MusicLibraryWeb.StatsControllerTest do assert html_response(conn, 200) =~ escape(latest_record.title) for artist <- latest_record.artists do - assert html_response(conn, 200) =~ escape(artist["name"]) + assert html_response(conn, 200) =~ escape(artist.name) end end end diff --git a/test/music_library_web/live/record_index_test.exs b/test/music_library_web/live/record_index_test.exs index 6bf8acc6..0ca8d4a8 100644 --- a/test/music_library_web/live/record_index_test.exs +++ b/test/music_library_web/live/record_index_test.exs @@ -49,7 +49,7 @@ defmodule MusicLibraryWeb.RecordIndexTest do assert record_row_html =~ ~p"/covers/#{record.id}?vsn=#{record.cover_hash}" for artist <- record.artists do - assert record_row_html =~ escape(artist["name"]) + assert record_row_html =~ escape(artist.name) end end end diff --git a/test/music_library_web/live/record_show_test.exs b/test/music_library_web/live/record_show_test.exs index 1ca252bf..afb661a3 100644 --- a/test/music_library_web/live/record_show_test.exs +++ b/test/music_library_web/live/record_show_test.exs @@ -40,7 +40,7 @@ defmodule MusicLibraryWeb.RecordShowTest do assert html =~ Phoenix.HTML.Safe.to_iodata(record.updated_at) for artist <- record.artists do - assert html =~ escape(artist["name"]) + assert html =~ escape(artist.name) end end end diff --git a/test/support/fixtures/records_fixtures.ex b/test/support/fixtures/records_fixtures.ex index 861ec105..9cbad072 100644 --- a/test/support/fixtures/records_fixtures.ex +++ b/test/support/fixtures/records_fixtures.ex @@ -28,7 +28,17 @@ defmodule MusicLibrary.RecordsFixtures do "Red", "Foxtrot", "The Lamb Lies Down on Broadway", - "Thick as a Brick" + "Thick as a Brick", + "Marbles", + "Vigil in a Wilderness of Mirrors" + ] + @artists [ + "Steven Wilson", + "King Crimson", + "Pink Floyd", + "Genesis", + "Marillion", + "Fish" ] # While it would be great to have this random, it's ok to use one single image @marbles_cover_data_path "#{__DIR__}/marillion-marbles.jpg" @@ -38,19 +48,30 @@ defmodule MusicLibrary.RecordsFixtures do def raven_cover_fixture, do: @raven_cover_data_path def record_fixture(attrs \\ %{}) do - musicbrainz_id = Ecto.UUID.generate() + record_musicbrainz_id = Ecto.UUID.generate() + artist_name = Enum.random(@artists) + + artists_attrs = [ + %{ + name: artist_name, + musicbrainz_id: Ecto.UUID.generate(), + sort_name: artist_name, + disambiguation: artist_name + } + ] {:ok, record} = attrs |> Enum.into(%{ genres: Enum.take_random(@genres, :rand.uniform(3)), - cover_url: "https://coverartarchive.org/release-group/#{musicbrainz_id}/front", + cover_url: "https://coverartarchive.org/release-group/#{record_musicbrainz_id}/front", cover_data: File.read!(@marbles_cover_data_path), - musicbrainz_id: musicbrainz_id, + musicbrainz_id: record_musicbrainz_id, title: Enum.random(@titles), type: :album, format: Record.formats() |> Enum.random(), - release: Enum.random(1969..2024) |> Integer.to_string() + release: Enum.random(1969..2024) |> Integer.to_string(), + artists: artists_attrs }) |> MusicLibrary.Records.create_record()