Files
minstrel/internal/playlists/seed_selection_test.go
T

48 lines
1.4 KiB
Go

package playlists
import (
"testing"
"github.com/jackc/pgx/v5/pgtype"
)
// pickSeedArtistsFromRows is the pure helper that turns sqlc rows into
// the seed list. The DB-level query is exercised in system_test.go's
// integration test; this unit test pins the post-fetch logic.
func TestPickSeedArtistsFromRows_PreservesOrder(t *testing.T) {
mk := func(b byte, score int64) seedArtistRow {
return seedArtistRow{
ArtistID: pgtype.UUID{Bytes: [16]byte{b}, Valid: true},
Score: score,
}
}
// Caller (SQL) already orders + limits; helper preserves order.
rows := []seedArtistRow{mk(1, 100), mk(2, 50), mk(3, 25)}
got := pickSeedArtistsFromRows(rows)
if len(got) != 3 {
t.Fatalf("len: got %d, want 3", len(got))
}
if got[0].Bytes[0] != 1 || got[1].Bytes[0] != 2 || got[2].Bytes[0] != 3 {
t.Errorf("expected [1,2,3] preserving input order; got %v", got)
}
}
func TestPickSeedArtistsFromRows_FewerThanThree(t *testing.T) {
mk := func(b byte, score int64) seedArtistRow {
return seedArtistRow{ArtistID: pgtype.UUID{Bytes: [16]byte{b}, Valid: true}, Score: score}
}
rows := []seedArtistRow{mk(1, 100)}
got := pickSeedArtistsFromRows(rows)
if len(got) != 1 {
t.Errorf("len: got %d, want 1", len(got))
}
}
func TestPickSeedArtistsFromRows_Empty(t *testing.T) {
got := pickSeedArtistsFromRows(nil)
if len(got) != 0 {
t.Errorf("empty input should yield empty output; got %v", got)
}
}