The schema test compares the declared variables against `.env.example`, so the two cannot drift apart. The server tests drive the real handler over a loopback socket rather than a mock, which is what caught the health probe missing from bootstrap mode and the deployments recorded under the wrong guild. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
47 lines
1.7 KiB
JavaScript
47 lines
1.7 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import { describe, it } from 'node:test';
|
|
import { createRouter } from '../src/web/router.js';
|
|
|
|
const noop = () => null;
|
|
|
|
describe('web router', () => {
|
|
const router = createRouter();
|
|
router.get('/api/health', noop, { public: true });
|
|
router.get('/api/repositories/:owner/:repo', noop);
|
|
router.post('/api/repositories/:owner/:repo/issues', noop);
|
|
router.delete('/api/repositories/:owner/:repo/branches', noop);
|
|
|
|
it('matches a static route', () => {
|
|
const route = router.resolve('GET', '/api/health');
|
|
assert.deepEqual(route.params, {});
|
|
assert.equal(route.options.public, true);
|
|
});
|
|
|
|
it('extracts named parameters', () => {
|
|
const route = router.resolve('GET', '/api/repositories/FWS/FWS-Arch');
|
|
assert.deepEqual(route.params, { owner: 'FWS', repo: 'FWS-Arch' });
|
|
});
|
|
|
|
it('decodes percent-encoded parameters', () => {
|
|
const route = router.resolve('GET', '/api/repositories/FWS/mon%20depot');
|
|
assert.equal(route.params.repo, 'mon depot');
|
|
});
|
|
|
|
it('keeps methods apart on the same path', () => {
|
|
assert.doesNotThrow(() => router.resolve('DELETE', '/api/repositories/FWS/Arch/branches'));
|
|
assert.throws(() => router.resolve('GET', '/api/repositories/FWS/Arch/branches'), { status: 405 });
|
|
});
|
|
|
|
it('rejects an unknown path with 404', () => {
|
|
assert.throws(() => router.resolve('GET', '/api/nope'), { status: 404 });
|
|
});
|
|
|
|
it('does not let a shorter path match a longer pattern', () => {
|
|
assert.throws(() => router.resolve('GET', '/api/repositories/FWS'), { status: 404 });
|
|
});
|
|
|
|
it('lists the registered routes', () => {
|
|
assert.ok(router.list().includes('POST /api/repositories/:owner/:repo/issues'));
|
|
});
|
|
});
|