4.0.0 • Published 1 year ago

@dustfoundation/serverless-testing v4.0.0

Weekly downloads
-
License
-
Repository
github
Last release
1 year ago

@dustfoundation/serverless-testing

CI NPM Version Minimum Node.js Version

Library for testing serverless applications.

Installation

npm install --save @dustfoundation/serverless-testing

Features

Mock API Gateway Proxy Handler

import { mockAPIGatewayProxyHandler } from '@dustfoundation/serverless-testing';
import { expect } from 'chai';

describe('simple test', () => {
  it('GIVEN valid data THEN 201', async () => {
    // mockAPIGatewayProxyHandler.execute<T> - T is optional generic that describes response body type
    const { statusCode, body } = await mockAPIGatewayProxyHandler(handler)
      .execute<{ users: string[] }>({
        event: {
          pathParameters: { field: 'some' },
          queryStringParameters: { field: 'some' },
          body: JSON.stringify({ field: 'some' }),
          headers: { field: 'some' },
          requestContext: {
            authorizer: {
              id: 'YourCustomAuthorizerId',
              groups: ['YourCustomAuthorizerGroup1', 'YourCustomAuthorizerGroup2'].join(';'),
            },
          },
        },
        responseToJson: true,
      });

    expect(statusCode).eql(201);
    expect(body.users).lengthOf(5);
  });
});

Mock DynamoDB Stream Handler

import { mockDDBStreamHandler } from '@dustfoundation/serverless-testing';
import { expect } from 'chai';

describe('simple test', () => {
  it('GIVEN valid data THEN success', async () => {
    await mockDDBStreamHandler(handler).execute({
      records: [], // DynamoDB Stream Records
    });

    // You can test handler with .commandCalls(), etc...
  });
});

Mock SNS Handler

import { mockSNSHandler } from '@dustfoundation/serverless-testing';
import { expect } from 'chai';

describe('simple test', () => {
  it('GIVEN valid data THEN success', async () => {
    await mockSNSHandler(handler).execute({
      records: [], // SNS Records
    });

    // You can test handler with .commandCalls(), etc...
  });
});

Mock SQS Handler

import { mockSQSHandler } from '@dustfoundation/serverless-testing';
import { expect } from 'chai';

describe('simple test', () => {
  it('GIVEN valid data THEN success', async () => {
    await mockSQSHandler(handler).execute({
      records: [], // SQS Records
    });

    // You can test handler with .commandCalls(), etc...
  });
});
4.0.0-beta.1

1 year ago

4.0.0-beta.0

1 year ago

4.0.0

1 year ago

3.1.1

1 year ago

2.3.0

2 years ago

2.2.0

2 years ago

2.1.0

2 years ago

2.0.0

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago