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:
@@ -20,7 +20,7 @@ func TestFilterReleaseGroups_ExcludesBootlegPromotionPseudo(t *testing.T) {
|
||||
{ID: "rg-4", Title: "Pseudo Release", Type: "Album", Status: "Pseudo-Release"},
|
||||
}
|
||||
|
||||
result := FilterReleaseGroups(groups)
|
||||
result := FilterReleaseGroups(groups, FilterOptions{})
|
||||
|
||||
if len(result) != 1 {
|
||||
t.Fatalf("FilterReleaseGroups() returned %d groups, want 1", len(result))
|
||||
@@ -41,7 +41,7 @@ func TestFilterReleaseGroups_IncludesOnlyAllowedTypes(t *testing.T) {
|
||||
{ID: "rg-7", Title: "Remix", Type: "Remix", Status: "Official"},
|
||||
}
|
||||
|
||||
result := FilterReleaseGroups(groups)
|
||||
result := FilterReleaseGroups(groups, FilterOptions{})
|
||||
|
||||
if len(result) != 4 {
|
||||
t.Fatalf("FilterReleaseGroups() returned %d groups, want 4", len(result))
|
||||
@@ -55,6 +55,44 @@ func TestFilterReleaseGroups_IncludesOnlyAllowedTypes(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterReleaseGroups_IgnoreSingles(t *testing.T) {
|
||||
groups := []ReleaseGroup{
|
||||
{ID: "rg-1", Title: "Album", Type: "Album", Status: "Official"},
|
||||
{ID: "rg-2", Title: "Single", Type: "Single", Status: "Official"},
|
||||
{ID: "rg-3", Title: "EP", Type: "EP", Status: "Official"},
|
||||
}
|
||||
|
||||
result := FilterReleaseGroups(groups, FilterOptions{IgnoreSingles: true})
|
||||
|
||||
if len(result) != 2 {
|
||||
t.Fatalf("FilterReleaseGroups() returned %d groups, want 2", len(result))
|
||||
}
|
||||
for _, rg := range result {
|
||||
if rg.Type == "Single" {
|
||||
t.Errorf("single %q should have been filtered out", rg.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterReleaseGroups_IgnoreCompilations(t *testing.T) {
|
||||
groups := []ReleaseGroup{
|
||||
{ID: "rg-1", Title: "Album", Type: "Album", Status: "Official"},
|
||||
{ID: "rg-2", Title: "Compilation", Type: "Compilation", Status: "Official"},
|
||||
{ID: "rg-3", Title: "EP", Type: "EP", Status: "Official"},
|
||||
}
|
||||
|
||||
result := FilterReleaseGroups(groups, FilterOptions{IgnoreCompilations: true})
|
||||
|
||||
if len(result) != 2 {
|
||||
t.Fatalf("FilterReleaseGroups() returned %d groups, want 2", len(result))
|
||||
}
|
||||
for _, rg := range result {
|
||||
if rg.Type == "Compilation" {
|
||||
t.Errorf("compilation %q should have been filtered out", rg.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- NormalizeString tests ----------
|
||||
|
||||
func TestNormalizeString_Basic(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user