Skip to content

Commit

Permalink
Added unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Schmid committed May 29, 2017
1 parent 06bbfed commit 5756f32
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions test/stackops/init.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
'use strict';
/**
* Unit tests for initialization.
*/

const getInstalledPath = require('get-installed-path');
const BbPromise = require('bluebird');
const chai = require('chai');
const sinon = require('sinon');
const AWSAlias = require('../../index');

const serverlessPath = getInstalledPath.sync('serverless', { local: true });
const AwsProvider = require(`${serverlessPath}/lib/plugins/aws/provider/awsProvider`);
const Serverless = require(`${serverlessPath}/lib/Serverless`);

chai.use(require('chai-as-promised'));
chai.use(require('sinon-chai'));
const expect = chai.expect;

describe('SNS Events', () => {
let serverless;
let options;
let awsAlias;
// Sinon and stubs for SLS CF access
let sandbox;
let logStub;

before(() => {
sandbox = sinon.sandbox.create();
});

beforeEach(() => {
options = {
alias: 'myAlias',
stage: 'myStage',
region: 'us-east-1',
};
serverless = new Serverless(options);
serverless.setProvider('aws', new AwsProvider(serverless));
serverless.cli = new serverless.classes.CLI(serverless);
serverless.service.service = 'testService';
serverless.service.provider.compiledCloudFormationAliasTemplate = {};
awsAlias = new AWSAlias(serverless, options);

// Disable logging
logStub = sandbox.stub(serverless.cli, 'log');
logStub.returns();
});

afterEach(() => {
sandbox.restore();
});

describe('#aliasInit()', () => {
it('should set alias flags', () => {
serverless.service.provider.compiledCloudFormationTemplate = require('../data/sls-stack-1.json');
const aliasStack = serverless.service.provider.compiledCloudFormationAliasTemplate = require('../data/alias-stack-1.json');
return expect(awsAlias.aliasInit({}, [], {})).to.be.fulfilled
.then(() => BbPromise.all([
expect(aliasStack).to.have.property('Outputs')
.that.has.property('AliasFlags')
.that.deep.equals({
Description: 'Alias flags.',
Value: { hasRole: false }
})
]));
});
});
});

0 comments on commit 5756f32

Please sign in to comment.