Skip to content

Commit

Permalink
test(AWS API Gateway): Improve tests organization
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Dec 16, 2021
1 parent 2c0a962 commit 729196f
Showing 1 changed file with 51 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1418,61 +1418,63 @@ describe('test/unit/lib/plugins/aws/package/compile/events/apiGateway/lib/valida
const getApiGatewayMethod = (path, method) =>
cfResources[naming.getMethodLogicalId(naming.normalizePath(path), method)];

before(async () => {
const result = await runServerless({
fixture: 'function',
command: 'package',
configExt: {
functions: {
corsDefault: {
handler: 'index.handler',
events: [
{
http: {
method: 'POST',
path: '/cors-default-set-by-boolean',
cors: true,
describe('regular', () => {
before(async () => {
const result = await runServerless({
fixture: 'function',
command: 'package',
configExt: {
functions: {
corsDefault: {
handler: 'index.handler',
events: [
{
http: {
method: 'POST',
path: '/cors-default-set-by-boolean',
cors: true,
},
},
},
{
http: {
method: 'POST',
path: '/cors-default-set-by-object',
cors: {},
{
http: {
method: 'POST',
path: '/cors-default-set-by-object',
cors: {},
},
},
},
],
],
},
},
},
},
});
cfTemplate = result.cfTemplate;
cfResources = cfTemplate.Resources;
naming = result.awsNaming;
});
cfTemplate = result.cfTemplate;
cfResources = cfTemplate.Resources;
naming = result.awsNaming;
});

it('should process cors defaults', async () => {
const expected = {
'method.response.header.Access-Control-Allow-Headers': `'${[
'Content-Type',
'X-Amz-Date',
'Authorization',
'X-Api-Key',
'X-Amz-Security-Token',
'X-Amz-User-Agent',
].join(',')}'`,
'method.response.header.Access-Control-Allow-Methods': `'${['OPTIONS', 'POST'].join(',')}'`,
'method.response.header.Access-Control-Allow-Origin': "'*'",
};

expect(
getApiGatewayMethod('/cors-default-set-by-boolean', 'OPTIONS').Properties.Integration
.IntegrationResponses[0].ResponseParameters
).to.deep.eq(expected);
expect(
getApiGatewayMethod('/cors-default-set-by-object', 'OPTIONS').Properties.Integration
.IntegrationResponses[0].ResponseParameters
).to.deep.eq(expected);
it('should process cors defaults', async () => {
const expected = {
'method.response.header.Access-Control-Allow-Headers': `'${[
'Content-Type',
'X-Amz-Date',
'Authorization',
'X-Api-Key',
'X-Amz-Security-Token',
'X-Amz-User-Agent',
].join(',')}'`,
'method.response.header.Access-Control-Allow-Methods': `'${['OPTIONS', 'POST'].join(',')}'`,
'method.response.header.Access-Control-Allow-Origin': "'*'",
};

expect(
getApiGatewayMethod('/cors-default-set-by-boolean', 'OPTIONS').Properties.Integration
.IntegrationResponses[0].ResponseParameters
).to.deep.eq(expected);
expect(
getApiGatewayMethod('/cors-default-set-by-object', 'OPTIONS').Properties.Integration
.IntegrationResponses[0].ResponseParameters
).to.deep.eq(expected);
});
});

it('should throw an error when restApiRootResourceId is not provided with restApiId', async () => {
Expand Down

0 comments on commit 729196f

Please sign in to comment.