UNPKG

@incdevco/framework

Version:
100 lines (68 loc) 2.21 kB
var Expect = require('chai').expect; var Lambda = require('./index'); var Sinon = require('sinon'); describe('lambda action-producer', function () { var lambda; var context, event, record, sandbox; beforeEach(function () { context = {}; record = { "EventVersion": "1.0", "EventSubscriptionArn": "arn:aws:sns:EXAMPLE", "EventSource": "aws:sns", "Sns": { "SignatureVersion": "1", "Timestamp": "1970-01-01T00:00:00.000Z", "Signature": "EXAMPLE", "SigningCertUrl": "EXAMPLE", "MessageId": "95df01b4-ee98-5cb9-9903-4c221d41eb5e", "Message": "Hello from SNS!", "MessageAttributes": { "Test": { "Type": "String", "Value": "TestString" }, "TestBinary": { "Type": "Binary", "Value": "TestBinary" } }, "Type": "Notification", "UnsubscribeUrl": "EXAMPLE", "TopicArn": "arn:aws:sns:EXAMPLE", "Subject": "TestInvoke" } }; event = { "Records": [ record ] }; lambda = new Lambda(); sandbox = Sinon.sandbox.create(); sandbox.stub(lambda, 'log'); }); afterEach(function () { sandbox.verifyAndRestore(); }); describe('handler', function() { it('should call handleRecord with event, context and record in that order', function (done) { sandbox.mock(lambda) .expects('handleRecord') .withArgs(event, context, record) .returns(Promise.resolve(true)); lambda.handler(event, context, done); }); }); describe('handleRecord', function() { it('should catch invalid JSON', function (done) { record.Sns.Message = 'Invalid' lambda.handleRecord(event, context, record) .then(function (result) { Expect(result).to.equal(false, 'result'); done(); }) .catch(done); }); }); });