metadata.test.ts (1230B)
1 import { describe, expect, it } from "vitest"; 2 3 import { buildArchiveDownloadUrl, parseTrackLine } from "./metadata.js"; 4 5 describe("buildArchiveDownloadUrl", () => { 6 it("builds ZIP member URL from MySpace CDN path", () => { 7 const url = 8 "http://cache06-music02.myspacecdn.com/46/std_1f69563352d19cb0132334cd0d3adeaf.mp3"; 9 const out = buildArchiveDownloadUrl(url); 10 expect(out).toBe( 11 "https://archive.org/download/myspace_dragon_hoard_2010/46.zip/46%2Fstd_1f69563352d19cb0132334cd0d3adeaf.mp3", 12 ); 13 }); 14 15 it("returns null for invalid URLs", () => { 16 expect(buildArchiveDownloadUrl("not-a-url")).toBeNull(); 17 expect(buildArchiveDownloadUrl("https://example.com/foo.txt")).toBeNull(); 18 }); 19 }); 20 21 describe("parseTrackLine", () => { 22 it("parses a valid TSV line", () => { 23 const line = 24 "1\tBig Yellow Moon\t78393366\tbill nelson\twww.myspace.com/x\t0\tmyspace\t25796\thttp://cache06-music02.myspacecdn.com/46/std_1f69563352d19cb0132334cd0d3adeaf.mp3"; 25 const t = parseTrackLine(line); 26 expect(t).not.toBeNull(); 27 expect(t!.id).toBe("1"); 28 expect(t!.title).toBe("Big Yellow Moon"); 29 expect(t!.artist).toBe("bill nelson"); 30 expect(t!.fileKey).toMatch(/\.mp3$/i); 31 }); 32 });