Extract artist infos fixtures
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
defmodule MusicLibrary.ListeningStatsTest do
|
defmodule MusicLibrary.ListeningStatsTest do
|
||||||
use MusicLibrary.DataCase
|
use MusicLibrary.DataCase
|
||||||
|
|
||||||
|
import MusicLibrary.ArtistInfoFixtures
|
||||||
import MusicLibrary.ScrobbledTracksFixtures
|
import MusicLibrary.ScrobbledTracksFixtures
|
||||||
|
|
||||||
alias MusicLibrary.ListeningStats
|
alias MusicLibrary.ListeningStats
|
||||||
@@ -19,13 +20,10 @@ defmodule MusicLibrary.ListeningStatsTest do
|
|||||||
|
|
||||||
describe "get_top_artists/1" do
|
describe "get_top_artists/1" do
|
||||||
test "counts tracks with missing artist_infos records" do
|
test "counts tracks with missing artist_infos records" do
|
||||||
artist_mbid = Ecto.UUID.generate()
|
artist_info =
|
||||||
|
artist_info_fixture(%{musicbrainz_data: %{"name" => "Thin Lizzy"}})
|
||||||
|
|
||||||
# Create an artist_info record for the known musicbrainz_id
|
artist_mbid = artist_info.id
|
||||||
MusicLibrary.Repo.insert!(%MusicLibrary.Artists.ArtistInfo{
|
|
||||||
id: artist_mbid,
|
|
||||||
musicbrainz_data: %{"name" => "Thin Lizzy"}
|
|
||||||
})
|
|
||||||
|
|
||||||
now = System.system_time(:second)
|
now = System.system_time(:second)
|
||||||
|
|
||||||
@@ -62,13 +60,13 @@ defmodule MusicLibrary.ListeningStatsTest do
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "returns image_hash from artist_infos when available" do
|
test "returns image_hash from artist_infos when available" do
|
||||||
artist_mbid = Ecto.UUID.generate()
|
artist_info =
|
||||||
|
artist_info_fixture(%{
|
||||||
|
musicbrainz_data: %{"name" => "Test Artist"},
|
||||||
|
image_data_hash: "abc123"
|
||||||
|
})
|
||||||
|
|
||||||
MusicLibrary.Repo.insert!(%MusicLibrary.Artists.ArtistInfo{
|
artist_mbid = artist_info.id
|
||||||
id: artist_mbid,
|
|
||||||
musicbrainz_data: %{"name" => "Test Artist"},
|
|
||||||
image_data_hash: "abc123"
|
|
||||||
})
|
|
||||||
|
|
||||||
track_fixture(%{
|
track_fixture(%{
|
||||||
artist_name: "Test Artist",
|
artist_name: "Test Artist",
|
||||||
@@ -98,12 +96,10 @@ defmodule MusicLibrary.ListeningStatsTest do
|
|||||||
|
|
||||||
describe "get_top_artists_by_days/2" do
|
describe "get_top_artists_by_days/2" do
|
||||||
test "counts tracks with missing artist_infos records within date range" do
|
test "counts tracks with missing artist_infos records within date range" do
|
||||||
artist_mbid = Ecto.UUID.generate()
|
artist_info =
|
||||||
|
artist_info_fixture(%{musicbrainz_data: %{"name" => "Thin Lizzy"}})
|
||||||
|
|
||||||
MusicLibrary.Repo.insert!(%MusicLibrary.Artists.ArtistInfo{
|
artist_mbid = artist_info.id
|
||||||
id: artist_mbid,
|
|
||||||
musicbrainz_data: %{"name" => "Thin Lizzy"}
|
|
||||||
})
|
|
||||||
|
|
||||||
now = DateTime.utc_now()
|
now = DateTime.utc_now()
|
||||||
now_unix = DateTime.to_unix(now)
|
now_unix = DateTime.to_unix(now)
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
defmodule MusicLibrary.Records.SimilarityTest do
|
defmodule MusicLibrary.Records.SimilarityTest do
|
||||||
use MusicLibrary.DataCase
|
use MusicLibrary.DataCase
|
||||||
|
|
||||||
|
import MusicLibrary.ArtistInfoFixtures
|
||||||
import MusicLibrary.Fixtures.Records
|
import MusicLibrary.Fixtures.Records
|
||||||
|
|
||||||
alias MusicLibrary.Artists.ArtistInfo
|
|
||||||
alias MusicLibrary.Records.{Record, Similarity}
|
alias MusicLibrary.Records.{Record, Similarity}
|
||||||
alias MusicLibrary.Repo
|
|
||||||
|
|
||||||
describe "text_representation/1" do
|
describe "text_representation/1" do
|
||||||
test "generates text representation for a record" do
|
test "generates text representation for a record" do
|
||||||
@@ -35,17 +34,15 @@ defmodule MusicLibrary.Records.SimilarityTest do
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "includes Wikipedia data when available" do
|
test "includes Wikipedia data when available" do
|
||||||
artist_id = Ecto.UUID.generate()
|
artist_info =
|
||||||
|
artist_info_fixture(%{
|
||||||
Repo.insert!(%ArtistInfo{
|
musicbrainz_data: %{"name" => "Radiohead"},
|
||||||
id: artist_id,
|
wikipedia_data: %{
|
||||||
musicbrainz_data: %{"name" => "Radiohead"},
|
"description" => "English rock band",
|
||||||
wikipedia_data: %{
|
"extract" =>
|
||||||
"description" => "English rock band",
|
"Radiohead are an English rock band formed in Abingdon. They are known for experimental music."
|
||||||
"extract" =>
|
}
|
||||||
"Radiohead are an English rock band formed in Abingdon. They are known for experimental music."
|
})
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
record = %Record{
|
record = %Record{
|
||||||
title: "OK Computer",
|
title: "OK Computer",
|
||||||
@@ -53,7 +50,7 @@ defmodule MusicLibrary.Records.SimilarityTest do
|
|||||||
%{
|
%{
|
||||||
name: "Radiohead",
|
name: "Radiohead",
|
||||||
sort_name: "Radiohead",
|
sort_name: "Radiohead",
|
||||||
musicbrainz_id: artist_id,
|
musicbrainz_id: artist_info.id,
|
||||||
disambiguation: "",
|
disambiguation: "",
|
||||||
joinphrase: ""
|
joinphrase: ""
|
||||||
}
|
}
|
||||||
@@ -71,17 +68,15 @@ defmodule MusicLibrary.Records.SimilarityTest do
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "falls back to truncated Discogs profile when Wikipedia unavailable" do
|
test "falls back to truncated Discogs profile when Wikipedia unavailable" do
|
||||||
artist_id = Ecto.UUID.generate()
|
artist_info =
|
||||||
|
artist_info_fixture(%{
|
||||||
Repo.insert!(%ArtistInfo{
|
musicbrainz_data: %{"name" => "Some Artist"},
|
||||||
id: artist_id,
|
discogs_data: %{
|
||||||
musicbrainz_data: %{"name" => "Some Artist"},
|
"name" => "Some Artist",
|
||||||
discogs_data: %{
|
"profile_plaintext" => "Some Artist is a funk band. They have released many albums.",
|
||||||
"name" => "Some Artist",
|
"members" => [%{"name" => "Member One"}, %{"name" => "Member Two"}]
|
||||||
"profile_plaintext" => "Some Artist is a funk band. They have released many albums.",
|
}
|
||||||
"members" => [%{"name" => "Member One"}, %{"name" => "Member Two"}]
|
})
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
record = %Record{
|
record = %Record{
|
||||||
title: "Funky Album",
|
title: "Funky Album",
|
||||||
@@ -89,7 +84,7 @@ defmodule MusicLibrary.Records.SimilarityTest do
|
|||||||
%{
|
%{
|
||||||
name: "Some Artist",
|
name: "Some Artist",
|
||||||
sort_name: "Some Artist",
|
sort_name: "Some Artist",
|
||||||
musicbrainz_id: artist_id,
|
musicbrainz_id: artist_info.id,
|
||||||
disambiguation: "",
|
disambiguation: "",
|
||||||
joinphrase: ""
|
joinphrase: ""
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
defmodule MusicLibrary.Worker.ApplyScrobbleRulesTest do
|
defmodule MusicLibrary.Worker.ApplyScrobbleRulesTest do
|
||||||
use MusicLibrary.DataCase
|
use MusicLibrary.DataCase
|
||||||
|
|
||||||
|
import MusicLibrary.ScrobbledTracksFixtures
|
||||||
|
|
||||||
alias LastFm.Track
|
alias LastFm.Track
|
||||||
alias MusicLibrary.ScrobbleRules
|
alias MusicLibrary.ScrobbleRules
|
||||||
alias MusicLibrary.Worker.ApplyScrobbleRules
|
alias MusicLibrary.Worker.ApplyScrobbleRules
|
||||||
@@ -34,31 +36,21 @@ defmodule MusicLibrary.Worker.ApplyScrobbleRulesTest do
|
|||||||
})
|
})
|
||||||
|
|
||||||
# Create test tracks
|
# Create test tracks
|
||||||
%Track{}
|
scrobbled_track_fixture(%{
|
||||||
|> Track.changeset(%{
|
|
||||||
scrobbled_at_uts: System.system_time(:second),
|
|
||||||
musicbrainz_id: "track-mbid-1",
|
musicbrainz_id: "track-mbid-1",
|
||||||
title: "Breathe",
|
title: "Breathe",
|
||||||
cover_url: "http://example.com/cover.jpg",
|
|
||||||
scrobbled_at_label: "01 Jan 2023, 12:00",
|
|
||||||
artist: %{musicbrainz_id: "", name: "Pink Floyd"},
|
artist: %{musicbrainz_id: "", name: "Pink Floyd"},
|
||||||
album: %{musicbrainz_id: "", title: "Dark Side of the Moon"},
|
album: %{musicbrainz_id: "", title: "Dark Side of the Moon"}
|
||||||
last_fm_data: %{}
|
|
||||||
})
|
})
|
||||||
|> Repo.insert!()
|
|
||||||
|
|
||||||
%Track{}
|
scrobbled_track_fixture(%{
|
||||||
|> Track.changeset(%{
|
|
||||||
scrobbled_at_uts: System.system_time(:second) + 1,
|
scrobbled_at_uts: System.system_time(:second) + 1,
|
||||||
musicbrainz_id: "track-mbid-2",
|
musicbrainz_id: "track-mbid-2",
|
||||||
title: "Money",
|
title: "Money",
|
||||||
cover_url: "http://example.com/cover.jpg",
|
|
||||||
scrobbled_at_label: "01 Jan 2023, 12:05",
|
scrobbled_at_label: "01 Jan 2023, 12:05",
|
||||||
artist: %{musicbrainz_id: "", name: "Pink Floyd"},
|
artist: %{musicbrainz_id: "", name: "Pink Floyd"},
|
||||||
album: %{musicbrainz_id: "", title: "Wish You Were Here"},
|
album: %{musicbrainz_id: "", title: "Wish You Were Here"}
|
||||||
last_fm_data: %{}
|
|
||||||
})
|
})
|
||||||
|> Repo.insert!()
|
|
||||||
|
|
||||||
# Execute the worker
|
# Execute the worker
|
||||||
assert :ok = ApplyScrobbleRules.perform(%Oban.Job{args: %{}})
|
assert :ok = ApplyScrobbleRules.perform(%Oban.Job{args: %{}})
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
defmodule MusicLibrary.Worker.ArtistRefreshDiscogsDataTest do
|
defmodule MusicLibrary.Worker.ArtistRefreshDiscogsDataTest do
|
||||||
use MusicLibrary.DataCase
|
use MusicLibrary.DataCase
|
||||||
|
|
||||||
|
import MusicLibrary.ArtistInfoFixtures
|
||||||
import MusicLibrary.Fixtures.Records
|
import MusicLibrary.Fixtures.Records
|
||||||
|
|
||||||
alias Discogs.Fixtures.Artist, as: ArtistFixture
|
alias Discogs.Fixtures.Artist, as: ArtistFixture
|
||||||
@@ -27,14 +28,10 @@ defmodule MusicLibrary.Worker.ArtistRefreshDiscogsDataTest do
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "returns ok when no discogs data is available" do
|
test "returns ok when no discogs data is available" do
|
||||||
artist_id = Ecto.UUID.generate()
|
artist_info =
|
||||||
|
artist_info_fixture(%{musicbrainz_data: %{"name" => "No Discogs Artist"}})
|
||||||
|
|
||||||
Repo.insert!(%Artists.ArtistInfo{
|
assert {:ok, _} = perform_job(ArtistRefreshDiscogsData, %{"id" => artist_info.id})
|
||||||
id: artist_id,
|
|
||||||
musicbrainz_data: %{"name" => "No Discogs Artist"}
|
|
||||||
})
|
|
||||||
|
|
||||||
assert {:ok, _} = perform_job(ArtistRefreshDiscogsData, %{"id" => artist_id})
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,20 +1,18 @@
|
|||||||
defmodule MusicLibrary.Worker.ArtistRefreshMusicBrainzDataTest do
|
defmodule MusicLibrary.Worker.ArtistRefreshMusicBrainzDataTest do
|
||||||
use MusicLibrary.DataCase
|
use MusicLibrary.DataCase
|
||||||
|
|
||||||
|
import MusicLibrary.ArtistInfoFixtures
|
||||||
|
|
||||||
alias MusicBrainz.Fixtures.Artist, as: ArtistFixture
|
alias MusicBrainz.Fixtures.Artist, as: ArtistFixture
|
||||||
alias MusicLibrary.Artists
|
alias MusicLibrary.Artists
|
||||||
alias MusicLibrary.Artists.ArtistInfo
|
alias MusicLibrary.Artists.ArtistInfo
|
||||||
alias MusicLibrary.Worker.ArtistRefreshMusicBrainzData
|
alias MusicLibrary.Worker.ArtistRefreshMusicBrainzData
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
artist_id = Ecto.UUID.generate()
|
artist_info =
|
||||||
|
artist_info_fixture(%{musicbrainz_data: %{"name" => "Steven Wilson"}})
|
||||||
|
|
||||||
Repo.insert!(%ArtistInfo{
|
%{artist_id: artist_info.id}
|
||||||
id: artist_id,
|
|
||||||
musicbrainz_data: %{"name" => "Steven Wilson"}
|
|
||||||
})
|
|
||||||
|
|
||||||
%{artist_id: artist_id}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "perform/1" do
|
describe "perform/1" do
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
defmodule MusicLibrary.Worker.ArtistRefreshWikipediaDataTest do
|
defmodule MusicLibrary.Worker.ArtistRefreshWikipediaDataTest do
|
||||||
use MusicLibrary.DataCase
|
use MusicLibrary.DataCase
|
||||||
|
|
||||||
|
import MusicLibrary.ArtistInfoFixtures
|
||||||
import MusicLibrary.Fixtures.Records
|
import MusicLibrary.Fixtures.Records
|
||||||
|
|
||||||
alias MusicLibrary.Artists
|
alias MusicLibrary.Artists
|
||||||
@@ -38,16 +39,12 @@ defmodule MusicLibrary.Worker.ArtistRefreshWikipediaDataTest do
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "discards job when no wikidata_id exists in musicbrainz_data" do
|
test "discards job when no wikidata_id exists in musicbrainz_data" do
|
||||||
artist_id = Ecto.UUID.generate()
|
artist_info =
|
||||||
|
artist_info_fixture(%{musicbrainz_data: %{"name" => "No Wikipedia Artist"}})
|
||||||
Repo.insert!(%Artists.ArtistInfo{
|
|
||||||
id: artist_id,
|
|
||||||
musicbrainz_data: %{"name" => "No Wikipedia Artist"}
|
|
||||||
})
|
|
||||||
|
|
||||||
# No wikidata relation in musicbrainz_data → fetch_wikipedia_data returns {:ok, artist_info}
|
# No wikidata relation in musicbrainz_data → fetch_wikipedia_data returns {:ok, artist_info}
|
||||||
# Worker wraps non-error returns with `with`, so it passes through as :ok
|
# Worker wraps non-error returns with `with`, so it passes through as :ok
|
||||||
assert {:ok, _} = perform_job(ArtistRefreshWikipediaData, %{"id" => artist_id})
|
assert {:ok, _} = perform_job(ArtistRefreshWikipediaData, %{"id" => artist_info.id})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
defmodule MusicLibrary.Worker.FetchArtistImageTest do
|
defmodule MusicLibrary.Worker.FetchArtistImageTest do
|
||||||
use MusicLibrary.DataCase
|
use MusicLibrary.DataCase
|
||||||
|
|
||||||
|
import MusicLibrary.ArtistInfoFixtures
|
||||||
import MusicLibrary.Fixtures.Records
|
import MusicLibrary.Fixtures.Records
|
||||||
|
|
||||||
alias Discogs.Fixtures.Artist
|
alias Discogs.Fixtures.Artist
|
||||||
@@ -27,29 +28,25 @@ defmodule MusicLibrary.Worker.FetchArtistImageTest do
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "cancels when no discogs data exists" do
|
test "cancels when no discogs data exists" do
|
||||||
artist_id = Ecto.UUID.generate()
|
artist_info =
|
||||||
|
artist_info_fixture(%{
|
||||||
Repo.insert!(%Artists.ArtistInfo{
|
musicbrainz_data: %{"name" => "No Image Artist"},
|
||||||
id: artist_id,
|
discogs_data: nil
|
||||||
musicbrainz_data: %{"name" => "No Image Artist"},
|
})
|
||||||
discogs_data: nil
|
|
||||||
})
|
|
||||||
|
|
||||||
assert {:cancel, :no_discogs_data} =
|
assert {:cancel, :no_discogs_data} =
|
||||||
perform_job(FetchArtistImage, %{"id" => artist_id})
|
perform_job(FetchArtistImage, %{"id" => artist_info.id})
|
||||||
end
|
end
|
||||||
|
|
||||||
test "cancels when discogs data has no images" do
|
test "cancels when discogs data has no images" do
|
||||||
artist_id = Ecto.UUID.generate()
|
artist_info =
|
||||||
|
artist_info_fixture(%{
|
||||||
Repo.insert!(%Artists.ArtistInfo{
|
musicbrainz_data: %{"name" => "No Image Artist"},
|
||||||
id: artist_id,
|
discogs_data: %{"id" => 12_345, "images" => []}
|
||||||
musicbrainz_data: %{"name" => "No Image Artist"},
|
})
|
||||||
discogs_data: %{"id" => 12_345, "images" => []}
|
|
||||||
})
|
|
||||||
|
|
||||||
assert {:cancel, :image_not_found} =
|
assert {:cancel, :image_not_found} =
|
||||||
perform_job(FetchArtistImage, %{"id" => artist_id})
|
perform_job(FetchArtistImage, %{"id" => artist_info.id})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,20 +1,17 @@
|
|||||||
defmodule MusicLibrary.Worker.FetchArtistLastFmDataTest do
|
defmodule MusicLibrary.Worker.FetchArtistLastFmDataTest do
|
||||||
use MusicLibrary.DataCase
|
use MusicLibrary.DataCase
|
||||||
|
|
||||||
|
import MusicLibrary.ArtistInfoFixtures
|
||||||
|
|
||||||
alias MusicLibrary.Artists
|
alias MusicLibrary.Artists
|
||||||
alias MusicLibrary.Artists.ArtistInfo
|
alias MusicLibrary.Artists.ArtistInfo
|
||||||
alias MusicLibrary.Repo
|
|
||||||
alias MusicLibrary.Worker.FetchArtistLastFmData
|
alias MusicLibrary.Worker.FetchArtistLastFmData
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
artist_id = Ecto.UUID.generate()
|
artist_info =
|
||||||
|
artist_info_fixture(%{musicbrainz_data: %{"name" => "Steven Wilson"}})
|
||||||
|
|
||||||
Repo.insert!(%ArtistInfo{
|
%{artist_id: artist_info.id}
|
||||||
id: artist_id,
|
|
||||||
musicbrainz_data: %{"name" => "Steven Wilson"}
|
|
||||||
})
|
|
||||||
|
|
||||||
%{artist_id: artist_id}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "perform/1" do
|
describe "perform/1" do
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
defmodule MusicLibrary.Worker.PruneArtistInfoTest do
|
defmodule MusicLibrary.Worker.PruneArtistInfoTest do
|
||||||
use MusicLibrary.DataCase
|
use MusicLibrary.DataCase
|
||||||
|
|
||||||
|
import MusicLibrary.ArtistInfoFixtures
|
||||||
import MusicLibrary.Fixtures.Records
|
import MusicLibrary.Fixtures.Records
|
||||||
|
|
||||||
alias MusicLibrary.Artists
|
alias MusicLibrary.Artists
|
||||||
@@ -18,17 +19,13 @@ defmodule MusicLibrary.Worker.PruneArtistInfoTest do
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "deletes artist info when artist is not referenced by any record" do
|
test "deletes artist info when artist is not referenced by any record" do
|
||||||
artist_id = Ecto.UUID.generate()
|
artist_info =
|
||||||
|
artist_info_fixture(%{musicbrainz_data: %{"name" => "Orphaned Artist"}})
|
||||||
|
|
||||||
Repo.insert!(%Artists.ArtistInfo{
|
assert :ok = perform_job(PruneArtistInfo, %{"id" => artist_info.id})
|
||||||
id: artist_id,
|
|
||||||
musicbrainz_data: %{"name" => "Orphaned Artist"}
|
|
||||||
})
|
|
||||||
|
|
||||||
assert :ok = perform_job(PruneArtistInfo, %{"id" => artist_id})
|
|
||||||
|
|
||||||
assert_raise Ecto.NoResultsError, fn ->
|
assert_raise Ecto.NoResultsError, fn ->
|
||||||
Artists.get_artist_info!(artist_id)
|
Artists.get_artist_info!(artist_info.id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
defmodule MusicLibrary.ArtistInfoFixtures do
|
||||||
|
@moduledoc """
|
||||||
|
This module defines test helpers for creating
|
||||||
|
entities via the `MusicLibrary.Artists.ArtistInfo` schema.
|
||||||
|
"""
|
||||||
|
|
||||||
|
alias MusicLibrary.Artists.ArtistInfo
|
||||||
|
alias MusicLibrary.Repo
|
||||||
|
|
||||||
|
def artist_info_fixture(attrs \\ %{}) do
|
||||||
|
attrs =
|
||||||
|
Map.merge(
|
||||||
|
%{
|
||||||
|
id: Ecto.UUID.generate(),
|
||||||
|
musicbrainz_data: %{"name" => "Test Artist"}
|
||||||
|
},
|
||||||
|
attrs
|
||||||
|
)
|
||||||
|
|
||||||
|
Repo.insert!(struct!(ArtistInfo, attrs))
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user