Files
netfelix-audio-fix/server/api/__tests__/review-approve-ready.test.ts
T
felixfoertsch 495a40a6c6
Build and Push Docker Image / build (push) Successful in 1m52s
restructure pipeline column headers with backward/skip/forward slots, rename ready → auto-approve
- columnshell: three-row header (title, subtitle, backward · skip · forward grid)
- inbox: auto-processing checkbox moves into subtitle, page top-right toggle removed
- review: add ← back to inbox, rename approve-all-ready to approve auto
- queue: clear button relabeled ← back to inbox (matches existing behaviour)
- done: add ← back to review (reopen-all), clear moves to middle skip slot
- seriescard: action row mirrors movie card, now at the top
-  ready badge →  auto-approve with tooltip, review subtitle uses "auto · need decisions"
- new endpoints: /api/review/unsort-all, /api/review/reopen-all (+ tests)
2026-04-19 13:16:29 +02:00

68 lines
2.1 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, jellyfin_id, type, name, file_path, container) VALUES (?, ?, 'Movie', ?, ?, 'mkv')",
)
.run(id, `jf-${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);
});
});