diff --git a/__tests__/unit.api-gateway-v2.js b/__tests__/unit.api-gateway-v2.js new file mode 100644 index 00000000..0cafa7ac --- /dev/null +++ b/__tests__/unit.api-gateway-v2.js @@ -0,0 +1,21 @@ +const eventSources = require('../src/event-sources') +const testUtils = require('../src/event-sources/utils.test') + +const apiGatewayEventSource = eventSources.getEventSource({ + eventSourceName: 'AWS_API_GATEWAY_V2' +}) + +test('request has correct headers', () => { + const req = getReq() + // see https://github.com/vendia/serverless-express/issues/387 + expect(typeof req).toEqual('object') + expect(JSON.stringify(req.headers)).toEqual( + '{"cookie":"","host":"localhost:9000","user-agent":"curl/7.64.1","accept":"*/*","x-forwarded-proto":"http","x-forwarded-port":"9000"}' + ) +}) + +function getReq () { + const event = testUtils.sam_httpapi_event + const request = apiGatewayEventSource.getRequest({ event }) + return request +} diff --git a/src/event-sources/aws/api-gateway-v2.js b/src/event-sources/aws/api-gateway-v2.js index 334676ad..def071f9 100644 --- a/src/event-sources/aws/api-gateway-v2.js +++ b/src/event-sources/aws/api-gateway-v2.js @@ -18,7 +18,7 @@ function getRequestValuesFromApiGatewayEvent ({ event }) { search: rawQueryString }) - const headers = [] + const headers = {} if (cookies) { headers.cookie = cookies.join('; ') diff --git a/src/event-sources/utils.test.ts b/src/event-sources/utils.test.ts index acfd475d..b37f742d 100644 --- a/src/event-sources/utils.test.ts +++ b/src/event-sources/utils.test.ts @@ -50,3 +50,7 @@ describe("getEventSourceNameBasedOnEvent", () => { expect(result).toEqual("AWS_API_GATEWAY_V2"); }); }); + +module.exports = { + sam_httpapi_event, +};