Files
netfelix-audio-fix/server/api/__tests__/review-approve-ready.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

66 lines
2.0 KiB
TypeScript

import { Database } from "bun:sqlite";
import { describe, expect, test } from "bun:test";
import { SCHEMA } from "../../db/schema";
import { approveReady } 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);
}
return db;
}
function seedSortedPlan(db: Database, id: number, autoClass: "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 media_streams (item_id, stream_index, type, codec, language) VALUES (?, 0, 'Audio', 'eac3', 'eng')",
)
.run(id);
db
.prepare(
"INSERT INTO review_plans (item_id, status, is_noop, auto_class, sorted, apple_compat, job_type) VALUES (?, 'pending', 0, ?, 1, 'direct_play', 'copy')",
)
.run(id, autoClass);
db
.prepare(
"INSERT INTO stream_decisions (plan_id, stream_id, action, target_index) SELECT rp.id, ms.id, 'keep', 0 FROM review_plans rp, media_streams ms WHERE rp.item_id = ? AND ms.item_id = ?",
)
.run(id, id);
}
describe("approveReady", () => {
test("approves auto_heuristic only, leaves manual alone", () => {
const db = makeDb();
seedSortedPlan(db, 1, "auto_heuristic");
seedSortedPlan(db, 2, "manual");
seedSortedPlan(db, 3, "auto_heuristic");
const count = approveReady(db);
expect(count).toBe(2);
const statuses = db.prepare("SELECT item_id, status FROM review_plans ORDER BY item_id").all() as {
item_id: number;
status: string;
}[];
expect(statuses).toEqual([
{ item_id: 1, status: "approved" },
{ item_id: 2, status: "pending" },
{ item_id: 3, status: "approved" },
]);
const jobCount = (db.prepare("SELECT COUNT(*) as n FROM jobs").get() as { n: number }).n;
expect(jobCount).toBe(2);
});
test("noop when nothing is ready", () => {
const db = makeDb();
seedSortedPlan(db, 1, "manual");
expect(approveReady(db)).toBe(0);
});
});