feat: node http transport with :param route matching

This commit is contained in:
chrnx committed 2026-06-26 00:49:29 -05:00
1 parent 23a31f9264
commit 3803d4fe95
2 files changed
+61

No files matched your search

+16
View File
@@ -0,0 +1,16 @@
import { expect, test } from 'vitest';
import { matchRoute } from '../src/http';
const handler = async () => ({ status: 200, headers: {}, body: 'ok' });
test('matches a static + :param route and extracts params', () => {
const routes = [{ method: 'GET', pattern: '/api/users/:id', handler }];
const m = matchRoute(routes, 'GET', '/api/users/42');
expect(m?.params).toEqual({ id: '42' });
});
test('returns undefined when nothing matches', () => {
const routes = [{ method: 'GET', pattern: '/api/users/:id', handler }];
expect(matchRoute(routes, 'GET', '/api/orders/1')).toBeUndefined();
expect(matchRoute(routes, 'POST', '/api/users/1')).toBeUndefined();
});