deepkit-framework icon indicating copy to clipboard operation
deepkit-framework copied to clipboard

[Bug] Routes with Return Type `Promise<Response>` Not Serialized Correctly

Open Char2sGu opened this issue 2 years ago • 0 comments

#321 didn't manage to fix this bug completely.

This is the failing version of the current unit test

test('explicitly annotated response objects', async () => {
    class Controller {
        @http.GET('/a')
        a(): JSONResponse {
            return new JSONResponse('a');
        }

        @http.GET('/b')
        b(): HtmlResponse {
            return new HtmlResponse('b');
        }

        @http.GET('/c')
        c(): Response {
            return new Response('c', 'text/plain');
        }

        @http.GET('/d')
        async d(): Promise<Response> {
            return new Response('d', 'text/plain');
        }
    }

    const httpKernel = createHttpKernel([Controller]);

    expect((await httpKernel.request(HttpRequest.GET('/a'))).bodyString).toBe('"a"');
    expect((await httpKernel.request(HttpRequest.GET('/b'))).bodyString).toBe('b');
    expect((await httpKernel.request(HttpRequest.GET('/c'))).bodyString).toBe('c');
    expect((await httpKernel.request(HttpRequest.GET('/d'))).bodyString).toBe('d'); // <-- this fails
});

Char2sGu avatar Aug 21 '22 14:08 Char2sGu