31 lines
918 B
JavaScript
31 lines
918 B
JavaScript
import assert from "node:assert/strict"
|
|
import test from "node:test"
|
|
|
|
import { stationArtistId } from "./station-artist.ts"
|
|
|
|
const songs = [
|
|
{ id: "song-a", artist: { id: "artist-a" } },
|
|
{ id: "song-b", artist: { id: "artist-a" } },
|
|
{ id: "song-c", artist: { id: "artist-b" } },
|
|
]
|
|
|
|
test("a single song or a selection sharing one artist can create a station", () => {
|
|
assert.equal(stationArtistId(songs, new Set(["song-c"])), "artist-b")
|
|
assert.equal(
|
|
stationArtistId(songs, new Set(["song-a", "song-b"])),
|
|
"artist-a"
|
|
)
|
|
})
|
|
|
|
test("mixed artists cannot create a station", () => {
|
|
assert.equal(stationArtistId(songs, new Set(["song-a", "song-c"])), undefined)
|
|
})
|
|
|
|
test("empty or partially missing selections cannot create a station", () => {
|
|
assert.equal(stationArtistId(songs, new Set()), undefined)
|
|
assert.equal(
|
|
stationArtistId(songs, new Set(["song-a", "missing"])),
|
|
undefined
|
|
)
|
|
})
|