feat(routes): per-endpoint duplicates override via @Post/@Get opts

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
chrnx committed 2026-07-06 20:16:46 -05:00
1 parent ec2e3a0e62
commit 34017f6ab2
4 files changed
+23 -6

No files matched your search

+15
View File
@@ -72,4 +72,19 @@ describe('bodyDuplicates', () => {
method: 'POST', headers: { 'content-type': 'application/x-www-form-urlencoded' }, body: 'x=1&x=2' });
expect(await r.json()).toEqual({ x: '2' });
});
it('per-endpoint override beats app default', async () => {
@Route('/') class C {
@Post('/a', { duplicates: 'last' }) a(@body() b: any) { return b; }
@Post('/b', { duplicates: 'array' }) b2(@body() b: any) { return b; }
}
@Module({ mountpoint: '/', controllers: [C] }) class CMod {}
app = createApp({ modules: [CMod], bodyDuplicates: 'last' });
const server = await app.listen(0);
const port = (server.address() as any).port;
const post = (p: string) => fetch(`http://127.0.0.1:${port}${p}`, {
method: 'POST', headers: { 'content-type': 'application/x-www-form-urlencoded' }, body: 'x=1&x=2' }).then((r) => r.json());
expect(await post('/a')).toEqual({ x: '2' });
expect(await post('/b')).toEqual({ x: ['1', '2'] });
});
});