Rename record_fixture* to record*
This commit is contained in:
@@ -6,7 +6,7 @@ defmodule MusicLibrary.ArtistsTest do
|
||||
|
||||
describe "get_artist/1" do
|
||||
test "it returns records with essential data" do
|
||||
record = record_fixture()
|
||||
record = record()
|
||||
[expected] = record.artists
|
||||
|
||||
artist = Artists.get_artist!(expected.musicbrainz_id)
|
||||
|
||||
@@ -7,24 +7,24 @@ defmodule MusicLibrary.CollectionTest do
|
||||
defp fill_collection(_) do
|
||||
# Purchased dates are in ascending order
|
||||
records = [
|
||||
record_fixture_with_artist("Marillion", %{
|
||||
record_with_artist("Marillion", %{
|
||||
title: "Brave",
|
||||
format: :cd,
|
||||
type: :album,
|
||||
purchased_at: ~U[2024-12-27 16:50:57Z]
|
||||
}),
|
||||
record_fixture_with_artist("Marillion", %{
|
||||
record_with_artist("Marillion", %{
|
||||
title: "Brave (Remastered)",
|
||||
format: :vinyl,
|
||||
type: :live,
|
||||
purchased_at: ~U[2024-12-28 16:50:57Z]
|
||||
}),
|
||||
record_fixture_with_artist("Marillion", %{
|
||||
record_with_artist("Marillion", %{
|
||||
format: :vinyl,
|
||||
type: :ep,
|
||||
purchased_at: ~U[2024-12-29 16:50:57Z]
|
||||
}),
|
||||
record_fixture_with_artist("Marillion", %{
|
||||
record_with_artist("Marillion", %{
|
||||
title: "Brave",
|
||||
format: :dvd,
|
||||
purchased_at: nil,
|
||||
@@ -90,7 +90,7 @@ defmodule MusicLibrary.CollectionTest do
|
||||
setup [:fill_collection]
|
||||
|
||||
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!()
|
||||
|
||||
assert expected_record.id == most_recent_purchase.id
|
||||
|
||||
@@ -12,11 +12,11 @@ defmodule MusicLibrary.RecordsTest do
|
||||
|
||||
defp create_records(_) do
|
||||
records = [
|
||||
record_fixture_with_artist("Marillion", %{title: "Brave", format: :vinyl}),
|
||||
record_fixture_with_artist("Marillion", %{title: "Brave (Live)", format: :cd, type: :live}),
|
||||
record_fixture_with_artist("Marillion", %{title: "Afraid of Sunlight"}),
|
||||
record_fixture_with_artist("Airbag", %{title: "The Greatest Show on Earth"}),
|
||||
record_fixture_with_artist("Airbag (AU)", %{title: "Libertad"})
|
||||
record_with_artist("Marillion", %{title: "Brave", format: :vinyl}),
|
||||
record_with_artist("Marillion", %{title: "Brave (Live)", format: :cd, type: :live}),
|
||||
record_with_artist("Marillion", %{title: "Afraid of Sunlight"}),
|
||||
record_with_artist("Airbag", %{title: "The Greatest Show on Earth"}),
|
||||
record_with_artist("Airbag (AU)", %{title: "Libertad"})
|
||||
]
|
||||
|
||||
%{records: records}
|
||||
@@ -33,7 +33,7 @@ defmodule MusicLibrary.RecordsTest do
|
||||
describe "create_record/1" do
|
||||
test "populates computed values" do
|
||||
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"]
|
||||
|
||||
@@ -54,7 +54,7 @@ defmodule MusicLibrary.RecordsTest do
|
||||
release_group_id = release_group_id(:marbles)
|
||||
|
||||
record =
|
||||
record_fixture(
|
||||
record(
|
||||
musicbrainz_id: release_group_id,
|
||||
musicbrainz_data: Map.put(release_group(:marbles), "releases", [])
|
||||
)
|
||||
@@ -149,7 +149,7 @@ defmodule MusicLibrary.RecordsTest do
|
||||
test "it fetches the record by id" do
|
||||
# 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.
|
||||
expected = record_fixture()
|
||||
expected = record()
|
||||
|
||||
assert expected == Records.get_record!(expected.id)
|
||||
end
|
||||
@@ -157,7 +157,7 @@ defmodule MusicLibrary.RecordsTest do
|
||||
|
||||
describe "get_artists_records/1" do
|
||||
test "it returns records with essential data" do
|
||||
expected = record_fixture()
|
||||
expected = record()
|
||||
|
||||
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
|
||||
# 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.
|
||||
expected = record_fixture()
|
||||
expected = record()
|
||||
|
||||
assert Map.take(expected, [:cover_hash, :cover_data]) == Records.get_cover(expected.id)
|
||||
end
|
||||
@@ -293,7 +293,7 @@ defmodule MusicLibrary.RecordsTest do
|
||||
|
||||
describe "refresh cover/1" 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())
|
||||
|
||||
|
||||
@@ -6,10 +6,10 @@ defmodule MusicLibrary.WishlistTest do
|
||||
|
||||
defp fill_wishlist(_) do
|
||||
records = [
|
||||
record_fixture(%{purchased_at: nil, title: "Brave"}),
|
||||
record_fixture(%{purchased_at: nil, title: "Brave"}),
|
||||
record_fixture(%{purchased_at: nil}),
|
||||
record_fixture(%{title: "Brave"})
|
||||
record(%{purchased_at: nil, title: "Brave"}),
|
||||
record(%{purchased_at: nil, title: "Brave"}),
|
||||
record(%{purchased_at: nil}),
|
||||
record(%{title: "Brave"})
|
||||
]
|
||||
|
||||
%{wishlist: records}
|
||||
|
||||
@@ -4,7 +4,7 @@ defmodule MusicLibraryWeb.CollectionControllerTest do
|
||||
import MusicLibrary.RecordsFixtures
|
||||
|
||||
defp create_record(_) do
|
||||
%{record: record_fixture_with_artist("Steven Wilson")}
|
||||
%{record: record_with_artist("Steven Wilson")}
|
||||
end
|
||||
|
||||
defp api_token do
|
||||
|
||||
@@ -5,7 +5,7 @@ defmodule MusicLibraryWeb.CoverControllerTest do
|
||||
alias MusicLibrary.Records.Cover
|
||||
|
||||
defp create_record(_) do
|
||||
%{record: record_fixture()}
|
||||
%{record: record()}
|
||||
end
|
||||
|
||||
describe "GET /covers/:record_id" do
|
||||
|
||||
@@ -17,7 +17,7 @@ defmodule MusicLibraryWeb.ArtistLive.ShowTest do
|
||||
|
||||
defp fill_collection(_config) do
|
||||
collection_record =
|
||||
record_fixture_with_artist("Steven Wilson", %{
|
||||
record_with_artist("Steven Wilson", %{
|
||||
title: "The Raven that refused to sing",
|
||||
purchased_at: DateTime.utc_now()
|
||||
})
|
||||
@@ -74,13 +74,13 @@ defmodule MusicLibraryWeb.ArtistLive.ShowTest do
|
||||
artist_musicbrainz_id: artist_musicbrainz_id
|
||||
} do
|
||||
wishlist_record =
|
||||
record_fixture_with_artist("Steven Wilson", %{
|
||||
record_with_artist("Steven Wilson", %{
|
||||
title: "Grace for drowning",
|
||||
purchased_at: nil
|
||||
})
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
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}
|
||||
end
|
||||
|
||||
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}
|
||||
end
|
||||
|
||||
@@ -216,7 +216,7 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
|
||||
|
||||
describe "Updating record metadata" do
|
||||
test "can navigate to the record edit form", %{conn: conn} do
|
||||
record = record_fixture()
|
||||
record = record()
|
||||
|
||||
conn
|
||||
|> visit(~p"/collection")
|
||||
@@ -226,7 +226,7 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
@@ -12,7 +12,7 @@ defmodule MusicLibraryWeb.CollectionLive.ShowTest do
|
||||
|
||||
describe "Edit record from show page" do
|
||||
test "can navigate to the record edit form", %{conn: conn} do
|
||||
record = record_fixture()
|
||||
record = record()
|
||||
|
||||
conn
|
||||
|> visit(~p"/collection/#{record.id}")
|
||||
@@ -24,7 +24,7 @@ defmodule MusicLibraryWeb.CollectionLive.ShowTest do
|
||||
|
||||
describe "Show record" do
|
||||
test "it includes all needed information", %{conn: conn} do
|
||||
record = record_fixture()
|
||||
record = record()
|
||||
|
||||
session =
|
||||
conn
|
||||
|
||||
@@ -11,12 +11,12 @@ defmodule MusicLibraryWeb.StatsLive.IndexTest do
|
||||
setup :verify_on_exit!
|
||||
|
||||
defp fill_collection(_) do
|
||||
records = Enum.map(1..19, fn _ -> record_fixture() end)
|
||||
records = Enum.map(1..19, fn _ -> record() end)
|
||||
%{collection: records}
|
||||
end
|
||||
|
||||
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}
|
||||
end
|
||||
|
||||
@@ -160,12 +160,12 @@ defmodule MusicLibraryWeb.StatsLive.IndexTest do
|
||||
# their status in the scrobble activity changes.
|
||||
|
||||
_machinarium_soundtrack =
|
||||
record_fixture(purchased_at: nil)
|
||||
record(purchased_at: nil)
|
||||
|> Records.change_record(%{release_ids: ["4bad26f6-1b27-4554-93bd-40b91ed7866c"]})
|
||||
|> Repo.update!()
|
||||
|
||||
_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"]})
|
||||
|> Repo.update!()
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ defmodule MusicLibraryWeb.WishlistLive.IndexTest do
|
||||
import MusicLibrary.RecordsFixtures
|
||||
|
||||
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}
|
||||
end
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ defmodule MusicLibrary.RecordsFixtures do
|
||||
def marbles_thumb_fixture, do: @marbles_thumb_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()
|
||||
artist_name = Enum.random(@artists)
|
||||
current_time = DateTime.utc_now()
|
||||
@@ -75,10 +75,10 @@ defmodule MusicLibrary.RecordsFixtures do
|
||||
record
|
||||
end
|
||||
|
||||
def record_fixture_with_artist(artist_name, record_attrs \\ %{}) do
|
||||
def record_with_artist(artist_name, record_attrs \\ %{}) do
|
||||
record_attrs
|
||||
|> Map.put(:artists, [artist_attrs(artist_name)])
|
||||
|> record_fixture()
|
||||
|> record()
|
||||
end
|
||||
|
||||
defp artist_attrs(name) do
|
||||
|
||||
Reference in New Issue
Block a user