Fix AwsInvoke tests

This commit is contained in:
Philipp Muens 2016-06-20 15:39:47 +02:00
parent bd223ebdbb
commit b5f3e6a53b

View File

@ -7,11 +7,15 @@ const os = require('os');
const AwsInvoke = require('../');
const Serverless = require('../../../../Serverless');
const BbPromise = require('bluebird');
const AWS = require('aws-sdk');
describe('AwsInvoke', () => {
const serverless = new Serverless();
const awsInvoke = new AwsInvoke(serverless);
const options = {
stage: 'dev',
region: 'us-east-1',
function: 'hello',
};
const awsInvoke = new AwsInvoke(serverless, options);
describe('#constructor()', () => {
it('should have hooks', () => expect(awsInvoke.hooks).to.be.not.empty);
@ -45,7 +49,7 @@ describe('AwsInvoke', () => {
dev: {
vars: {},
regions: {
aws_useast1: {
'us-east-1': {
vars: {},
},
},
@ -57,17 +61,8 @@ describe('AwsInvoke', () => {
handler: true,
},
};
awsInvoke.options = {
stage: 'dev',
region: 'us-east-1',
function: 'hello',
};
});
it('it should resolve if all config is valid', () => awsInvoke.validate()
.then(() => expect(typeof awsInvoke.Lambda).to.not.be.equal('undefined'))
);
it('it should parse file if file path is provided', () => {
serverless.config.servicePath = path.join(os.tmpdir(), (new Date).getTime().toString());
const data = {
@ -104,24 +99,23 @@ describe('AwsInvoke', () => {
describe('#invoke()', () => {
let invokeStub;
beforeEach(() => {
awsInvoke.Lambda = new AWS.Lambda({ region: 'us-east-1' });
BbPromise.promisifyAll(awsInvoke.Lambda, { suffix: 'Promised' });
invokeStub = sinon.stub(awsInvoke.sdk, 'request').
returns(BbPromise.resolve());
awsInvoke.serverless.service.service = 'new-service';
awsInvoke.options = {
function: 'hello',
};
invokeStub = sinon.stub(awsInvoke.Lambda, 'invokePromised').returns(BbPromise.resolve());
});
it('should invoke with correct params', () => awsInvoke.invoke()
.then(() => {
expect(invokeStub.calledOnce).to.be.equal(true);
expect(invokeStub.args[0][0].FunctionName).to.be.equal('new-service-hello');
expect(invokeStub.args[0][0].InvocationType).to.be.equal('RequestResponse');
expect(invokeStub.args[0][0].LogType).to.be.equal('None');
expect(typeof invokeStub.args[0][0].Payload).to.not.be.equal('undefined');
awsInvoke.Lambda.invokePromised.restore();
expect(invokeStub.calledWith(awsInvoke.options.stage, awsInvoke.options.region));
expect(invokeStub.args[0][2].FunctionName).to.be.equal('new-service-hello');
expect(invokeStub.args[0][2].InvocationType).to.be.equal('RequestResponse');
expect(invokeStub.args[0][2].LogType).to.be.equal('None');
expect(typeof invokeStub.args[0][2].Payload).to.not.be.equal('undefined');
awsInvoke.sdk.request.restore();
})
);
@ -130,11 +124,12 @@ describe('AwsInvoke', () => {
return awsInvoke.invoke().then(() => {
expect(invokeStub.calledOnce).to.be.equal(true);
expect(invokeStub.args[0][0].FunctionName).to.be.equal('new-service-hello');
expect(invokeStub.args[0][0].InvocationType).to.be.equal('RequestResponse');
expect(invokeStub.args[0][0].LogType).to.be.equal('Tail');
expect(typeof invokeStub.args[0][0].Payload).to.not.be.equal('undefined');
awsInvoke.Lambda.invokePromised.restore();
expect(invokeStub.calledWith(awsInvoke.options.stage, awsInvoke.options.region));
expect(invokeStub.args[0][2].FunctionName).to.be.equal('new-service-hello');
expect(invokeStub.args[0][2].InvocationType).to.be.equal('RequestResponse');
expect(invokeStub.args[0][2].LogType).to.be.equal('Tail');
expect(typeof invokeStub.args[0][2].Payload).to.not.be.equal('undefined');
awsInvoke.sdk.request.restore();
});
});
@ -143,11 +138,12 @@ describe('AwsInvoke', () => {
return awsInvoke.invoke().then(() => {
expect(invokeStub.calledOnce).to.be.equal(true);
expect(invokeStub.args[0][0].FunctionName).to.be.equal('new-service-hello');
expect(invokeStub.args[0][0].InvocationType).to.be.equal('OtherType');
expect(invokeStub.args[0][0].LogType).to.be.equal('None');
expect(typeof invokeStub.args[0][0].Payload).to.not.be.equal('undefined');
awsInvoke.Lambda.invokePromised.restore();
expect(invokeStub.calledWith(awsInvoke.options.stage, awsInvoke.options.region));
expect(invokeStub.args[0][2].FunctionName).to.be.equal('new-service-hello');
expect(invokeStub.args[0][2].InvocationType).to.be.equal('OtherType');
expect(invokeStub.args[0][2].LogType).to.be.equal('None');
expect(typeof invokeStub.args[0][2].Payload).to.not.be.equal('undefined');
awsInvoke.sdk.request.restore();
});
});
});