UNPKG

@incdevco/framework

Version:
136 lines (101 loc) 2.57 kB
var Expect = require('chai').expect; var fs = require('fs'); var Mock = require('../../mock'); var Prompt = require('../../prompt'); var Utilities = require('../../utilities'); var Plugin = require('./index'); describe('gulp create-update-cloud-formation-stack', function () { 'use strict' var changeSetName, config, expected, mock, params, stackName; beforeEach(function () { config = { cf: {} }; expected = 'expected'; mock = new Mock(); params = {}; stackName = 'stack-name'; changeSetName = stackName + '-moment'; }); afterEach(function () { mock.restore(); }); it('should create stack when no stack exists', function (done) { var mocked = mock.mock(config.cf); mocked .expect('describeStacks') .with({ StackName: stackName }) .willReturnAwsPromiseResolve({ Stacks: [] }); mocked .expect('createChangeSet') .with(params) .willReturnAwsPromiseResolve(true); var m = {}; mock.mock(Utilities) .expect('getMoment') .willReturn(m); mock.mock(m) .expect('format') .with('MM-DD-YYYY-HH-mm-ss') .willReturn('moment'); mocked .expect('describeChangeSet') .with({ ChangeSetName: changeSetName, NextToken: undefined, StackName: stackName }) .willReturnAwsPromiseResolve({ Status: 'CREATED' }); mock.mock(fs) .expect('writeFileSync') .with('dist/cf/stack-name-moment.json', JSON.stringify({ Status: 'CREATED' }, null, 2), 'utf8') .willReturn(true); mock.mock(Prompt) .expect('get') .with({ properties: { execute_change_set: { message: 'Do you want to execute this change set? y/n' } } }) .willResolve({ execute_change_set: 'y' }); mocked .expect('executeChangeSet') .with({ ChangeSetName: changeSetName, StackName: stackName }) .willReturnAwsPromiseResolve(true); expected = { StackName: stackName, StackStatus: 'CREATE_COMPLETE' }; mocked .expect('describeStacks') .with({ StackName: stackName }) .willReturnAwsPromiseResolve({ Stacks: [ expected ] }); Plugin(stackName, params, config) .then(function (result) { Expect(result).to.deep.equal(expected, 'result'); return mock.done(done); }) .catch(done); }); });