trackStore.test.ts (1439B)
1 import { describe, expect, it, beforeEach, afterEach } from "vitest"; 2 3 import type { TrackMeta } from "./metadata.js"; 4 import { WritableTrackStore } from "./trackStore.js"; 5 6 const SAMPLE: TrackMeta[] = [ 7 { 8 id: "1", 9 title: "Moon Song", 10 artist: "Bill Nelson", 11 fileKey: "a.mp3", 12 cdnUrl: "http://cache06-music02.myspacecdn.com/46/std_a.mp3", 13 archiveUrl: "https://archive.org/download/myspace_dragon_hoard_2010/46.zip/46%2Fa.mp3", 14 }, 15 { 16 id: "2", 17 title: "Fire Track", 18 artist: "Other Artist", 19 fileKey: "b.mp3", 20 cdnUrl: "http://cache06-music02.myspacecdn.com/46/std_b.mp3", 21 archiveUrl: "https://archive.org/download/myspace_dragon_hoard_2010/46.zip/46%2Fb.mp3", 22 }, 23 ]; 24 25 describe("TrackStore", () => { 26 let store: WritableTrackStore; 27 28 beforeEach(() => { 29 store = new WritableTrackStore(":memory:"); 30 store.open(); 31 store.insertBatch(SAMPLE); 32 store.finishIndex(); 33 }); 34 35 afterEach(() => { 36 store.close(); 37 }); 38 39 it("counts tracks", () => { 40 expect(store.count()).toBe(2); 41 }); 42 43 it("gets by id", () => { 44 const t = store.getById("1"); 45 expect(t?.title).toBe("Moon Song"); 46 }); 47 48 it("searches by artist", () => { 49 const hits = store.search("Bill", 10); 50 expect(hits.some((h) => h.id === "1")).toBe(true); 51 }); 52 53 it("excludes blocked ids from random", () => { 54 store.blockId("1"); 55 const t = store.random(); 56 expect(t?.id).toBe("2"); 57 }); 58 });