686434f5c3
- delete server/services/jellyfin.ts, webhook.ts, mqtt.ts and their tests - strip jellyfin/mqtt imports and startup calls from index.tsx and settings.ts - remove /jellyfin, /mqtt, /mqtt/status, /mqtt/test, /jellyfin/webhook-plugin endpoints from settings router - clean ENV_MAP and isEnvConfigured of jellyfin/mqtt keys - add db/index.ts migrations for series_key, duration_seconds, scan_status, scan_error, last_scanned_at (new columns absent on older dev DBs) - move idx_media_items_series_key out of SCHEMA into migrate() so it runs after the column is added - fix all test fixtures: drop jellyfin_id/series_jellyfin_id column refs, update MediaItem/MediaStream object literals to match current types Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
51 lines
1.8 KiB
TypeScript
51 lines
1.8 KiB
TypeScript
import { Database } from "bun:sqlite";
|
|
import { describe, expect, test } from "bun:test";
|
|
import { SCHEMA } from "../../db/schema";
|
|
import { enqueueAudioJob } from "../review";
|
|
|
|
function makeDb(): Database {
|
|
const db = new Database(":memory:");
|
|
for (const stmt of SCHEMA.split(";")) {
|
|
const trimmed = stmt.trim();
|
|
if (trimmed) db.run(trimmed);
|
|
}
|
|
db
|
|
.prepare("INSERT INTO media_items (id, type, name, file_path) VALUES (?, 'Movie', 'T', '/x.mkv')")
|
|
.run(1);
|
|
return db;
|
|
}
|
|
|
|
describe("enqueueAudioJob dedup", () => {
|
|
test("inserts a job when none exists", () => {
|
|
const db = makeDb();
|
|
expect(enqueueAudioJob(db, 1, "ffmpeg a")).toBe(true);
|
|
const { n } = db.prepare("SELECT COUNT(*) as n FROM jobs WHERE item_id = 1").get() as { n: number };
|
|
expect(n).toBe(1);
|
|
});
|
|
|
|
test("no-ops when a pending job already exists", () => {
|
|
const db = makeDb();
|
|
enqueueAudioJob(db, 1, "ffmpeg a");
|
|
expect(enqueueAudioJob(db, 1, "ffmpeg b")).toBe(false);
|
|
expect(enqueueAudioJob(db, 1, "ffmpeg c")).toBe(false);
|
|
const rows = db.prepare("SELECT command FROM jobs WHERE item_id = 1").all() as { command: string }[];
|
|
expect(rows.length).toBe(1);
|
|
expect(rows[0].command).toBe("ffmpeg a");
|
|
});
|
|
|
|
test("allows a new pending job once the previous one is done or errored", () => {
|
|
const db = makeDb();
|
|
enqueueAudioJob(db, 1, "ffmpeg a");
|
|
db.prepare("UPDATE jobs SET status = 'done' WHERE item_id = 1").run();
|
|
expect(enqueueAudioJob(db, 1, "ffmpeg b")).toBe(true);
|
|
|
|
db.prepare("UPDATE jobs SET status = 'error' WHERE command = 'ffmpeg b'").run();
|
|
expect(enqueueAudioJob(db, 1, "ffmpeg c")).toBe(true);
|
|
|
|
const pending = db.prepare("SELECT COUNT(*) as n FROM jobs WHERE item_id = 1 AND status = 'pending'").get() as {
|
|
n: number;
|
|
};
|
|
expect(pending.n).toBe(1);
|
|
});
|
|
});
|