fix(AWS API Gateway): Fix handling of usagePlan array

Improves leaky logic introduces with https://github.com/serverless/serverless/pull/5982
Exposed by regression introduced with https://github.com/serverless/serverless/pull/7827
This commit is contained in:
Mariusz Nowak 2020-06-16 16:10:45 +02:00 committed by Mariusz Nowak
parent 5d165ba2db
commit 85cc4476b3
2 changed files with 7 additions and 1 deletions

View File

@ -50,8 +50,9 @@ module.exports = {
const name = Object.keys(apiKeyDefinition)[0];
if (
_.isObject(apiKeyDefinition) &&
Array.isArray(this.serverless.service.provider.usagePlan) &&
_.flatten(
(this.serverless.service.provider.usagePlan || []).map(item => Object.keys(item))
this.serverless.service.provider.usagePlan.map(item => Object.keys(item))
).includes(name)
) {
keyNumber = 0;

View File

@ -39,6 +39,11 @@ describe('#compileApiKeys()', () => {
},
];
// Added purely to test https://github.com/serverless/serverless/issues/7844 regression
awsCompileApigEvents.serverless.service.provider.usagePlan = {
quota: { limit: 5000 },
};
return awsCompileApigEvents.compileApiKeys().then(() => {
const expectedApiKeys = [
{