Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lambda-test

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lambda-test

Simple Serverless tester, which works like this:

  • 2.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
14
decreased by-30%
Maintainers
1
Weekly downloads
 
Created
Source

Lambda test

Simple Serverless tester, which works like this:


const lambdaTest = require('lambda-test');
const { getById } = require('../../routes/users.js');

describe('GET /users/{id}', () => {

    it('should get user by id', async () => {
        const response = await lambdaTest(getById)
            .pathParameters({ id: 123 })
            .run();
    })
});

or much more sophisticated with Api Blueprint check


const assert = require('assert');
const { LambdaTest } = require('lambda-test');
const { updateById } = require('../../routes/users.js');

// in project root
const tester = new LambdaTest('./apiBlueprint.apib');

describe('UPDATE /users/{id}', () => {

    it('should get user by id', async () => {
        const response = await tester.test(updateById, '/users/{id}', 'UPDATE', 200)
            .pathParameters({ id: 123 })
            .queryStringParameters({ fields: 'name' })
            .headers({ Authorization: 'secret' })
            .body({ name: 'John Doe' })
            .verify();

        assert.equal(response.body.name, 'John Doe');
    });

});


API

Classes

LambdaTest
HandlerTester

LambdaTest

Kind: global class

new LambdaTest([blueprintFile])

ParamTypeDefaultDescription
[blueprintFile]stringnullapi blueprint

lambdaTest._getBlueprint() ⇒ ApiBlueprint

Kind: instance method of LambdaTest

lambdaTest.test(handler, [routeOrStatus], [httpMethod], [statusCode]) ⇒ HandlerTester

Create test and checks for status code

when first parameter is API path, response is checked against api blueprint

Kind: instance method of LambdaTest

ParamTypeDefaultDescription
handlerfunctionfunction to test
[routeOrStatus]number | string200route path for blueprint or status code
[httpMethod]stringnullhttp method to use
[statusCode]number | nullexpected status code

HandlerTester

Kind: global class

new HandlerTester(handler, [statusCode], [httpMethod], [route], [api])

ParamTypeDefault
handlerfunction
[statusCode]number | null
[httpMethod]string | nullnull
[route]string | nullnull
[api]ApiBlueprint | null

handlerTester.queryStringParameters(query) ⇒ this

Sets query string

Kind: instance method of HandlerTester

ParamTypeDefaultDescription
queryObject | nullthe query string

handlerTester.body(body) ⇒ this

Sets request body

Kind: instance method of HandlerTester

ParamTypeDefaultDescription
bodyObject | stringrequest body

handlerTester.headers(headers) ⇒ this

Set request headers

Kind: instance method of HandlerTester

ParamTypeDefault
headersObject | null

handlerTester.pathParameters(params) ⇒ this

Kind: instance method of HandlerTester

ParamTypeDefault
paramsObject | null

handlerTester.run() ⇒ Promise.<Object>

Send request

Kind: instance method of HandlerTester

handlerTester.verify() ⇒ Promise.<Object>

Send request

Kind: instance method of HandlerTester

Keywords

FAQs

Package last updated on 20 Jun 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc