feat(router): expose HEAD and OPTIONS decorators
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
6 files changed
+30
-5
No files matched your search
+13
-1
@@ -3,7 +3,7 @@ import { expect, test, describe, it } from 'vitest';
|
||||
import {
|
||||
Provider, Step, Route, Get, Module,
|
||||
getProviderMeta, getStepMeta, getRoutes, getModuleMeta,
|
||||
Sse, Ws, Stream, Post,
|
||||
Sse, Ws, Stream, Post, Head, Options,
|
||||
} from '../src/metadata';
|
||||
|
||||
@Provider({ provides: 'db', needs: ['config'] })
|
||||
@@ -54,6 +54,18 @@ describe('stream route decorators', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('HEAD and OPTIONS decorators', () => {
|
||||
it('records both as buffered methods', () => {
|
||||
class Methods {
|
||||
@Head('/resource') head() {}
|
||||
@Options('/resource') options() {}
|
||||
}
|
||||
const byName = Object.fromEntries(getRoutes(Methods).map((route) => [route.handlerName, route]));
|
||||
expect(byName.head).toMatchObject({ method: 'HEAD', transport: 'buffer', path: '/resource' });
|
||||
expect(byName.options).toMatchObject({ method: 'OPTIONS', transport: 'buffer', path: '/resource' });
|
||||
});
|
||||
});
|
||||
|
||||
describe('mesh export flags', () => {
|
||||
it('providers/steps carry export (default false)', () => {
|
||||
@Provider({ provides: 'config', export: true }) class C { provide() { return {}; } }
|
||||
|
||||
+8
-1
@@ -1,6 +1,13 @@
|
||||
import { expect, test } from 'vitest';
|
||||
import { VERSION } from '../src/index';
|
||||
import { Head, Options, VERSION, type HttpMethod } from '../src/index';
|
||||
|
||||
test('package loads and exposes a CalVer VERSION', () => {
|
||||
expect(VERSION).toMatch(/^\d{2}\.\d{1,2}\.\d+(-beta\.\d+)?$/);
|
||||
});
|
||||
|
||||
test('public barrel exports HEAD and OPTIONS route decorators', () => {
|
||||
const methods: HttpMethod[] = ['HEAD', 'OPTIONS'];
|
||||
expect(Head).toBeTypeOf('function');
|
||||
expect(Options).toBeTypeOf('function');
|
||||
expect(methods).toEqual(['HEAD', 'OPTIONS']);
|
||||
});
|
||||
Reference in new issue
Block a user