Adds speedtest pg-boss worker with injectable runner for testing, hourly cron enqueue, and /api/speedtest/history (GET) + /run (POST, owner-only) routes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
16 lines
694 B
JavaScript
16 lines
694 B
JavaScript
import { describe, it, expect, beforeAll, vi } from 'vitest';
|
|
import { resetDb } from '../helpers/db.js';
|
|
import { migrateUp } from '../../lib/db/migrate.js';
|
|
import * as worker from '../../lib/jobs/workers/speedtest.js';
|
|
import * as repo from '../../lib/db/repos/speedtest.js';
|
|
|
|
beforeAll(async () => { await resetDb(); await migrateUp(); });
|
|
describe('speedtest worker', () => {
|
|
it('runs the CLI runner and records the result', async () => {
|
|
worker._setRunner(vi.fn().mockResolvedValue({ down_mbps: 95.5, up_mbps: 18.3, ping_ms: 9 }));
|
|
await worker.handler({ id: 'j1', data: {} });
|
|
const hist = await repo.history(1);
|
|
expect(Number(hist[0].down_mbps)).toBe(95.5);
|
|
});
|
|
});
|