From ed6ef2c7efd9105c6ac8646ccd2c386402a8f099 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Mon, 6 Jan 2025 14:20:36 +0000 Subject: [PATCH] Rename record_fixture* to record* --- test/music_library/artists_test.exs | 2 +- test/music_library/collection_test.exs | 10 ++++----- test/music_library/records_test.exs | 22 +++++++++---------- test/music_library/wishlist_test.exs | 8 +++---- .../collection_controller_test.exs | 2 +- .../controllers/cover_controller_test.exs | 2 +- .../live/artist_live/show_test.exs | 6 ++--- .../live/collection_live/index_test.exs | 8 +++---- .../live/collection_live/show_test.exs | 4 ++-- .../live/stats_live/index_test.exs | 8 +++---- .../live/wishlist_live/index_test.exs | 2 +- test/support/fixtures/records_fixtures.ex | 6 ++--- 12 files changed, 40 insertions(+), 40 deletions(-) diff --git a/test/music_library/artists_test.exs b/test/music_library/artists_test.exs index 6faffd4c..66399eca 100644 --- a/test/music_library/artists_test.exs +++ b/test/music_library/artists_test.exs @@ -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) diff --git a/test/music_library/collection_test.exs b/test/music_library/collection_test.exs index 17fdd800..d4e3f745 100644 --- a/test/music_library/collection_test.exs +++ b/test/music_library/collection_test.exs @@ -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 diff --git a/test/music_library/records_test.exs b/test/music_library/records_test.exs index 42a339fb..ed6b817a 100644 --- a/test/music_library/records_test.exs +++ b/test/music_library/records_test.exs @@ -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()) diff --git a/test/music_library/wishlist_test.exs b/test/music_library/wishlist_test.exs index acdafd3d..7f8d528b 100644 --- a/test/music_library/wishlist_test.exs +++ b/test/music_library/wishlist_test.exs @@ -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} diff --git a/test/music_library_web/controllers/collection_controller_test.exs b/test/music_library_web/controllers/collection_controller_test.exs index 0ce46306..5c882480 100644 --- a/test/music_library_web/controllers/collection_controller_test.exs +++ b/test/music_library_web/controllers/collection_controller_test.exs @@ -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 diff --git a/test/music_library_web/controllers/cover_controller_test.exs b/test/music_library_web/controllers/cover_controller_test.exs index 16e99de4..1d9dcd33 100644 --- a/test/music_library_web/controllers/cover_controller_test.exs +++ b/test/music_library_web/controllers/cover_controller_test.exs @@ -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 diff --git a/test/music_library_web/live/artist_live/show_test.exs b/test/music_library_web/live/artist_live/show_test.exs index 973498ad..fea83bdf 100644 --- a/test/music_library_web/live/artist_live/show_test.exs +++ b/test/music_library_web/live/artist_live/show_test.exs @@ -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}, diff --git a/test/music_library_web/live/collection_live/index_test.exs b/test/music_library_web/live/collection_live/index_test.exs index e08044f9..17d9ee79 100644 --- a/test/music_library_web/live/collection_live/index_test.exs +++ b/test/music_library_web/live/collection_live/index_test.exs @@ -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 diff --git a/test/music_library_web/live/collection_live/show_test.exs b/test/music_library_web/live/collection_live/show_test.exs index 22bed68d..7b46ae54 100644 --- a/test/music_library_web/live/collection_live/show_test.exs +++ b/test/music_library_web/live/collection_live/show_test.exs @@ -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 diff --git a/test/music_library_web/live/stats_live/index_test.exs b/test/music_library_web/live/stats_live/index_test.exs index f7df62b1..e0d77e74 100644 --- a/test/music_library_web/live/stats_live/index_test.exs +++ b/test/music_library_web/live/stats_live/index_test.exs @@ -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!() diff --git a/test/music_library_web/live/wishlist_live/index_test.exs b/test/music_library_web/live/wishlist_live/index_test.exs index 2ed91289..2c3fdced 100644 --- a/test/music_library_web/live/wishlist_live/index_test.exs +++ b/test/music_library_web/live/wishlist_live/index_test.exs @@ -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 diff --git a/test/support/fixtures/records_fixtures.ex b/test/support/fixtures/records_fixtures.ex index 48959edd..594a25c0 100644 --- a/test/support/fixtures/records_fixtures.ex +++ b/test/support/fixtures/records_fixtures.ex @@ -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