feat: handle ErrArtistNotFound in ScanArtist gracefully by using empty TypeFilter

This commit is contained in:
2026-07-26 11:36:32 +03:00
parent 4b4e852fd1
commit 395a7f9b07
2 changed files with 43 additions and 3 deletions

View File

@@ -247,6 +247,46 @@ func seedArtistUnmonitored(t *testing.T, db *database.DB, id, name string) {
}
}
// TestScanArtist_ErrArtistNotFound verifies that ScanArtist handles ErrArtistNotFound
// by using empty TypeFilter (no filtering) instead of returning an error.
func TestScanArtist_ErrArtistNotFound(t *testing.T) {
db := newTestDB(t)
defer db.Close()
// Disable foreign key constraints to allow inserting external_releases without artist_settings
if _, err := db.Conn().Exec("PRAGMA foreign_keys = OFF"); err != nil {
t.Fatalf("disable foreign keys: %v", err)
}
// Re-enable foreign keys when we're done
defer func() {
if _, err := db.Conn().Exec("PRAGMA foreign_keys = ON"); err != nil {
t.Fatalf("re-enable foreign keys: %v", err)
}
}()
// Don't create artist settings - this will cause GetArtistSettings to return ErrArtistNotFound
// Insert external release directly to bypass FK constraint for testing inconsistent state
if _, err := db.Conn().Exec(
"INSERT INTO external_releases (rgid, artist_id, title, type, release_date, is_ignored) VALUES (?, ?, ?, ?, ?, ?)",
"rg1", "nonexistent-artist", "Test Album", "Album", "", false,
); err != nil {
t.Fatalf("insert external release: %v", err)
}
missing, err := ScanArtist(context.Background(), db, "nonexistent-artist", 0)
if err != nil {
t.Fatalf("ScanArtist() error: %v", err)
}
// Should return the release as missing (no filtering applied)
if len(missing) != 1 {
t.Errorf("expected 1 missing release, got %d", len(missing))
}
if missing[0].RGID != "rg1" {
t.Errorf("expected rg1 to be missing, got %v", missing[0].RGID)
}
}
// TestScanArtist_TypeToggle verifies that ScanArtist honors the artist's
// ignore_singles / ignore_compilations toggles at read time, so a toggled
// artist stops reporting those categories as missing immediately (without