2017-04-06 18:28:59 +07:00

88 lines
3.1 KiB
JavaScript

'use strict';
const expect = require('chai').expect;
const sinon = require('sinon');
const AwsProvider = require('../../../../provider/awsProvider');
const AwsCompileApigEvents = require('./index');
const Serverless = require('../../../../../../Serverless');
describe('AwsCompileApigEvents', () => {
let awsCompileApigEvents;
beforeEach(() => {
const serverless = new Serverless();
serverless.service.environment = {
vars: {},
stages: {
dev: {
vars: {},
regions: {
'us-east-1': {
vars: {},
},
},
},
},
};
const options = {
stage: 'dev',
region: 'us-east-1',
};
serverless.setProvider('aws', new AwsProvider(serverless));
awsCompileApigEvents = new AwsCompileApigEvents(serverless, options);
});
describe('#constructor()', () => {
it('should have hooks', () => expect(awsCompileApigEvents.hooks).to.be.not.empty);
it('should set the provider variable to be an instanceof AwsProvider', () =>
expect(awsCompileApigEvents.provider).to.be.instanceof(AwsProvider));
it('should run promise chain in order', () => {
const validateStub = sinon
.stub(awsCompileApigEvents, 'validate').returns({
events: [
{
functionName: 'first',
http: {
path: 'users',
method: 'POST',
},
},
],
});
const compileRestApiStub = sinon
.stub(awsCompileApigEvents, 'compileRestApi').resolves();
const compileResourcesStub = sinon
.stub(awsCompileApigEvents, 'compileResources').resolves();
const compileMethodsStub = sinon
.stub(awsCompileApigEvents, 'compileMethods').resolves();
const compileDeploymentStub = sinon
.stub(awsCompileApigEvents, 'compileDeployment').resolves();
const compilePermissionsStub = sinon
.stub(awsCompileApigEvents, 'compilePermissions').resolves();
return awsCompileApigEvents.hooks['package:compileEvents']().then(() => {
expect(validateStub.calledOnce).to.be.equal(true);
expect(compileRestApiStub.calledAfter(validateStub)).to.be.equal(true);
expect(compileResourcesStub.calledAfter(compileRestApiStub)).to.be.equal(true);
expect(compileMethodsStub.calledAfter(compileResourcesStub)).to.be.equal(true);
expect(compileDeploymentStub.calledAfter(compileMethodsStub)).to.be.equal(true);
expect(compilePermissionsStub.calledAfter(compileDeploymentStub)).to.be.equal(true);
awsCompileApigEvents.validate.restore();
awsCompileApigEvents.compileRestApi.restore();
awsCompileApigEvents.compileResources.restore();
awsCompileApigEvents.compileMethods.restore();
awsCompileApigEvents.compileDeployment.restore();
awsCompileApigEvents.compilePermissions.restore();
});
});
it('should resolve if no functions are given', () => {
awsCompileApigEvents.serverless.service.functions = {};
return awsCompileApigEvents.hooks['package:compileEvents']();
});
});
});