feat(speedtest): worker + hourly cron + history/run routes

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>
This commit is contained in:
root
2026-06-02 22:50:19 +10:00
parent c59d2407ed
commit e36a87a50e
7 changed files with 76 additions and 1 deletions

View File

@@ -0,0 +1,15 @@
import { describe, it, expect, beforeAll } from 'vitest';
import request from 'supertest';
import { setup } from './helpers.js';
import * as repo from '../../lib/db/repos/speedtest.js';
let app, ownerHeaders;
beforeAll(async () => { ({ app, ownerHeaders } = await setup()); await repo.record({ down_mbps: 50, up_mbps: 10, ping_ms: 12 }); });
describe('speedtest api', () => {
it('401 without auth', async () => expect((await request(app).get('/api/speedtest/history')).status).toBe(401));
it('history returns rows', async () => {
const res = await request(app).get('/api/speedtest/history').set(ownerHeaders);
expect(res.status).toBe(200);
expect(res.body.length).toBeGreaterThanOrEqual(1);
});
});