Rename record_fixture* to record*

This commit is contained in:
Claudio Ortolina
2025-01-06 14:20:36 +00:00
parent cf377f6a0c
commit ed6ef2c7ef
12 changed files with 40 additions and 40 deletions
+1 -1
View File
@@ -6,7 +6,7 @@ defmodule MusicLibrary.ArtistsTest do
describe "get_artist/1" do describe "get_artist/1" do
test "it returns records with essential data" do test "it returns records with essential data" do
record = record_fixture() record = record()
[expected] = record.artists [expected] = record.artists
artist = Artists.get_artist!(expected.musicbrainz_id) artist = Artists.get_artist!(expected.musicbrainz_id)
+5 -5
View File
@@ -7,24 +7,24 @@ defmodule MusicLibrary.CollectionTest do
defp fill_collection(_) do defp fill_collection(_) do
# Purchased dates are in ascending order # Purchased dates are in ascending order
records = [ records = [
record_fixture_with_artist("Marillion", %{ record_with_artist("Marillion", %{
title: "Brave", title: "Brave",
format: :cd, format: :cd,
type: :album, type: :album,
purchased_at: ~U[2024-12-27 16:50:57Z] purchased_at: ~U[2024-12-27 16:50:57Z]
}), }),
record_fixture_with_artist("Marillion", %{ record_with_artist("Marillion", %{
title: "Brave (Remastered)", title: "Brave (Remastered)",
format: :vinyl, format: :vinyl,
type: :live, type: :live,
purchased_at: ~U[2024-12-28 16:50:57Z] purchased_at: ~U[2024-12-28 16:50:57Z]
}), }),
record_fixture_with_artist("Marillion", %{ record_with_artist("Marillion", %{
format: :vinyl, format: :vinyl,
type: :ep, type: :ep,
purchased_at: ~U[2024-12-29 16:50:57Z] purchased_at: ~U[2024-12-29 16:50:57Z]
}), }),
record_fixture_with_artist("Marillion", %{ record_with_artist("Marillion", %{
title: "Brave", title: "Brave",
format: :dvd, format: :dvd,
purchased_at: nil, purchased_at: nil,
@@ -90,7 +90,7 @@ defmodule MusicLibrary.CollectionTest do
setup [:fill_collection] setup [:fill_collection]
test "returns the most recently purchased record" do test "returns the most recently purchased record" do
expected_record = record_fixture(%{purchased_at: DateTime.utc_now()}) expected_record = record(%{purchased_at: DateTime.utc_now()})
most_recent_purchase = Collection.get_latest_record!() most_recent_purchase = Collection.get_latest_record!()
assert expected_record.id == most_recent_purchase.id assert expected_record.id == most_recent_purchase.id
+11 -11
View File
@@ -12,11 +12,11 @@ defmodule MusicLibrary.RecordsTest do
defp create_records(_) do defp create_records(_) do
records = [ records = [
record_fixture_with_artist("Marillion", %{title: "Brave", format: :vinyl}), record_with_artist("Marillion", %{title: "Brave", format: :vinyl}),
record_fixture_with_artist("Marillion", %{title: "Brave (Live)", format: :cd, type: :live}), record_with_artist("Marillion", %{title: "Brave (Live)", format: :cd, type: :live}),
record_fixture_with_artist("Marillion", %{title: "Afraid of Sunlight"}), record_with_artist("Marillion", %{title: "Afraid of Sunlight"}),
record_fixture_with_artist("Airbag", %{title: "The Greatest Show on Earth"}), record_with_artist("Airbag", %{title: "The Greatest Show on Earth"}),
record_fixture_with_artist("Airbag (AU)", %{title: "Libertad"}) record_with_artist("Airbag (AU)", %{title: "Libertad"})
] ]
%{records: records} %{records: records}
@@ -33,7 +33,7 @@ defmodule MusicLibrary.RecordsTest do
describe "create_record/1" do describe "create_record/1" do
test "populates computed values" do test "populates computed values" do
record = record =
record_fixture(musicbrainz_data: release_group(:lockdown_trilogy)) record(musicbrainz_data: release_group(:lockdown_trilogy))
assert record.release_ids == ["77e746fc-566f-445b-a62b-cc014280fac9"] assert record.release_ids == ["77e746fc-566f-445b-a62b-cc014280fac9"]
@@ -54,7 +54,7 @@ defmodule MusicLibrary.RecordsTest do
release_group_id = release_group_id(:marbles) release_group_id = release_group_id(:marbles)
record = record =
record_fixture( record(
musicbrainz_id: release_group_id, musicbrainz_id: release_group_id,
musicbrainz_data: Map.put(release_group(:marbles), "releases", []) musicbrainz_data: Map.put(release_group(:marbles), "releases", [])
) )
@@ -149,7 +149,7 @@ defmodule MusicLibrary.RecordsTest do
test "it fetches the record by id" do test "it fetches the record by id" do
# while this test may seem redundant, it implicitely checks that ALL record fields are returned, # while this test may seem redundant, it implicitely checks that ALL record fields are returned,
# as opposed to other code paths where we only return essential ones. # as opposed to other code paths where we only return essential ones.
expected = record_fixture() expected = record()
assert expected == Records.get_record!(expected.id) assert expected == Records.get_record!(expected.id)
end end
@@ -157,7 +157,7 @@ defmodule MusicLibrary.RecordsTest do
describe "get_artists_records/1" do describe "get_artists_records/1" do
test "it returns records with essential data" do test "it returns records with essential data" do
expected = record_fixture() expected = record()
artist_musicbrainz_id = expected.artists |> hd() |> Map.get(:musicbrainz_id) artist_musicbrainz_id = expected.artists |> hd() |> Map.get(:musicbrainz_id)
@@ -171,7 +171,7 @@ defmodule MusicLibrary.RecordsTest do
test "it returns the record cover by id" do test "it returns the record cover by id" do
# while this test may seem redundant, it implicitely checks that ALL record fields are returned, # while this test may seem redundant, it implicitely checks that ALL record fields are returned,
# as opposed to other code paths where we only return essential ones. # as opposed to other code paths where we only return essential ones.
expected = record_fixture() expected = record()
assert Map.take(expected, [:cover_hash, :cover_data]) == Records.get_cover(expected.id) assert Map.take(expected, [:cover_hash, :cover_data]) == Records.get_cover(expected.id)
end end
@@ -293,7 +293,7 @@ defmodule MusicLibrary.RecordsTest do
describe "refresh cover/1" do describe "refresh cover/1" do
test "it fetches and stores the updated cover" do test "it fetches and stores the updated cover" do
record = record_fixture(cover_data: File.read!(marbles_cover_fixture())) record = record(cover_data: File.read!(marbles_cover_fixture()))
raven_cover_data = File.read!(raven_cover_fixture()) raven_cover_data = File.read!(raven_cover_fixture())
+4 -4
View File
@@ -6,10 +6,10 @@ defmodule MusicLibrary.WishlistTest do
defp fill_wishlist(_) do defp fill_wishlist(_) do
records = [ records = [
record_fixture(%{purchased_at: nil, title: "Brave"}), record(%{purchased_at: nil, title: "Brave"}),
record_fixture(%{purchased_at: nil, title: "Brave"}), record(%{purchased_at: nil, title: "Brave"}),
record_fixture(%{purchased_at: nil}), record(%{purchased_at: nil}),
record_fixture(%{title: "Brave"}) record(%{title: "Brave"})
] ]
%{wishlist: records} %{wishlist: records}
@@ -4,7 +4,7 @@ defmodule MusicLibraryWeb.CollectionControllerTest do
import MusicLibrary.RecordsFixtures import MusicLibrary.RecordsFixtures
defp create_record(_) do defp create_record(_) do
%{record: record_fixture_with_artist("Steven Wilson")} %{record: record_with_artist("Steven Wilson")}
end end
defp api_token do defp api_token do
@@ -5,7 +5,7 @@ defmodule MusicLibraryWeb.CoverControllerTest do
alias MusicLibrary.Records.Cover alias MusicLibrary.Records.Cover
defp create_record(_) do defp create_record(_) do
%{record: record_fixture()} %{record: record()}
end end
describe "GET /covers/:record_id" do describe "GET /covers/:record_id" do
@@ -17,7 +17,7 @@ defmodule MusicLibraryWeb.ArtistLive.ShowTest do
defp fill_collection(_config) do defp fill_collection(_config) do
collection_record = collection_record =
record_fixture_with_artist("Steven Wilson", %{ record_with_artist("Steven Wilson", %{
title: "The Raven that refused to sing", title: "The Raven that refused to sing",
purchased_at: DateTime.utc_now() purchased_at: DateTime.utc_now()
}) })
@@ -74,13 +74,13 @@ defmodule MusicLibraryWeb.ArtistLive.ShowTest do
artist_musicbrainz_id: artist_musicbrainz_id artist_musicbrainz_id: artist_musicbrainz_id
} do } do
wishlist_record = wishlist_record =
record_fixture_with_artist("Steven Wilson", %{ record_with_artist("Steven Wilson", %{
title: "Grace for drowning", title: "Grace for drowning",
purchased_at: nil purchased_at: nil
}) })
other_collection_record = other_collection_record =
record_fixture_with_artist("Porcupine Tree", %{purchased_at: DateTime.utc_now()}) record_with_artist("Porcupine Tree", %{purchased_at: DateTime.utc_now()})
# for this test, we don't care about the artist info, but we mock it to avoid false test failures # for this test, we don't care about the artist info, but we mock it to avoid false test failures
expect(APIBehaviourMock, :get_artist_info, fn {:musicbrainz_id, ^artist_musicbrainz_id}, expect(APIBehaviourMock, :get_artist_info, fn {:musicbrainz_id, ^artist_musicbrainz_id},
@@ -13,12 +13,12 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
@total_records @default_records_page_size + 10 @total_records @default_records_page_size + 10
defp fill_collection(_) do defp fill_collection(_) do
records = Enum.map(1..@total_records, fn _ -> record_fixture() end) records = Enum.map(1..@total_records, fn _ -> record() end)
%{collection: records} %{collection: records}
end end
defp fill_wishlist(_) do defp fill_wishlist(_) do
records = Enum.map(1..@total_records, fn _ -> record_fixture(%{purchased_at: nil}) end) records = Enum.map(1..@total_records, fn _ -> record(%{purchased_at: nil}) end)
%{wishlist: records} %{wishlist: records}
end end
@@ -216,7 +216,7 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
describe "Updating record metadata" do describe "Updating record metadata" do
test "can navigate to the record edit form", %{conn: conn} do test "can navigate to the record edit form", %{conn: conn} do
record = record_fixture() record = record()
conn conn
|> visit(~p"/collection") |> visit(~p"/collection")
@@ -226,7 +226,7 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
end end
test "can change the record cover", %{conn: conn} do test "can change the record cover", %{conn: conn} do
record = record_fixture(cover_data: File.read!(marbles_cover_fixture())) record = record(cover_data: File.read!(marbles_cover_fixture()))
session = visit(conn, ~p"/collection/#{record.id}/edit") session = visit(conn, ~p"/collection/#{record.id}/edit")
session session
@@ -12,7 +12,7 @@ defmodule MusicLibraryWeb.CollectionLive.ShowTest do
describe "Edit record from show page" do describe "Edit record from show page" do
test "can navigate to the record edit form", %{conn: conn} do test "can navigate to the record edit form", %{conn: conn} do
record = record_fixture() record = record()
conn conn
|> visit(~p"/collection/#{record.id}") |> visit(~p"/collection/#{record.id}")
@@ -24,7 +24,7 @@ defmodule MusicLibraryWeb.CollectionLive.ShowTest do
describe "Show record" do describe "Show record" do
test "it includes all needed information", %{conn: conn} do test "it includes all needed information", %{conn: conn} do
record = record_fixture() record = record()
session = session =
conn conn
@@ -11,12 +11,12 @@ defmodule MusicLibraryWeb.StatsLive.IndexTest do
setup :verify_on_exit! setup :verify_on_exit!
defp fill_collection(_) do defp fill_collection(_) do
records = Enum.map(1..19, fn _ -> record_fixture() end) records = Enum.map(1..19, fn _ -> record() end)
%{collection: records} %{collection: records}
end end
defp fill_wishlist(_) do defp fill_wishlist(_) do
records = Enum.map(1..21, fn _ -> record_fixture(%{purchased_at: nil}) end) records = Enum.map(1..21, fn _ -> record(%{purchased_at: nil}) end)
%{wishlist: records} %{wishlist: records}
end end
@@ -160,12 +160,12 @@ defmodule MusicLibraryWeb.StatsLive.IndexTest do
# their status in the scrobble activity changes. # their status in the scrobble activity changes.
_machinarium_soundtrack = _machinarium_soundtrack =
record_fixture(purchased_at: nil) record(purchased_at: nil)
|> Records.change_record(%{release_ids: ["4bad26f6-1b27-4554-93bd-40b91ed7866c"]}) |> Records.change_record(%{release_ids: ["4bad26f6-1b27-4554-93bd-40b91ed7866c"]})
|> Repo.update!() |> Repo.update!()
_the_last_flight = _the_last_flight =
record_fixture(purchased_at: DateTime.utc_now()) record(purchased_at: DateTime.utc_now())
|> Records.change_record(%{release_ids: ["2157367e-bf73-48bb-8185-41023a54fa08"]}) |> Records.change_record(%{release_ids: ["2157367e-bf73-48bb-8185-41023a54fa08"]})
|> Repo.update!() |> Repo.update!()
@@ -4,7 +4,7 @@ defmodule MusicLibraryWeb.WishlistLive.IndexTest do
import MusicLibrary.RecordsFixtures import MusicLibrary.RecordsFixtures
defp fill_wishlist(_) do defp fill_wishlist(_) do
records = Enum.map(1..5, fn _ -> record_fixture(%{purchased_at: nil}) end) records = Enum.map(1..5, fn _ -> record(%{purchased_at: nil}) end)
%{wishlist: records} %{wishlist: records}
end end
+3 -3
View File
@@ -50,7 +50,7 @@ defmodule MusicLibrary.RecordsFixtures do
def marbles_thumb_fixture, do: @marbles_thumb_data_path def marbles_thumb_fixture, do: @marbles_thumb_data_path
def raven_cover_fixture, do: @raven_cover_data_path def raven_cover_fixture, do: @raven_cover_data_path
def record_fixture(attrs \\ %{}) do def record(attrs \\ %{}) do
record_musicbrainz_id = Ecto.UUID.generate() record_musicbrainz_id = Ecto.UUID.generate()
artist_name = Enum.random(@artists) artist_name = Enum.random(@artists)
current_time = DateTime.utc_now() current_time = DateTime.utc_now()
@@ -75,10 +75,10 @@ defmodule MusicLibrary.RecordsFixtures do
record record
end end
def record_fixture_with_artist(artist_name, record_attrs \\ %{}) do def record_with_artist(artist_name, record_attrs \\ %{}) do
record_attrs record_attrs
|> Map.put(:artists, [artist_attrs(artist_name)]) |> Map.put(:artists, [artist_attrs(artist_name)])
|> record_fixture() |> record()
end end
defp artist_attrs(name) do defp artist_attrs(name) do