diff --git a/lib/plugins/aws/package/compile/events/apiGateway/lib/stage.test.js b/lib/plugins/aws/package/compile/events/apiGateway/lib/stage.test.js index 2909eaf14..124f8a8d0 100644 --- a/lib/plugins/aws/package/compile/events/apiGateway/lib/stage.test.js +++ b/lib/plugins/aws/package/compile/events/apiGateway/lib/stage.test.js @@ -95,32 +95,97 @@ describe('#compileStage()', () => { }); describe('tags', () => { - it('should add tag from provider.stackTags and provider.tags', () => { + it('should create a dedicated stage resource if provider.stackTags is configured', () => { provider.stackTags = { - foo: 'bar', - }; - provider.tags = { - // override stackTags - foo: 'high-priority', + foo: '1', }; awsCompileApigEvents.compileStage().then(() => { - const template = awsCompileApigEvents.serverless.service.provider - .compiledCloudFormationTemplate; - const actual = template.Resources[stageLogicalId]; - expect(actual).to.deep.equal({ + const resources = awsCompileApigEvents.serverless.service.provider + .compiledCloudFormationTemplate.Resources; + expect(resources[awsCompileApigEvents.apiGatewayDeploymentLogicalId]).to.deep.equal({ + Properties: {}, + }); + + expect(resources[stageLogicalId]).to.deep.equal({ Type: 'AWS::ApiGateway::Stage', Properties: { - DeploymentId: { - Ref: awsCompileApigEvents.apiGatewayDeploymentLogicalId, - }, RestApiId: { Ref: awsCompileApigEvents.apiGatewayRestApiLogicalId, }, + DeploymentId: { + Ref: awsCompileApigEvents.apiGatewayDeploymentLogicalId, + }, StageName: stage, TracingEnabled: false, Tags: [ - { Key: 'foo', Value: 'high-priority' }, + { Key: 'foo', Value: '1' }, + ], + }, + }); + }); + }); + + it('should create a dedicated stage resource if provider.tags is configured', () => { + provider.tags = { + foo: '1', + }; + + awsCompileApigEvents.compileStage().then(() => { + const resources = awsCompileApigEvents.serverless.service.provider + .compiledCloudFormationTemplate.Resources; + expect(resources[awsCompileApigEvents.apiGatewayDeploymentLogicalId]).to.deep.equal({ + Properties: {}, + }); + + expect(resources[stageLogicalId]).to.deep.equal({ + Type: 'AWS::ApiGateway::Stage', + Properties: { + RestApiId: { + Ref: awsCompileApigEvents.apiGatewayRestApiLogicalId, + }, + DeploymentId: { + Ref: awsCompileApigEvents.apiGatewayDeploymentLogicalId, + }, + StageName: stage, + TracingEnabled: false, + Tags: [ + { Key: 'foo', Value: '1' }, + ], + }, + }); + }); + }); + + it('should override provider.stackTags by provider.tags', () => { + provider.stackTags = { + foo: 'from-stackTags', + bar: 'from-stackTags', + }; + provider.tags = { + foo: 'from-tags', + buz: 'from-tags', + }; + + awsCompileApigEvents.compileStage().then(() => { + const resources = awsCompileApigEvents.serverless.service.provider + .compiledCloudFormationTemplate.Resources; + + expect(resources[stageLogicalId]).to.deep.equal({ + Type: 'AWS::ApiGateway::Stage', + Properties: { + RestApiId: { + Ref: awsCompileApigEvents.apiGatewayRestApiLogicalId, + }, + DeploymentId: { + Ref: awsCompileApigEvents.apiGatewayDeploymentLogicalId, + }, + StageName: stage, + TracingEnabled: false, + Tags: [ + { Key: 'foo', Value: 'from-tags' }, + { Key: 'bar', Value: 'from-stackTags' }, + { Key: 'buz', Value: 'from-tags' }, ], }, });