From ab96f2f3c0f7f795692d49e6a37ee5194647a9c1 Mon Sep 17 00:00:00 2001 From: "Marc J. Schmidt" Date: Fri, 27 Sep 2024 12:45:15 +0200 Subject: [PATCH] chore(http): add failing test for #614 --- packages/http/src/model.ts | 8 ++++++-- packages/http/tests/router.spec.ts | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/packages/http/src/model.ts b/packages/http/src/model.ts index 4577081ba..2a1b81af7 100644 --- a/packages/http/src/model.ts +++ b/packages/http/src/model.ts @@ -365,8 +365,12 @@ Content-Type: application/json\r return this; } - query(query: any): this { - this.queryPath = querystring.stringify(query); + query(query: any | string): this { + if ('string' === typeof query) { + this.queryPath = query; + } else { + this.queryPath = querystring.stringify(query); + } return this; } } diff --git a/packages/http/tests/router.spec.ts b/packages/http/tests/router.spec.ts index 8c5bd4f65..9ac067fab 100644 --- a/packages/http/tests/router.spec.ts +++ b/packages/http/tests/router.spec.ts @@ -1727,6 +1727,25 @@ test('required fields in body should be required', async () => { expect((await httpKernel.request(HttpRequest.POST('/').json({ a: 'a', b: 'asd' }))).json).toEqual(['a', 'asd']); }); +test('query validator withing HttpQuery', async () => { + class Controller { + @http.GET('do') + async do( + a: HttpQuery>, + b: HttpQuery, + ) { + return { valid: true }; + } + } + + const httpKernel = createHttpKernel([Controller]); + + //todo: fix this, see https://github.com/deepkit/deepkit-framework/issues/614 + // expect((await httpKernel.request(HttpRequest.GET('/do').query('a=aaaaaaaa&b=bbbb'))).json).toMatchObject({ + // valid: true + // }); +}); + test('http body deep optional union', async () => { interface AdTitleAndBasicAttributes { title: string;