Files
netfelix-audio-fix/server/api/__tests__/execute-clear.test.ts
T
felixfoertsch 9d65dd12be
Build and Push Docker Image / build (push) Successful in 2m10s
pipeline ux: actionable errors, inbox sorting, danger stop buttons, overlapping checkmarks
- clickable error count in header shows file names + error messages
- inbox sort dropdown (scan time / name, asc / desc)
- inbox movies no longer minimal (show available badges)
- stop buttons use solid danger style, descriptive labels (Stop Scan, Stop Job, Stop Sorting)
- double checkmarks overlap like WhatsApp read receipts
- processInbox logs start/completion to stdout for Docker visibility
- fix byTitle in language-resolver test, bump to 2026.04.21.1

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-21 08:58:08 +02:00

83 lines
2.7 KiB
TypeScript

import { Database } from "bun:sqlite";
import { describe, expect, test } from "bun:test";
import { SCHEMA } from "../../db/schema";
import { clearQueue } from "../execute";
function makeDb(): Database {
const db = new Database(":memory:");
for (const stmt of SCHEMA.split(";")) {
const trimmed = stmt.trim();
if (trimmed) db.run(trimmed);
}
return db;
}
function seedQueuedItem(db: Database, id: number, autoClass: "auto" | "auto_heuristic" | "manual") {
db
.prepare("INSERT INTO media_items (id, type, name, file_path, container) VALUES (?, 'Movie', ?, ?, 'mkv')")
.run(id, `Item ${id}`, `/x/${id}.mkv`);
db
.prepare(
"INSERT INTO review_plans (item_id, status, is_noop, auto_class, sorted, apple_compat, job_type) VALUES (?, 'approved', 0, ?, 1, 'direct_play', 'copy')",
)
.run(id, autoClass);
db.prepare("INSERT INTO jobs (item_id, command, job_type, status) VALUES (?, 'ffmpeg …', 'audio', 'pending')").run(id);
}
describe("clearQueue", () => {
test("deletes pending jobs and returns plans to the Inbox (sorted=0, pending)", () => {
const db = makeDb();
seedQueuedItem(db, 1, "auto");
seedQueuedItem(db, 2, "auto");
const cleared = clearQueue(db);
expect(cleared).toBe(2);
const plans = db.prepare("SELECT item_id, status, sorted FROM review_plans ORDER BY item_id").all() as {
item_id: number;
status: string;
sorted: number;
}[];
expect(plans).toEqual([
{ item_id: 1, status: "pending", sorted: 0 },
{ item_id: 2, status: "pending", sorted: 0 },
]);
const jobCount = (db.prepare("SELECT COUNT(*) as n FROM jobs WHERE status = 'pending'").get() as { n: number }).n;
expect(jobCount).toBe(0);
});
test("leaves running + completed jobs alone", () => {
const db = makeDb();
seedQueuedItem(db, 1, "auto");
db.prepare("UPDATE jobs SET status = 'running' WHERE item_id = 1").run();
seedQueuedItem(db, 2, "auto");
db.prepare("UPDATE jobs SET status = 'done' WHERE item_id = 2").run();
seedQueuedItem(db, 3, "auto"); // stays pending
const cleared = clearQueue(db);
expect(cleared).toBe(1);
const surviving = db.prepare("SELECT item_id, status FROM jobs ORDER BY item_id").all() as {
item_id: number;
status: string;
}[];
expect(surviving).toEqual([
{ item_id: 1, status: "running" },
{ item_id: 2, status: "done" },
]);
// Only the plan whose job was pending should be reset.
const plan3 = db.prepare("SELECT status, sorted FROM review_plans WHERE item_id = 3").get() as {
status: string;
sorted: number;
};
expect(plan3).toEqual({ status: "pending", sorted: 0 });
const plan1 = db.prepare("SELECT status, sorted FROM review_plans WHERE item_id = 1").get() as {
status: string;
sorted: number;
};
expect(plan1).toEqual({ status: "approved", sorted: 1 });
});
});