diff --git a/packages/@aws-cdk/integ-tests-alpha/lib/assertions/providers/lambda-handler/http.ts b/packages/@aws-cdk/integ-tests-alpha/lib/assertions/providers/lambda-handler/http.ts index 386c56cf1d96e..ec9ff7ba80e7b 100644 --- a/packages/@aws-cdk/integ-tests-alpha/lib/assertions/providers/lambda-handler/http.ts +++ b/packages/@aws-cdk/integ-tests-alpha/lib/assertions/providers/lambda-handler/http.ts @@ -15,11 +15,12 @@ export class HttpHandler extends CustomResourceHandler { describe('HttpHandler', () => { test('default', async () => { // GIVEN - const handler = httpHandler() as any; const request: HttpRequest = { parameters: { url: 'url', @@ -42,7 +41,7 @@ describe('HttpHandler', () => { }; // WHEN - const response: HttpResponseWrapper = await handler.processEvent(request); + const response = await processEvent(request); // THEN expect(response.apiCallResponse).toEqual({ @@ -63,7 +62,6 @@ describe('HttpHandler', () => { test('with fetch options', async () => { // GIVEN - const handler = httpHandler() as any; const request: HttpRequest = { parameters: { url: 'url', @@ -79,7 +77,7 @@ describe('HttpHandler', () => { }; // WHEN - const response: HttpResponseWrapper = await handler.processEvent(request); + const response = await processEvent(request); // THEN expect(response.apiCallResponse).toEqual({ @@ -104,4 +102,34 @@ describe('HttpHandler', () => { }, }); }); + + test('JSON is parsed', async () => { + // GIVEN + fetchMock.mockResolvedValue( + new Response(JSON.stringify({ key: 'value' }), { status: 200, statusText: 'OK', ok: true }), + ); + + // WHEN + const response = await processEvent({ parameters: { url: 'x' } }); + + // THEN + expect(response.apiCallResponse.body).toEqual({ key: 'value' }); + }); + + test('Non-JSON is not parsed', async () => { + // GIVEN + fetchMock.mockResolvedValue( + new Response('this is a string', { status: 200, statusText: 'OK', ok: true }), + ); + + // WHEN + const response = await processEvent({ parameters: { url: 'x' } }); + + // THEN + expect(response.apiCallResponse.body).toEqual('this is a string'); + }); }); + +function processEvent(request: HttpRequest): ReturnType { + return (httpHandler() as any).processEvent(request); +} \ No newline at end of file