'use strict'; const AwsDeploy = require('../index'); const Serverless = require('../../../../Serverless'); const expect = require('chai').expect; const BbPromise = require('bluebird'); const sinon = require('sinon'); describe('AwsDeploy', () => { const serverless = new Serverless(); const options = { stage: 'dev', region: 'us-east-1', }; const awsDeploy = new AwsDeploy(serverless, options); awsDeploy.serverless.cli = new serverless.classes.CLI(); describe('#constructor()', () => { it('should have hooks', () => expect(awsDeploy.hooks).to.be.not.empty); it('should set the provider variable to "aws"', () => expect(awsDeploy.provider) .to.equal('aws')); it('should run "before:deploy:initialize" hook promise chain in order', () => { const validateStub = sinon .stub(awsDeploy, 'validate').returns(BbPromise.resolve()); return awsDeploy.hooks['before:deploy:initialize']().then(() => { expect(validateStub.calledOnce).to.be.equal(true); awsDeploy.validate.restore(); }); }); it('should run "deploy:initialize" hook promise chain in order', () => { const initializeResourcesStub = sinon .stub(awsDeploy, 'initializeResources').returns(BbPromise.resolve()); return awsDeploy.hooks['deploy:initialize']().then(() => { expect(initializeResourcesStub.calledOnce).to.be.equal(true); awsDeploy.initializeResources.restore(); }); }); it('should run "deploy:setupProviderConfiguration" hook promise chain in order', () => { const createStackStub = sinon .stub(awsDeploy, 'createStack').returns(BbPromise.resolve()); return awsDeploy.hooks['deploy:setupProviderConfiguration']().then(() => { expect(createStackStub.calledOnce).to.be.equal(true); awsDeploy.createStack.restore(); }); }); it('should run "deploy:deploy" promise chain in order', () => { const uploadDeploymentPackage = sinon .stub(awsDeploy, 'uploadDeploymentPackage').returns(BbPromise.resolve()); const deployFunctionsStub = sinon .stub(awsDeploy, 'deployFunctions').returns(BbPromise.resolve()); const updateStackStub = sinon .stub(awsDeploy, 'updateStack').returns(BbPromise.resolve()); return awsDeploy.hooks['deploy:deploy']().then(() => { expect(uploadDeploymentPackage.calledOnce).to.be.equal(true); expect(deployFunctionsStub.calledAfter(uploadDeploymentPackage)).to.be.equal(true); expect(updateStackStub.calledAfter(deployFunctionsStub)).to.be.equal(true); awsDeploy.uploadDeploymentPackage.restore(); awsDeploy.deployFunctions.restore(); awsDeploy.updateStack.restore(); }); }); }); });