Add a paged lyrics quality queue
This commit is contained in:
37
server/admin-tools.test.js
Normal file
37
server/admin-tools.test.js
Normal file
@@ -0,0 +1,37 @@
|
||||
import { describe, test, expect, beforeAll, afterAll } from 'bun:test';
|
||||
import { mkdtempSync, rmSync } from 'node:fs';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
import { Hono } from 'hono';
|
||||
|
||||
const root = mkdtempSync(join(tmpdir(), 'ytp-admin-tools-'));
|
||||
process.env.DB_PATH = join(root, 'admin.db');
|
||||
const db = await import('./db.js');
|
||||
const { registerAdminToolsRoutes } = await import('./admin-tools.js');
|
||||
const app = new Hono();
|
||||
const auth = async (c, next) => c.req.header('x-admin') === 'yes' ? next() : c.json({ ok: false }, 401);
|
||||
|
||||
beforeAll(async () => {
|
||||
await db.initDb();
|
||||
registerAdminToolsRoutes(app, { db, adminAuth: auth });
|
||||
await db.db.execute({ sql: 'INSERT INTO video_meta(id,card,hay,seen,updated_at) VALUES(?,?,?,?,?)', args: ['QualMiss001', JSON.stringify({ title: 'Missing lyric sample', channel: 'Choir' }), 'missing lyric sample choir', 1, Date.now()] });
|
||||
await db.db.execute({ sql: 'INSERT INTO video_meta(id,card,hay,seen,updated_at) VALUES(?,?,?,?,?)', args: ['Untimely001', JSON.stringify({ title: 'Untimed sample', channel: 'Band' }), 'untimed sample band', 1, Date.now()] });
|
||||
await db.db.execute({ sql: "INSERT INTO video_notes(video_id,kind,data,rev,source) VALUES(?, 'lyrics', ?, 1, 'user')", args: ['Untimely001', JSON.stringify({ lines: [{ t: null, text: 'A line' }, { t: 4, text: 'Next' }] })] });
|
||||
});
|
||||
afterAll(() => rmSync(root, { recursive: true, force: true }));
|
||||
|
||||
describe('lyrics quality queue', () => {
|
||||
test('requires admin and returns missing, untimed and short-lyrics reasons in pages', async () => {
|
||||
expect((await app.request('/api/admin/lyrics/quality')).status).toBe(401);
|
||||
const headers = { 'x-admin': 'yes' };
|
||||
const missing = await (await app.request('/api/admin/lyrics/quality?category=missing', { headers })).json();
|
||||
expect(missing.total).toBe(1);
|
||||
expect(missing.songs[0]).toMatchObject({ id: 'QualMiss001', reasons: ['missing'] });
|
||||
const untimed = await (await app.request('/api/admin/lyrics/quality?category=untimed', { headers })).json();
|
||||
expect(untimed.songs[0]).toMatchObject({ id: 'Untimely001', lines: 2, untimed: true });
|
||||
const short = await (await app.request('/api/admin/lyrics/quality?category=short&minLines=3', { headers })).json();
|
||||
expect(short.songs[0].reasons).toContain('short');
|
||||
const page = await (await app.request('/api/admin/lyrics/quality?limit=1&offset=1', { headers })).json();
|
||||
expect(page.songs).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user