65 lines
2.6 KiB
TypeScript
65 lines
2.6 KiB
TypeScript
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("cleans filename-only track names from dotted and temp media filenames", () => {
|
|
assert.deepEqual(parseArtistTitle("The.Hills.flac"), [
|
|
{ source: "The Hills", query: "The Hills", title: "The Hills" }
|
|
]);
|
|
assert.deepEqual(parseArtistTitle("15.I Feel It Coming.temp.mp3"), [
|
|
{ source: "I Feel It Coming", query: "I Feel It Coming", title: "I Feel It Coming" }
|
|
]);
|
|
assert.deepEqual(parseArtistTitle("Y.M.C.A..mp3"), [
|
|
{ source: "Y.M.C.A.", query: "Y.M.C.A.", title: "Y.M.C.A." }
|
|
]);
|
|
});
|
|
|
|
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"
|
|
]);
|
|
});
|