fix: address fourth code review findings

- Fix FK constraint violation in SyncArtistDiscography: delete
  notifications_sent rows before external_releases to prevent
  constraint failure when re-syncing artists with prior notifications.
- Implement per-artist type filtering: FilterReleaseGroups now accepts
  FilterOptions with IgnoreSingles/IgnoreCompilations flags, read from
  artist_settings table via getArtistFilterOptions.
- Fix inconsistent error wrapping: GetExternalRelease now wraps errors
  with fmt.Errorf like all other functions in the package; updated test
  to use errors.Is for sql.ErrNoRows check.
- Add tests: FilterReleaseGroups ignore singles/compilations,
  SyncArtistDiscography per-artist type filtering, and FK-safe resync.
This commit is contained in:
2026-05-26 17:29:05 +03:00
parent 5d52a09868
commit 424be1efc4
6 changed files with 242 additions and 11 deletions

View File

@@ -2,6 +2,7 @@ package database
import (
"database/sql"
"errors"
"testing"
)
@@ -58,7 +59,8 @@ func TestGetExternalRelease_Found(t *testing.T) {
}
}
// TestGetExternalRelease_NotFound verifies that a missing release returns sql.ErrNoRows.
// TestGetExternalRelease_NotFound verifies that a missing release returns an error
// that wraps sql.ErrNoRows.
func TestGetExternalRelease_NotFound(t *testing.T) {
db, err := New(":memory:")
if err != nil {
@@ -67,8 +69,8 @@ func TestGetExternalRelease_NotFound(t *testing.T) {
defer db.Close()
_, err = GetExternalRelease(db, "nonexistent")
if err != sql.ErrNoRows {
t.Errorf("expected sql.ErrNoRows, got %v", err)
if !errors.Is(err, sql.ErrNoRows) {
t.Errorf("expected error wrapping sql.ErrNoRows, got %v", err)
}
}