@janiscommerce/aws-listener-test
v1.0.0
Published
A package for testing AWS Listeners developed with @janiscommerce/aws-listeners
Downloads
3
Readme
aws-listener-test
A package for testing AWS Listeners developed with @janiscommerce/aws-listeners
Installation
npm install @janiscommerce/aws-listener-test
Rule
A rule is an object that defines a test case. It has the following properties:
description
: <string> Required. The test case description.only
: <boolean> If it's set to true, only this rule will be executed. Useful to debug when a test fails.event
: <object|string> Required. The AWS event to test, or you can use this string options:SNS
,S3
,SQS
.before
: <function> A function to be called before this test case is executed. It receivessinon
as the first argument.after
: <function> A function to be called after this test case is executed. It receivessinon
as the first argument.printResponse
: <boolean> Indicates if this test case response should be printed in the console (good for debugging).
Examples
const AwsListenerTest = require('@janiscommerce/aws-listener-test');
const MyServerlessHandler = require('./handler');
const MyModel = require('./model');
AwsListenerTest(MyServerlessHandler, [
{
description: 'It should return a 200 and do nothing',
event: 'SNS'
},
{
description: 'It should return a 200 and do nothing',
event: 'S3'
},
{
description: 'It should return a 200 and do nothing',
event: 'SQS'
},
{
description: 'It fail with a 500 status code if event is errorHappened',
event: {
// the complete AWS event object
}
},
{
description: 'It should update a record and return a 200',
event: 'SNS',
before: sinon => {
sinon.stub(MyModel.prototype, 'update')
.returns(true);
},
after: sinon => {
sinon.assert.calledOnce(MyModel.prototype.update);
}
}
]);