feat(spotify): implement milestone M4 importers
This commit is contained in:
52
skills/spotify/tests/importer-utils.test.ts
Normal file
52
skills/spotify/tests/importer-utils.test.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { test } from "node:test";
|
||||
|
||||
import {
|
||||
buildSearchQueries,
|
||||
dedupeTrackRefs,
|
||||
isAudioFile,
|
||||
normalizeText,
|
||||
parseArtistTitle,
|
||||
stripAudioExtension,
|
||||
stripTrackNumberPrefix
|
||||
} from "../src/importers/importer-utils.js";
|
||||
|
||||
test("normalizes whitespace and underscores", () => {
|
||||
assert.equal(normalizeText(" Radiohead__Karma\tPolice "), "Radiohead Karma Police");
|
||||
});
|
||||
|
||||
test("strips audio extensions and track number prefixes", () => {
|
||||
assert.equal(stripAudioExtension("01 - Radiohead - Karma Police.mp3"), "01 - Radiohead - Karma Police");
|
||||
assert.equal(stripTrackNumberPrefix("01 - Radiohead - Karma Police"), "Radiohead - Karma Police");
|
||||
assert.equal(isAudioFile("song.FLAC"), true);
|
||||
assert.equal(isAudioFile("cover.jpg"), false);
|
||||
});
|
||||
|
||||
test("parses artist title patterns", () => {
|
||||
assert.deepEqual(parseArtistTitle("Radiohead - Karma Police"), [
|
||||
{ source: "Radiohead - Karma Police", query: "Radiohead Karma Police", artist: "Radiohead", title: "Karma Police" },
|
||||
{ source: "Radiohead - Karma Police", query: "Karma Police Radiohead", artist: "Karma Police", title: "Radiohead" }
|
||||
]);
|
||||
assert.deepEqual(parseArtistTitle("Radiohead: Karma Police"), [
|
||||
{ source: "Radiohead: Karma Police", query: "Radiohead Karma Police", artist: "Radiohead", title: "Karma Police" }
|
||||
]);
|
||||
assert.deepEqual(parseArtistTitle("Radiohead_Karma Police"), [
|
||||
{ source: "Radiohead Karma Police", query: "Radiohead Karma Police", artist: "Radiohead", title: "Karma Police" }
|
||||
]);
|
||||
});
|
||||
|
||||
test("dedupes normalized artist title refs", () => {
|
||||
const refs = dedupeTrackRefs([
|
||||
{ source: "a", query: "Radiohead Karma Police", artist: "Radiohead", title: "Karma Police" },
|
||||
{ source: "b", query: "radiohead karma police", artist: " radiohead ", title: "karma police" }
|
||||
]);
|
||||
|
||||
assert.equal(refs.length, 1);
|
||||
});
|
||||
|
||||
test("builds fallback search queries", () => {
|
||||
assert.deepEqual(buildSearchQueries({ source: "x", query: "Radiohead Karma Police", artist: "Radiohead", title: "Karma Police" }), [
|
||||
"Radiohead Karma Police",
|
||||
"track:Karma Police artist:Radiohead"
|
||||
]);
|
||||
});
|
||||
Reference in New Issue
Block a user