feat: complete Task 1 - update database schema and model for live/remix filtering

This commit is contained in:
2026-08-05 17:03:40 +03:00
parent f49ad40002
commit 75326cda3a
3 changed files with 285 additions and 14 deletions

View File

@@ -592,3 +592,196 @@ func TestSaveArtistSettings_LastSyncedUpdated(t *testing.T) {
t.Errorf("expected last_synced to be updated to %v, got %v", newTime, got.LastSynced)
}
}
// TestGetArtistSettings_FoundWithNewFields verifies retrieving an existing artist with new fields.
func TestGetArtistSettings_FoundWithNewFields(t *testing.T) {
db, err := New(":memory:")
if err != nil {
t.Fatalf("New() error: %v", err)
}
defer db.Close()
// Insert a row with all fields including new ones
_, err = db.Conn().Exec(
"INSERT INTO artist_settings (id, name, mbid, ignore_singles, ignore_compilations, ignore_live, ignore_remix, monitored, last_synced) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
"artist-1", "Test Artist", "", true, false, true, false, true, time.Now(),
)
if err != nil {
t.Fatalf("insert: %v", err)
}
s, err := GetArtistSettings(db, "artist-1")
if err != nil {
t.Fatalf("GetArtistSettings() error: %v", err)
}
if s.ID != "artist-1" {
t.Errorf("expected ID 'artist-1', got %q", s.ID)
}
if s.Name != "Test Artist" {
t.Errorf("expected Name 'Test Artist', got %q", s.Name)
}
if !s.IgnoreSingles {
t.Error("expected IgnoreSingles true")
}
if s.IgnoreCompilations {
t.Error("expected IgnoreCompilations false")
}
if !s.IgnoreLive {
t.Error("expected IgnoreLive true")
}
if s.IgnoreRemix {
t.Error("expected IgnoreRemix false")
}
if !s.Monitored {
t.Error("expected Monitored true")
}
}
// TestSaveArtistSettings_UpdateNewFields verifies that SaveArtistSettings works with new fields.
func TestSaveArtistSettings_UpdateNewFields(t *testing.T) {
db, err := New(":memory:")
if err != nil {
t.Fatalf("New() error: %v", err)
}
defer db.Close()
// Insert initial row
s1 := &ArtistSettings{
ID: "artist-1",
Name: "Original Name",
IgnoreSingles: false,
IgnoreCompilations: false,
IgnoreLive: false,
IgnoreRemix: false,
Monitored: true,
}
if err := SaveArtistSettings(db, s1); err != nil {
t.Fatalf("first SaveArtistSettings() error: %v", err)
}
// Update with new fields
s2 := &ArtistSettings{
ID: "artist-1",
Name: "Updated Name",
IgnoreSingles: true,
IgnoreCompilations: true,
IgnoreLive: true,
IgnoreRemix: true,
Monitored: false,
}
if err := SaveArtistSettings(db, s2); err != nil {
t.Fatalf("second SaveArtistSettings() error: %v", err)
}
got, err := GetArtistSettings(db, "artist-1")
if err != nil {
t.Fatalf("GetArtistSettings() error: %v", err)
}
if got.Name != "Updated Name" {
t.Errorf("expected Name 'Updated Name', got %q", got.Name)
}
if !got.IgnoreSingles {
t.Error("expected IgnoreSingles true")
}
if !got.IgnoreCompilations {
t.Error("expected IgnoreCompilations true")
}
if !got.IgnoreLive {
t.Error("expected IgnoreLive true")
}
if !got.IgnoreRemix {
t.Error("expected IgnoreRemix false")
}
if got.Monitored {
t.Error("expected Monitored false")
}
}
// TestUpdateArtistSettings_NewFields verifies updating the new fields works.
func TestUpdateArtistSettings_NewFields(t *testing.T) {
db, err := New(":memory:")
if err != nil {
t.Fatalf("New() error: %v", err)
}
defer db.Close()
// Insert initial row
s := &ArtistSettings{
ID: "artist-1",
Name: "Original",
IgnoreSingles: false,
IgnoreCompilations: false,
IgnoreLive: false,
IgnoreRemix: false,
Monitored: true,
}
if err := SaveArtistSettings(db, s); err != nil {
t.Fatalf("SaveArtistSettings() error: %v", err)
}
// Update only new fields
updates := map[string]interface{}{
"ignore_live": true,
"ignore_remix": true,
}
if err := UpdateArtistSettings(db, "artist-1", updates); err != nil {
t.Fatalf("UpdateArtistSettings() error: %v", err)
}
got, err := GetArtistSettings(db, "artist-1")
if err != nil {
t.Fatalf("GetArtistSettings() error: %v", err)
}
if !got.IgnoreLive {
t.Error("expected IgnoreLive true")
}
if !got.IgnoreRemix {
t.Error("expected IgnoreRemix true")
}
// Unchanged fields should remain
if got.IgnoreSingles != false {
t.Error("expected IgnoreSingles unchanged (false)")
}
if got.IgnoreCompilations != false {
t.Error("expected IgnoreCompilations unchanged (false)")
}
if !got.Monitored {
t.Error("expected Monitored unchanged (true)")
}
}
// TestUpdateArtistSettings_NewFieldsNotFound verifies updating a nonexistent artist returns error.
func TestUpdateArtistSettings_NewFieldsNotFound(t *testing.T) {
db, err := New(":memory:")
if err != nil {
t.Fatalf("New() error: %v", err)
}
defer db.Close()
updates := map[string]interface{}{"ignore_live": true}
err = UpdateArtistSettings(db, "nonexistent", updates)
if err == nil {
t.Error("expected error for nonexistent artist, got nil")
}
}
// TestUpdateArtistSettings_InvalidColumnNewFields verifies unknown columns are rejected.
func TestUpdateArtistSettings_InvalidColumnNewFields(t *testing.T) {
db, err := New(":memory:")
if err != nil {
t.Fatalf("New() error: %v", err)
}
defer db.Close()
s := &ArtistSettings{ID: "artist-1", Name: "Test"}
if err := SaveArtistSettings(db, s); err != nil {
t.Fatalf("SaveArtistSettings() error: %v", err)
}
updates := map[string]interface{}{"invalid_col": "value"}
err = UpdateArtistSettings(db, "artist-1", updates)
if err == nil {
t.Error("expected error for invalid column, got nil")
}
}

View File

@@ -31,7 +31,7 @@ func TestNew_InitializationAndSchema(t *testing.T) {
}
}
// TestNew_MigrationIdempency verifies that calling New() twice (via migrate) does not fail.
// TestNew_MigrationIdempotency verifies that calling New() twice (via migrate) does not fail.
func TestNew_MigrationIdempotency(t *testing.T) {
db, err := New(":memory:")
if err != nil {
@@ -89,26 +89,27 @@ func TestArtistSettingsSchema(t *testing.T) {
// Insert a row to verify column names and types.
_, err = db.Conn().Exec(
"INSERT INTO artist_settings (id, name, ignore_singles, ignore_compilations, monitored) VALUES (?, ?, ?, ?, ?)",
"artist-1", "Test Artist", true, false, true,
"INSERT INTO artist_settings (id, name, ignore_singles, ignore_compilations, ignore_live, ignore_remix, monitored) VALUES (?, ?, ?, ?, ?, ?, ?)",
"artist-1", "Test Artist", true, false, false, false, true,
)
if err != nil {
t.Fatalf("insert into artist_settings: %v", err)
}
var id, name string
var ignoreLive, ignoreRemix bool
var ignoreSingles, ignoreCompilations, monitored bool
err = db.Conn().QueryRow(
"SELECT id, name, ignore_singles, ignore_compilations, monitored FROM artist_settings WHERE id = ?",
"SELECT id, name, ignore_singles, ignore_compilations, ignore_live, ignore_remix, monitored FROM artist_settings WHERE id = ?",
"artist-1",
).Scan(&id, &name, &ignoreSingles, &ignoreCompilations, &monitored)
).Scan(&id, &name, &ignoreSingles, &ignoreCompilations, &ignoreLive, &ignoreRemix, &monitored)
if err != nil {
t.Fatalf("select from artist_settings: %v", err)
}
if id != "artist-1" || name != "Test Artist" || !ignoreSingles || ignoreCompilations || !monitored {
t.Errorf("unexpected row values: id=%q name=%q ignoreSingles=%v ignoreCompilations=%v monitored=%v",
id, name, ignoreSingles, ignoreCompilations, monitored)
if id != "artist-1" || name != "Test Artist" || !ignoreSingles || ignoreCompilations || ignoreLive || ignoreRemix || !monitored {
t.Errorf("unexpected row values: id=%q name=%q ignoreSingles=%v ignoreCompilations=%v ignoreLive=%v ignoreRemix=%v monitored=%v",
id, name, ignoreSingles, ignoreCompilations, ignoreLive, ignoreRemix, monitored)
}
}
@@ -205,11 +206,8 @@ func TestMigrationTracking(t *testing.T) {
t.Fatalf("query migrations count: %v", err)
}
// We have 9 recorded migrations: artist_settings, external_releases,
// local_albums, notifications_sent, cached_at column, secondary_types
// column, the external_releases.artist_id index, the artist_settings mbid
// column, and the artist_settings last_synced column.
if count != 9 {
t.Errorf("expected 9 applied migrations, got %d", count)
// We now have 10 recorded migrations.
if count != 10 {
t.Errorf("expected 10 applied migrations, got %d", count)
}
}