Skip to content

Commit

Permalink
fix(AWS API Gateway): Correctly set throttle when quota missing
Browse files Browse the repository at this point in the history
  • Loading branch information
cemenson committed Jan 20, 2021
1 parent 4ba4b81 commit 4a30bb1
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function createUsagePlanResource(that, name) {
}
return accum;
}, {});
if (Object.keys(quotaProperties).length) {
if (Object.keys(throttleProperties).length) {
_.merge(template, {
Properties: {
Throttle: _.merge(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,54 +332,70 @@ describe('UsagePlan', () => {
},
};

it('Should have values for throttle', () => {
it('Should have values for throttle', async () => {
serverlessConfigurationExtension.provider.apiGateway = { usagePlan: { throttle } };
return runServerless({
const { cfTemplate } = await runServerless({
fixture: 'apiGateway',
configExt: serverlessConfigurationExtension,
cliArgs: ['package'],
}).then(({ cfTemplate }) => {
const cfResources = cfTemplate.Resources;

expect(cfResources.ApiGatewayUsagePlan.Properties.Throttle.BurstLimit).to.be.equal(
burstLimit
);
expect(cfResources.ApiGatewayUsagePlan.Properties.Throttle.RateLimit).to.be.equal(rateLimit);
});

expect(cfTemplate.Resources.ApiGatewayUsagePlan.Properties.Throttle.BurstLimit).to.be.equal(
burstLimit
);
expect(cfTemplate.Resources.ApiGatewayUsagePlan.Properties.Throttle.RateLimit).to.be.equal(
rateLimit
);
});

it('Should have values for quota', () => {
it('Should have values for quota', async () => {
serverlessConfigurationExtension.provider.apiGateway = { usagePlan: { quota } };
return runServerless({
const { cfTemplate } = await runServerless({
fixture: 'apiGateway',
configExt: serverlessConfigurationExtension,
cliArgs: ['package'],
}).then(({ cfTemplate }) => {
const cfResources = cfTemplate.Resources;
});

expect(cfResources.ApiGatewayUsagePlan.Properties.Quota.Limit).to.be.equal(limit);
expect(cfResources.ApiGatewayUsagePlan.Properties.Quota.Offset).to.be.equal(offset);
expect(cfResources.ApiGatewayUsagePlan.Properties.Quota.Period).to.be.equal(period);
expect(cfTemplate.Resources.ApiGatewayUsagePlan.Properties.Quota.Limit).to.be.equal(limit);
expect(cfTemplate.Resources.ApiGatewayUsagePlan.Properties.Quota.Offset).to.be.equal(offset);
expect(cfTemplate.Resources.ApiGatewayUsagePlan.Properties.Quota.Period).to.be.equal(period);
});

it('Should have values for throttle and not quota', async () => {
serverlessConfigurationExtension.provider.apiGateway = { usagePlan: { throttle } };
const { cfTemplate } = await runServerless({
fixture: 'apiGateway',
configExt: serverlessConfigurationExtension,
cliArgs: ['package'],
});

expect(cfTemplate.Resources.ApiGatewayUsagePlan.Properties.Throttle.BurstLimit).to.be.equal(
burstLimit
);
expect(cfTemplate.Resources.ApiGatewayUsagePlan.Properties.Throttle.RateLimit).to.be.equal(
rateLimit
);

expect(cfTemplate.Resources.ApiGatewayUsagePlan.Properties).to.not.have.property('quota');
});

it('Should have values for quota and throttle', () => {
it('Should have values for quota and throttle', async () => {
serverlessConfigurationExtension.provider.apiGateway = { usagePlan: { throttle, quota } };
return runServerless({
const { cfTemplate } = await runServerless({
fixture: 'apiGateway',
configExt: serverlessConfigurationExtension,
cliArgs: ['package'],
}).then(({ cfTemplate }) => {
const cfResources = cfTemplate.Resources;
});

expect(cfResources.ApiGatewayUsagePlan.Properties.Throttle.BurstLimit).to.be.equal(
burstLimit
);
expect(cfResources.ApiGatewayUsagePlan.Properties.Throttle.RateLimit).to.be.equal(rateLimit);
expect(cfTemplate.Resources.ApiGatewayUsagePlan.Properties.Throttle.BurstLimit).to.be.equal(
burstLimit
);
expect(cfTemplate.Resources.ApiGatewayUsagePlan.Properties.Throttle.RateLimit).to.be.equal(
rateLimit
);

expect(cfResources.ApiGatewayUsagePlan.Properties.Quota.Limit).to.be.equal(limit);
expect(cfResources.ApiGatewayUsagePlan.Properties.Quota.Offset).to.be.equal(offset);
expect(cfResources.ApiGatewayUsagePlan.Properties.Quota.Period).to.be.equal(period);
});
expect(cfTemplate.Resources.ApiGatewayUsagePlan.Properties.Quota.Limit).to.be.equal(limit);
expect(cfTemplate.Resources.ApiGatewayUsagePlan.Properties.Quota.Offset).to.be.equal(offset);
expect(cfTemplate.Resources.ApiGatewayUsagePlan.Properties.Quota.Period).to.be.equal(period);
});
});

0 comments on commit 4a30bb1

Please sign in to comment.