Extract fixture

This commit is contained in:
Claudio Ortolina
2026-03-06 08:53:25 +00:00
parent 7cf9b4e7f8
commit 3819afca4d
2 changed files with 29 additions and 25 deletions
+1 -25
View File
@@ -2,6 +2,7 @@ defmodule MusicLibrary.ScrobbleRulesTest do
use MusicLibrary.DataCase
import MusicLibrary.ScrobbleRulesFixtures
import MusicLibrary.ScrobbledTracksFixtures
alias LastFm.Track
alias MusicLibrary.ScrobbleRules
@@ -26,31 +27,6 @@ defmodule MusicLibrary.ScrobbleRulesTest do
@invalid_attrs %{type: nil, match_value: nil, target_musicbrainz_id: nil}
def scrobbled_track_fixture(attrs \\ %{}) do
default_attrs = %{
scrobbled_at_uts: System.system_time(:second),
musicbrainz_id: "track-mbid-12345",
title: "Breathe",
cover_url: "http://example.com/cover.jpg",
scrobbled_at_label: "01 Jan 2023, 12:00",
artist: %{
musicbrainz_id: "",
name: "Pink Floyd"
},
album: %{
musicbrainz_id: "",
title: "Dark Side of the Moon"
},
last_fm_data: %{}
}
attrs = Enum.into(attrs, default_attrs)
%Track{}
|> Track.changeset(attrs)
|> Repo.insert!()
end
test "list_scrobble_rules/0 returns all scrobble_rules" do
scrobble_rule = scrobble_rule_fixture()
assert ScrobbleRules.list_scrobble_rules() == [scrobble_rule]
@@ -41,6 +41,34 @@ defmodule MusicLibrary.ScrobbledTracksFixtures do
track
end
@doc """
Generate a scrobbled track with nested artist/album maps.
"""
def scrobbled_track_fixture(attrs \\ %{}) do
default_attrs = %{
scrobbled_at_uts: System.system_time(:second),
musicbrainz_id: "track-mbid-12345",
title: "Breathe",
cover_url: "http://example.com/cover.jpg",
scrobbled_at_label: "01 Jan 2023, 12:00",
artist: %{
musicbrainz_id: "",
name: "Pink Floyd"
},
album: %{
musicbrainz_id: "",
title: "Dark Side of the Moon"
},
last_fm_data: %{}
}
attrs = Enum.into(attrs, default_attrs)
%Track{}
|> Track.changeset(attrs)
|> Repo.insert!()
end
@doc """
Generate multiple scrobbled tracks for testing pagination and search.
"""