ML-193: add secondary parser, search, and API coverage tests
Add ~80 focused tests across 10 files covering:
- Record set search by name, description, contained record title, artist name
- Navigation events for records, artists, record sets, links, and view-all actions
- MusicBrainz.ReleaseGroup parser (artist credits, included RGs, release IDs, types)
- MusicBrainz.ReleaseSearchResult edge cases (missing RG, unknown formats)
- LastFm.Session XML edge cases (non-subscriber, missing nodes)
- MusicLibrary.HttpError default status-kind mapping
- Discogs.API.ErrorResponse fallback message and retry-delay behavior
- ArtistRefreshWikipediaData {:cancel, :no_english_wikipedia} worker path
- StatsComponents grouped on-this-day records and anniversary labels
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
defmodule MusicLibrary.HttpErrorTest do
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
alias MusicLibrary.HttpError
|
||||
|
||||
describe "default_kind/1" do
|
||||
test "maps 429 to :rate_limit" do
|
||||
assert HttpError.default_kind(429) == :rate_limit
|
||||
end
|
||||
|
||||
test "maps 5xx to :server_error" do
|
||||
for status <- [500, 502, 503, 504, 599] do
|
||||
assert HttpError.default_kind(status) == :server_error,
|
||||
"expected #{status} to be :server_error"
|
||||
end
|
||||
end
|
||||
|
||||
test "maps 401 and 403 to :auth_error" do
|
||||
assert HttpError.default_kind(401) == :auth_error
|
||||
assert HttpError.default_kind(403) == :auth_error
|
||||
end
|
||||
|
||||
test "maps 404 to :not_found" do
|
||||
assert HttpError.default_kind(404) == :not_found
|
||||
end
|
||||
|
||||
test "maps other 4xx to :client_error" do
|
||||
for status <- [400, 402, 405, 422, 499] do
|
||||
assert HttpError.default_kind(status) == :client_error,
|
||||
"expected #{status} to be :client_error"
|
||||
end
|
||||
end
|
||||
|
||||
test "maps unexpected statuses to :unknown" do
|
||||
for status <- [200, 302, 600, 999] do
|
||||
assert HttpError.default_kind(status) == :unknown,
|
||||
"expected #{status} to be :unknown"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -2,6 +2,7 @@ defmodule MusicLibrary.SearchTest do
|
||||
use MusicLibrary.DataCase
|
||||
|
||||
import MusicLibrary.Fixtures.Records
|
||||
import MusicLibrary.Fixtures.RecordSets
|
||||
|
||||
alias MusicLibrary.Search
|
||||
|
||||
@@ -38,6 +39,49 @@ defmodule MusicLibrary.SearchTest do
|
||||
assert "Marillion" in artist_names
|
||||
end
|
||||
|
||||
test "returns record sets matching by name" do
|
||||
record_set(%{name: "My Jazz Collection"})
|
||||
record_set(%{name: "Rock Favorites"})
|
||||
|
||||
results = Search.universal_search("Jazz")
|
||||
assert results.record_sets != []
|
||||
names = Enum.map(results.record_sets, & &1.name)
|
||||
assert Enum.any?(names, &String.contains?(&1, "Jazz"))
|
||||
end
|
||||
|
||||
test "returns record sets matching by description" do
|
||||
record_set(%{name: "Favorites", description: "All the prog rock classics"})
|
||||
record_set(%{name: "Other", description: "Some other set"})
|
||||
|
||||
results = Search.universal_search("prog rock")
|
||||
assert results.record_sets != []
|
||||
names = Enum.map(results.record_sets, & &1.name)
|
||||
assert Enum.any?(names, &(&1 == "Favorites"))
|
||||
end
|
||||
|
||||
test "returns record sets matching by contained record title" do
|
||||
{set, _records} = record_set_with_records(1, %{name: "Prog", description: "Prog"})
|
||||
contained_title = set.items |> List.first() |> Map.get(:record) |> Map.get(:title)
|
||||
|
||||
results = Search.universal_search(contained_title)
|
||||
assert results.record_sets != []
|
||||
end
|
||||
|
||||
test "returns record sets matching by contained artist name" do
|
||||
# Create a record set with a record that has a unique artist
|
||||
{_, [record]} = record_set_with_records(1, %{name: "Artist Set", description: "Testing"})
|
||||
artist = hd(record.artists)
|
||||
|
||||
results = Search.universal_search(artist.name)
|
||||
record_set_ids = Enum.map(results.record_sets, & &1.id)
|
||||
assert record_set_ids != []
|
||||
end
|
||||
|
||||
test "returns empty record sets for no match" do
|
||||
results = Search.universal_search("zzz_nonexistent_record_set_zzz")
|
||||
assert results.record_sets == []
|
||||
end
|
||||
|
||||
test "returns empty results for no matches" do
|
||||
results = Search.universal_search("zzz_nonexistent_zzz")
|
||||
|
||||
@@ -52,18 +96,22 @@ defmodule MusicLibrary.SearchTest do
|
||||
assert length(results.collection) <= 1
|
||||
assert length(results.wishlist) <= 1
|
||||
assert length(results.artists) <= 1
|
||||
assert length(results.record_sets) <= 1
|
||||
end
|
||||
end
|
||||
|
||||
describe "search_counts/1" do
|
||||
setup [:create_records]
|
||||
|
||||
test "returns counts per category" do
|
||||
test "returns counts per category including record sets" do
|
||||
{_set, _records} = record_set_with_records(1, %{name: "Marillion Favorites"})
|
||||
|
||||
counts = Search.search_counts("Marillion")
|
||||
|
||||
assert counts.collection_count >= 1
|
||||
assert counts.wishlist_count >= 1
|
||||
assert counts.artists_count >= 1
|
||||
assert counts.record_sets_count >= 1
|
||||
end
|
||||
|
||||
test "returns zero counts for no matches" do
|
||||
@@ -72,6 +120,22 @@ defmodule MusicLibrary.SearchTest do
|
||||
assert counts.collection_count == 0
|
||||
assert counts.wishlist_count == 0
|
||||
assert counts.artists_count == 0
|
||||
assert counts.record_sets_count == 0
|
||||
end
|
||||
end
|
||||
|
||||
describe "search_record_sets/2" do
|
||||
test "returns record sets matching by name" do
|
||||
record_set(%{name: "Best of 2020", description: "Top albums of 2020"})
|
||||
|
||||
results = Search.search_record_sets("2020")
|
||||
names = Enum.map(results, & &1.name)
|
||||
assert "Best of 2020" in names
|
||||
end
|
||||
|
||||
test "returns empty for non-matching query" do
|
||||
results = Search.search_record_sets("zzz_nonexistent_zzz")
|
||||
assert results == []
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -39,6 +39,15 @@ defmodule MusicLibrary.Worker.ArtistRefreshWikipediaDataTest do
|
||||
assert Map.has_key?(updated.wikipedia_data, "intro_html")
|
||||
end
|
||||
|
||||
test "cancels when no English Wikipedia article exists", %{artist_info: artist_info} do
|
||||
Req.Test.stub(Wikipedia.API, fn conn ->
|
||||
Req.Test.json(conn, Wikipedia.Fixtures.wikidata_response_no_enwiki())
|
||||
end)
|
||||
|
||||
assert {:cancel, :no_english_wikipedia} =
|
||||
perform_job(ArtistRefreshWikipediaData, %{"id" => artist_info.id})
|
||||
end
|
||||
|
||||
test "discards job when no wikidata_id exists in musicbrainz_data" do
|
||||
artist_info =
|
||||
artist_info_fixture(%{musicbrainz_data: %{"name" => "No Wikipedia Artist"}})
|
||||
|
||||
Reference in New Issue
Block a user