feat: Sse/Ws/Stream/Post route decorators with transport metadata
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
2 files changed
+39
-10
No files matched your search
+19
-2
@@ -1,8 +1,9 @@
|
||||
import 'reflect-metadata';
|
||||
import { expect, test } from 'vitest';
|
||||
import { expect, test, describe, it } from 'vitest';
|
||||
import {
|
||||
Provider, Step, Route, Get, Module,
|
||||
getProviderMeta, getStepMeta, getRoutes, getModuleMeta,
|
||||
Sse, Ws, Stream, Post,
|
||||
} from '../src/metadata';
|
||||
|
||||
@Provider({ provides: 'db', needs: ['config'] })
|
||||
@@ -26,7 +27,7 @@ test('step metadata is readable', () => {
|
||||
});
|
||||
|
||||
test('routes carry method, path and handler name', () => {
|
||||
expect(getRoutes(Ctl)).toEqual([{ method: 'GET', path: '/users/:id', handlerName: 'getUser' }]);
|
||||
expect(getRoutes(Ctl)).toEqual([{ method: 'GET', path: '/users/:id', handlerName: 'getUser', transport: 'buffer' }]);
|
||||
});
|
||||
|
||||
test('module metadata lists members', () => {
|
||||
@@ -36,3 +37,19 @@ test('module metadata lists members', () => {
|
||||
expect(m.steps).toEqual([Auth]);
|
||||
expect(m.controllers).toEqual([Ctl]);
|
||||
});
|
||||
|
||||
describe('stream route decorators', () => {
|
||||
it('records transport + method per decorator', () => {
|
||||
class StreamCtl {
|
||||
@Sse('/feed') feed() {}
|
||||
@Ws('/chat') chat() {}
|
||||
@Stream('/either') either() {}
|
||||
@Post('/make') make() {}
|
||||
}
|
||||
const byName = Object.fromEntries(getRoutes(StreamCtl).map((r) => [r.handlerName, r]));
|
||||
expect(byName.feed).toMatchObject({ method: 'GET', transport: 'sse', path: '/feed' });
|
||||
expect(byName.chat).toMatchObject({ method: 'GET', transport: 'ws', path: '/chat' });
|
||||
expect(byName.either).toMatchObject({ method: 'GET', transport: 'negotiate', path: '/either' });
|
||||
expect(byName.make).toMatchObject({ method: 'POST', transport: 'buffer', path: '/make' });
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user