Skip to content

Commit

Permalink
Added unit test for configuration change
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Schmid committed Dec 1, 2017
1 parent 54e10ce commit 57f0561
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions lib/plugins/aws/package/compile/functions/index.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const _ = require('lodash');
const path = require('path');
const chai = require('chai');
const AwsProvider = require('../../../provider/awsProvider');
Expand Down Expand Up @@ -1622,6 +1623,72 @@ describe('AwsCompileFunctions', () => {
});
});

it('should create a new version object if only the configuration changed', () => {
awsCompileFunctions.serverless.service.functions = {
func: {
handler: 'func.function.handler',
},
anotherFunc: {
handler: 'anotherFunc.function.handler',
},
};

const expectedOutputs = {
FuncLambdaFunctionQualifiedArn: {
Description: 'Current Lambda function version',
Value: { Ref: 'FuncLambdaVersionl6Rjpaz0gycgsEDI51sLed039fH2uR4W8Q2IW8cNo' },
},
AnotherFuncLambdaFunctionQualifiedArn: {
Description: 'Current Lambda function version',
Value: {
Ref: 'AnotherFuncLambdaVersion6JZQneYqP4bC0Z3ywMc3XJPyECHK4RMGhpv8iis4E',
},
},
};

return expect(awsCompileFunctions.compileFunctions()).to.be.fulfilled
.then(() => {
expect(
awsCompileFunctions.serverless.service.provider.compiledCloudFormationTemplate
.Outputs
).to.deep.equal(
expectedOutputs
);

// Change configuration
awsCompileFunctions.serverless.service.provider.compiledCloudFormationTemplate = {
Resources: {},
Outputs: {},
};

_.set(
awsCompileFunctions,
'serverless.service.functions.func.environment.MY_ENV_VAR',
'myvalue'
);

return expect(awsCompileFunctions.compileFunctions()).to.be.fulfilled;
})
.then(() => {
// Expect different version hash
_.set(
expectedOutputs,
'FuncLambdaFunctionQualifiedArn',
{
Description: 'Current Lambda function version',
Value: { Ref: 'FuncLambdaVersiona6VymfU25aF6eS2qysm7sHqPyy8RqYUzoTvDeBrrBA' },
}
);

expect(
awsCompileFunctions.serverless.service.provider.compiledCloudFormationTemplate
.Outputs
).to.deep.equal(
expectedOutputs
);
});
});

it('should include description under version too if function is specified', () => {
awsCompileFunctions.serverless.service.functions = {
func: {
Expand Down

0 comments on commit 57f0561

Please sign in to comment.