Skip to content

Commit

Permalink
set default statusCodes to response if it is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
horike37 committed Feb 26, 2018
1 parent 87c2e01 commit 93c37e4
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
Expand Up @@ -78,6 +78,11 @@ module.exports = {
http.request = this.getRequest(http);
http.request.passThrough = this.getRequestPassThrough(http);
http.response = this.getResponse(http);
if (http.integration === 'AWS' && _.isEmpty(http.response)) {
http.response = {
statusCodes: DEFAULT_STATUS_CODES,
};
}
} else if (http.integration === 'AWS_PROXY' || http.integration === 'HTTP_PROXY') {
// show a warning when request / response config is used with AWS_PROXY (LAMBDA-PROXY)
if (http.request) {
Expand Down
Expand Up @@ -1728,4 +1728,54 @@ describe('#validate()', () => {
expect(validated.events).to.be.an('Array').with.length(1);
expect(validated.events[0].http.request.passThrough).to.equal(undefined);
});

it('should set default statusCodes to response for lambda by default', () => {
awsCompileApigEvents.serverless.service.functions = {
first: {
events: [
{
http: {
method: 'GET',
path: 'users/list',
integration: 'lambda',
integrationMethod: 'GET',
},
},
],
},
};

const validated = awsCompileApigEvents.validate();
expect(validated.events).to.be.an('Array').with.length(1);
expect(validated.events[0].http.response.statusCodes).to.deep.equal({
200: {
pattern: '',
},
400: {
pattern: '[\\s\\S]*\\[400\\][\\s\\S]*',
},
401: {
pattern: '[\\s\\S]*\\[401\\][\\s\\S]*',
},
403: {
pattern: '[\\s\\S]*\\[403\\][\\s\\S]*',
},
404: {
pattern: '[\\s\\S]*\\[404\\][\\s\\S]*',
},
422: {
pattern: '[\\s\\S]*\\[422\\][\\s\\S]*',
},
500: {
pattern:
'[\\s\\S]*(Process\\s?exited\\s?before\\s?completing\\s?request|\\[500\\])[\\s\\S]*',
},
502: {
pattern: '[\\s\\S]*\\[502\\][\\s\\S]*',
},
504: {
pattern: '([\\s\\S]*\\[504\\][\\s\\S]*)|(^[Task timed out].*)',
},
});
});
});

0 comments on commit 93c37e4

Please sign in to comment.