Remove duplication in artists attributes fixture generation

This commit is contained in:
Claudio Ortolina
2024-11-11 12:41:56 +00:00
parent 066fb30b21
commit bcf555ea4c
+11 -20
View File
@@ -52,15 +52,6 @@ defmodule MusicLibrary.RecordsFixtures do
artist_name = Enum.random(@artists) artist_name = Enum.random(@artists)
current_time = DateTime.utc_now() current_time = DateTime.utc_now()
artists_attrs = [
%{
name: artist_name,
musicbrainz_id: artist_uuid(artist_name),
sort_name: artist_name,
disambiguation: artist_name
}
]
{:ok, record} = {:ok, record} =
attrs attrs
|> Enum.into(%{ |> Enum.into(%{
@@ -73,7 +64,7 @@ defmodule MusicLibrary.RecordsFixtures do
format: Record.formats() |> Enum.random(), format: Record.formats() |> Enum.random(),
release: Enum.random(1969..2024) |> Integer.to_string(), release: Enum.random(1969..2024) |> Integer.to_string(),
purchased_at: current_time, purchased_at: current_time,
artists: artists_attrs artists: [artist_attrs(artist_name)]
}) })
|> MusicLibrary.Records.create_record() |> MusicLibrary.Records.create_record()
@@ -81,20 +72,20 @@ defmodule MusicLibrary.RecordsFixtures do
end end
def record_fixture_with_artist(artist_name, record_attrs \\ %{}) do def record_fixture_with_artist(artist_name, record_attrs \\ %{}) do
artists_attrs = [
%{
name: artist_name,
musicbrainz_id: artist_uuid(artist_name),
sort_name: artist_name,
disambiguation: artist_name
}
]
record_attrs record_attrs
|> Map.put(:artists, artists_attrs) |> Map.put(:artists, [artist_attrs(artist_name)])
|> record_fixture() |> record_fixture()
end end
defp artist_attrs(name) do
%{
name: name,
musicbrainz_id: artist_uuid(name),
sort_name: name,
disambiguation: name
}
end
# The following functions have been lifted from `Ecto.UUID`'s source. # The following functions have been lifted from `Ecto.UUID`'s source.
# The purpose is to provide a deterministic implementation of uuid generation # The purpose is to provide a deterministic implementation of uuid generation
# that can be used in tests to generate the same artist uuid. # that can be used in tests to generate the same artist uuid.