Files
stef-openclaw-skills/skills/spotify/tests/text-list.test.ts

34 lines
1.1 KiB
TypeScript

import assert from "node:assert/strict";
import { mkdtemp, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { tmpdir } from "node:os";
import { test } from "node:test";
import { parseTextList, readTextList } from "../src/importers/text-list.js";
test("parses text list with comments, blanks, and dedupe", () => {
const refs = parseTextList(`
# favorites
Radiohead - Karma Police
Radiohead: Karma Police
// ignored
Massive Attack - Teardrop
`);
assert.equal(refs.some((ref) => ref.artist === "Radiohead" && ref.title === "Karma Police"), true);
assert.equal(refs.some((ref) => ref.artist === "Massive Attack" && ref.title === "Teardrop"), true);
assert.equal(refs.filter((ref) => ref.artist === "Radiohead" && ref.title === "Karma Police").length, 1);
});
test("reads text list from file", async () => {
const root = await mkdtemp(join(tmpdir(), "spotify-text-"));
const path = join(root, "tracks.txt");
await writeFile(path, "Radiohead - Karma Police\n");
const refs = await readTextList(path);
assert.equal(refs[0].artist, "Radiohead");
assert.equal(refs[0].title, "Karma Police");
});