fix: address code review findings

This commit is contained in:
2026-07-19 19:52:27 +03:00
parent a7803615cd
commit 0bee9b9b27
6 changed files with 138 additions and 31 deletions

View File

@@ -827,8 +827,50 @@ func TestSyncArtistDiscography_IgnoreCompilations(t *testing.T) {
}
// -----------------------------------------------------------------------
// Test: resync with notifications_sent does not violate FK constraint
// Test: cache-hit path applies secondary-type filtering consistently with the
// cache-miss path. A release whose primary type is "Album" but which is also
// a "Compilation" via its secondary type must be dropped by IgnoreCompilations
// on a cache hit, exactly as FilterReleaseGroups drops it on a cache miss.
// -----------------------------------------------------------------------
func TestSyncArtistDiscography_CacheHit_IgnoreSecondaryCompilation(t *testing.T) {
artistID := "nav-comp-secondary-test"
artistName := "Secondary Comp Artist"
db := newTestDB(t)
defer db.Close()
if _, err := db.Conn().Exec(
"INSERT INTO artist_settings (id, name, ignore_compilations, monitored) VALUES (?, ?, 1, 1)",
artistID, artistName,
); err != nil {
t.Fatalf("seed artist: %v", err)
}
// Seed a cached release: primary "Album" + secondary "Compilation".
// cached_at is set far in the past so it is still within any TTL (TTL 0).
if err := database.SaveExternalRelease(db, &database.ExternalRelease{
RGID: "rg-comp",
ArtistID: artistID,
Title: "Greatest Hits",
Type: "Album",
SecondaryTypes: []string{"Compilation"},
IsIgnored: false,
CachedAt: time.Now().UTC(),
}); err != nil {
t.Fatalf("seed cached release: %v", err)
}
// No MusicBrainz server is started; a cache hit must not hit the API.
client := newTestClient("http://unused.invalid")
ctx := context.Background()
releases, err := SyncArtistDiscography(ctx, client, db, artistID, "mbid-unused", 0)
if err != nil {
t.Fatalf("SyncArtistDiscography() error: %v", err)
}
if len(releases) != 0 {
t.Fatalf("expected 0 releases (secondary compilation filtered on cache hit), got %d", len(releases))
}
}
func TestSyncArtistDiscography_ResyncWithNotifications(t *testing.T) {
artistMBID := "artist-fk-test"
artistID := "nav-fk-test"