Skip to content

Commit

Permalink
fix(AWS API Gateway): Ensure shouldStartNameWithService support
Browse files Browse the repository at this point in the history
  • Loading branch information
vicary committed Nov 8, 2021
1 parent 723927f commit e8c8d25
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
Expand Up @@ -150,7 +150,7 @@ async function resolveRestApiId() {
}
const apiName = apiGatewayResource
? apiGatewayResource.Properties.Name
: provider.apiName || `${this.options.stage}-${this.state.service.service}`;
: provider.naming.getApiGatewayName();
const resolveFromAws = (position) =>
this.provider
.request('APIGateway', 'getRestApis', { position, limit: 500 })
Expand Down
Expand Up @@ -13,6 +13,7 @@ const {
defaultApiGatewayLogLevel,
} = require('../../../../../../../../../../../lib/plugins/aws/package/compile/events/apiGateway/lib/hack/updateStage');
const runServerless = require('../../../../../../../../../../utils/run-serverless');
const fixtures = require('../../../../../../../../../../fixtures/programmatic');

chai.use(require('sinon-chai'));
chai.use(require('chai-as-promised'));
Expand Down Expand Up @@ -811,4 +812,66 @@ describe('test/unit/lib/plugins/aws/package/compile/events/apiGateway/lib/hack/u
expect(untagResourceStub).to.have.been.calledOnce;
expect(untagResourceStub.args[0][0].tagKeys).to.deep.equal(['keytoremove']);
});

it('should deploys shouldStartNameWithService without apiName', async () => {
const { serviceConfig, servicePath, updateConfig } = await fixtures.setup('apiGateway');
const getDeploymentsStub = sinon.stub().returns({ items: [{ id: 'deployment-id' }] });
const stage = 'dev';

await updateConfig({
provider: {
apiGateway: {
shouldStartNameWithService: true,
},
stackTags: { key: 'value' },
},
});

await runServerless({
command: 'deploy',
cwd: servicePath,
options: { stage },
lastLifecycleHookName: 'after:deploy:deploy',
awsRequestStubMap: {
APIGateway: {
createStage: {},
getDeployments: getDeploymentsStub,
getRestApis: { items: [{ id: 'api-id', name: `${serviceConfig.service}-${stage}` }] },
tagResource: {},
},
CloudFormation: {
describeStacks: { Stacks: [{}] },
describeStackEvents: {
StackEvents: [
{
ResourceStatus: 'UPDATE_COMPLETE',
ResourceType: 'AWS::CloudFormation::Stack',
},
],
},
describeStackResource: {
StackResourceDetail: { PhysicalResourceId: 'deployment-bucket' },
},
listStackResources: {},
validateTemplate: {},
updateStack: {},
},
S3: {
listObjectsV2: {},
upload: {},
},
STS: {
getCallerIdentity: {
ResponseMetadata: { RequestId: 'ffffffff-ffff-ffff-ffff-ffffffffffff' },
UserId: 'XXXXXXXXXXXXXXXXXXXXX',
Account: '999999999999',
Arn: 'arn:aws-us-gov:iam::999999999999:user/test',
},
},
},
});

expect(getDeploymentsStub).to.have.been.calledOnce;
expect(getDeploymentsStub.args[0][0].restApiId).to.equal('api-id');
});
});

0 comments on commit e8c8d25

Please sign in to comment.