1.0.0 • Published 10 months ago

@janiscommerce/aws-listener-test v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
10 months ago

aws-listener-test

Build Status Coverage Status npm version

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 receives sinon as the first argument.
  • after: <function> A function to be called after this test case is executed. It receives sinon 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);
		}
	}
]);
1.0.0

10 months ago

0.1.0

4 years ago