Split test into granular cases.

This commit is contained in:
exoego 2019-04-17 11:55:39 +09:00
parent 7383281a6b
commit dd8b60675c

View File

@ -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' },
],
},
});