Skip to content

Commit b243995

Browse files
committed
refactor: replace usage of apiGatewayRequest by makeAPIGatewayRequestEvent on
integration-tests - makeAPIGatewayRequestEvent accepts an input object, allowing the developer to change values of desired fields when needed, while apiGatewayRequest would always return the same object
1 parent a454a2a commit b243995

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

tests/integration-tests.test.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import _ from 'underscore';
22
import {
3-
apiGatewayRequest,
43
handlerContext,
54
albRequest,
65
albMultiValHeadersRequest,
76
apiGatewayRequestRawQuery,
7+
makeAPIGatewayRequestEvent,
88
} from './samples';
99
import { spy, SinonSpy, assert } from 'sinon';
1010
import { Application, Request, Response, Router } from '../src';
@@ -22,7 +22,7 @@ describe('integration tests', () => {
2222
});
2323

2424
const makeRequestEvent = (path: string, base?: RequestEvent, method?: string): RequestEvent => {
25-
return _.extend(base || apiGatewayRequest(), { path: path, httpMethod: (method || 'GET') });
25+
return _.extend(base, { path: path, httpMethod: (method || 'GET') });
2626
};
2727

2828
const testWithLastResortHandler = (code: number, desc: string, testHeaders: string[] = [], expectedBody = ''): void => {
@@ -54,7 +54,7 @@ describe('integration tests', () => {
5454

5555
const testOutcome = (method: string, path: string, expectedBody: string): void => {
5656
const cb = spy(),
57-
evt = makeRequestEvent(path, apiGatewayRequest(), method);
57+
evt = makeAPIGatewayRequestEvent({ path, httpMethod: method });
5858

5959
app.run(evt, handlerContext(), cb);
6060

@@ -121,7 +121,7 @@ describe('integration tests', () => {
121121
};
122122

123123
it('works - APIGW', () => {
124-
const cb = test(makeRequestEvent('/hello/world'));
124+
const cb = test(makeAPIGatewayRequestEvent({ path: '/hello/world' }));
125125

126126
assert.calledWithExactly(cb, undefined, {
127127
statusCode: 200,
@@ -342,7 +342,10 @@ describe('integration tests', () => {
342342
// eslint-disable-next-line max-len,max-params
343343
const addTestsForMethod = (method: string, code: number, desc: string, hdrName: string, hdrVal: string, expectedBody: string, prep: () => void, contentType?: string): void => {
344344
const baseEvents = {
345-
'APIGW': apiGatewayRequest(),
345+
'APIGW': makeAPIGatewayRequestEvent({
346+
path: '/hello/world',
347+
httpMethod: method,
348+
}),
346349
'ALB': albRequest(),
347350
'ALBMV': albMultiValHeadersRequest(),
348351
};
@@ -760,7 +763,7 @@ describe('integration tests', () => {
760763
describe('request object', () => {
761764

762765
it('has an immutable context property', () => {
763-
let evt = makeRequestEvent('/test', apiGatewayRequest(), 'GET'),
766+
let evt = makeAPIGatewayRequestEvent({ path: '/test', httpMethod: 'GET' }),
764767
ctx = handlerContext(true),
765768
handler;
766769

0 commit comments

Comments
 (0)