2016-06-15 12:25:44 +02:00

43 lines
1.6 KiB
JavaScript

'use strict';
const expect = require('chai').expect;
const AwsCompileApigEvents = require('../awsCompileApigEvents');
const Serverless = require('../../../Serverless');
describe('#awsCompilePermissions()', () => {
let serverless;
let awsCompileApigEvents;
beforeEach(() => {
serverless = new Serverless();
serverless.init();
serverless.service.resources = { aws: { Resources: {} } };
awsCompileApigEvents = new AwsCompileApigEvents(serverless);
awsCompileApigEvents.resourcePaths = ['foo/bar', 'bar/foo'];
awsCompileApigEvents.serverless.service.functions = {
hello: {
events: {
aws: {
http_endpoints: {
post: 'foo/bar',
get: 'bar/foo',
},
},
},
},
};
});
it('should compile to the correct CF resources', () => awsCompileApigEvents
.compilePermissions().then(() => {
expect(awsCompileApigEvents.serverless.service.resources.aws.Resources
.ApigPermissionpost0.Properties.FunctionName['Fn::GetAtt'][0]).to.equal('hello');
expect(awsCompileApigEvents.serverless.service.resources.aws.Resources
.ApigPermissionpost0.Properties.SourceArn['Fn::GetAtt'][0]).to.equal('postMethodApigEvent0');
expect(awsCompileApigEvents.serverless.service.resources.aws.Resources
.ApigPermissionget1.Properties.FunctionName['Fn::GetAtt'][0]).to.equal('hello');
expect(awsCompileApigEvents.serverless.service.resources.aws.Resources
.ApigPermissionget1.Properties.SourceArn['Fn::GetAtt'][0]).to.equal('getMethodApigEvent1');
}));
});