From 58d7423fa06170e1c9bc8ae0954935f8e7554a69 Mon Sep 17 00:00:00 2001 From: Phillip Manwaring Date: Wed, 25 Nov 2020 22:47:37 -0500 Subject: [PATCH] update tests to match new testRequest logic --- CHANGELOG.md | 7 ++++ package-lock.json | 8 ++-- package.json | 4 +- src/api/v1/parser.test.ts | 62 +++++++++++++++---------------- src/api/v1/parser.ts | 21 ++++++----- src/api/v1/wrapper.test.ts | 58 ++++++++++++++--------------- src/api/v2-http/parser.test.ts | 66 ++++++++++++++++----------------- src/api/v2-http/parser.ts | 2 +- src/api/v2-http/wrapper.test.ts | 52 +++++++++++++------------- src/api/v2-http/wrapper.ts | 8 ++-- 10 files changed, 148 insertions(+), 140 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3743677..d7747ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html) +## [4.4.2]  (2020-11-25) + +### Fixed + +- Update calculation of `testRequest` prop on api signature based on headers + ## [4.4.1]  (2020-11-25) ### Changed @@ -342,6 +348,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/), - Update older libraries - Now publish from Git tags instead of master pushes +[4.4.2]: https://github.com/manwaring/lambda-wrapper/compare/v4.4.1...v4.4.2 [4.4.1]: https://github.com/manwaring/lambda-wrapper/compare/v4.4.0...v4.4.1 [4.4.0]: https://github.com/manwaring/lambda-wrapper/compare/v4.3.0...v4.4.0 [4.3.0]: https://github.com/manwaring/lambda-wrapper/compare/v4.2.0...v4.3.0 diff --git a/package-lock.json b/package-lock.json index 5d81914..28aa39c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@manwaring/lambda-wrapper", - "version": "4.4.1", + "version": "4.4.2", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -2269,9 +2269,9 @@ "dev": true }, "@types/node": { - "version": "14.14.9", - "resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.9.tgz", - "integrity": "sha512-JsoLXFppG62tWTklIoO4knA+oDTYsmqWxHRvd4lpmfQRNhX6osheUOWETP2jMoV/2bEHuMra8Pp3Dmo/stBFcw==", + "version": "14.14.10", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.10.tgz", + "integrity": "sha512-J32dgx2hw8vXrSbu4ZlVhn1Nm3GbeCFNw2FWL8S5QKucHGY0cyNwjdQdO+KMBZ4wpmC7KhLCiNsdk1RFRIYUQQ==", "dev": true }, "@types/normalize-package-data": { diff --git a/package.json b/package.json index 2370b6f..49e051a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@manwaring/lambda-wrapper", "description": "A lambda handler wrapper to abstract common functionality and provide useful defaults", - "version": "4.4.1", + "version": "4.4.2", "scripts": { "publish-please-dry-run": "publish-please --dry-run", "publish-please": "publish-please", @@ -23,7 +23,7 @@ "@types/aws-lambda": "^8.10.64", "@types/cfn-response": "^1.0.4", "@types/jest": "^26.0.15", - "@types/node": "^14.14.9", + "@types/node": "^14.14.10", "@typescript-eslint/eslint-plugin": "^4.8.2", "@typescript-eslint/parser": "^4.8.2", "aws-lambda": "^1.0.6", diff --git a/src/api/v1/parser.test.ts b/src/api/v1/parser.test.ts index 65a802d..8729df9 100644 --- a/src/api/v1/parser.test.ts +++ b/src/api/v1/parser.test.ts @@ -1,38 +1,38 @@ -import { stringify } from 'querystring'; -import { apiGatewayEvent } from 'serverless-plugin-test-helper'; -import { Request, Body } from './parser'; +import { stringify } from "querystring"; +import { apiGatewayEvent } from "serverless-plugin-test-helper"; +import { Request, Body } from "./parser"; -describe('Body parsing', () => { - it('Parses json body', () => { - const json = { hello: 'world' }; - const headers = { 'content-type': 'application/json' }; +describe("Body parsing", () => { + it("Parses json body", () => { + const json = { hello: "world" }; + const headers = { "content-type": "application/json" }; const body = new Body(JSON.stringify(json), headers).getParsedBody(); expect(body).toEqual(json); }); - it('Parses json body when charset is also defined in the content-type', () => { - const json = { hello: 'world' }; - const headers = { 'content-type': 'application/json;charset=UTF-8' }; + it("Parses json body when charset is also defined in the content-type", () => { + const json = { hello: "world" }; + const headers = { "content-type": "application/json;charset=UTF-8" }; const body = new Body(JSON.stringify(json), headers).getParsedBody(); expect(body).toEqual(json); }); - it('Parses form url encoded body', () => { - const form = { hello: 'world' }; - const headers = { 'content-type': 'application/x-www-form-urlencoded' }; + it("Parses form url encoded body", () => { + const form = { hello: "world" }; + const headers = { "content-type": "application/x-www-form-urlencoded" }; const body = new Body(stringify(form), headers).getParsedBody(); expect(body).toEqual(form); }); - it('Parses form url encoded body when charset is also defined in the content-type', () => { - const form = { hello: 'world' }; - const headers = { 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' }; + it("Parses form url encoded body when charset is also defined in the content-type", () => { + const form = { hello: "world" }; + const headers = { "content-type": "application/x-www-form-urlencoded;charset=UTF-8" }; const body = new Body(stringify(form), headers).getParsedBody(); expect(body).toEqual(form); }); it("Tries to parse body as JSON when content type isn't specified", () => { - const json = { hello: 'world' }; + const json = { hello: "world" }; const headers = undefined; const body = new Body(JSON.stringify(json), headers).getParsedBody(); expect(body).toEqual(json); @@ -40,33 +40,33 @@ describe('Body parsing', () => { it("Errors when encoding and content-type don't match", () => { const invalid = '2["test" : 123]4}{'; - const headers = { 'content-type': 'application/json' }; + const headers = { "content-type": "application/json" }; const body = new Body(invalid, headers).getParsedBody(); expect(body).toEqual(invalid); }); - it('Returns empty body when none given', () => { + it("Returns empty body when none given", () => { let empty; - const headers = { 'content-type': 'application/x-www-form-urlencoded' }; + const headers = { "content-type": "application/x-www-form-urlencoded" }; const body = new Body(empty, headers).getParsedBody(); expect(body).toEqual(empty); }); }); -describe('Request parsing', () => { - it('Gets all fields with optional parameters', () => { +describe("Request parsing", () => { + it("Gets all fields with optional parameters", () => { const event = apiGatewayEvent({ - body: JSON.stringify({ hello: 'world' }), - pathParameters: { proxy: 'not today' }, - queryStringParameters: { name: 'a test' }, - headers: { 'content-type': 'application/json', 'Test-Request': 'true' }, + body: JSON.stringify({ hello: "world" }), + pathParameters: { proxy: "not today" }, + queryStringParameters: { name: "a test" }, + headers: { "content-type": "application/json", "test-request": "true" }, }); const { body, path, query, auth, headers, testRequest } = new Request(event).getProperties(); - expect(body).toEqual({ hello: 'world' }); - expect(path).toEqual({ proxy: 'not today' }); - expect(query).toEqual({ name: 'a test' }); - expect(headers['content-type']).toEqual('application/json'); + expect(body).toEqual({ hello: "world" }); + expect(path).toEqual({ proxy: "not today" }); + expect(query).toEqual({ name: "a test" }); + expect(headers["content-type"]).toEqual("application/json"); expect(testRequest).toEqual(true); expect(auth).toBeTruthy(); }); @@ -87,7 +87,7 @@ describe('Request parsing', () => { expect(testRequest).toBeFalsy(); }); - it('Supports default values in method signature', () => { + it("Supports default values in method signature", () => { const event = apiGatewayEvent(); delete event.body; delete event.headers; diff --git a/src/api/v1/parser.ts b/src/api/v1/parser.ts index 92c9d4d..7ace5f2 100644 --- a/src/api/v1/parser.ts +++ b/src/api/v1/parser.ts @@ -1,8 +1,8 @@ -import { APIGatewayEvent } from 'aws-lambda'; -import { parse } from 'querystring'; -import { Metrics, logger } from '../../common'; +import { APIGatewayEvent } from "aws-lambda"; +import { parse } from "querystring"; +import { Metrics, logger } from "../../common"; -const metrics = new Metrics('API Gateway'); +const metrics = new Metrics("API Gateway"); export class Request { constructor(private event: APIGatewayEvent) {} @@ -15,7 +15,7 @@ export class Request { const auth = this.getAuth(); const headers = event.headers ? event.headers : undefined; const body = new Body(event.body, headers).getParsedBody(); - const TEST_REQUEST_HEADER = process.env.TEST_REQUEST_HEADER || 'Test-Request'; + const TEST_REQUEST_HEADER = process.env.TEST_REQUEST_HEADER || "test-request"; const testRequest = headers && headers[TEST_REQUEST_HEADER] ? JSON.parse(headers[TEST_REQUEST_HEADER]) : false; const parsed = { body, websocket, path, query, auth, headers, testRequest }; metrics.common(parsed, event); @@ -24,6 +24,7 @@ export class Request { private getAuth() { const authorizer = this.event?.requestContext?.authorizer; + // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore const httpApiAuth = this.event.auth; return authorizer ? authorizer : httpApiAuth; @@ -43,11 +44,11 @@ export class Body { } else if (this.isJSON(contentType)) { parsedBody = JSON.parse(this.body); } else { - logger.error('Content-Type header not found, attempting to parse as JSON'); + logger.error("Content-Type header not found, attempting to parse as JSON"); parsedBody = JSON.parse(this.body); } } catch (err) { - logger.error('Error parsing body, returning as-is', err, this.body); + logger.error("Error parsing body, returning as-is", err, this.body); parsedBody = this.body; } } @@ -56,15 +57,15 @@ export class Body { private getContentType(): string { return ( - this.headers && (this.headers['Content-Type'] || this.headers['CONTENT-TYPE'] || this.headers['content-type']) + this.headers && (this.headers["Content-Type"] || this.headers["CONTENT-TYPE"] || this.headers["content-type"]) ); } private isFormUrlEncoded(contentType?: string): boolean { - return contentType?.toUpperCase().includes('APPLICATION/X-WWW-FORM-URLENCODED'); + return contentType?.toUpperCase().includes("APPLICATION/X-WWW-FORM-URLENCODED"); } private isJSON(contentType: string): boolean { - return contentType?.toUpperCase().includes('APPLICATION/JSON'); + return contentType?.toUpperCase().includes("APPLICATION/JSON"); } } diff --git a/src/api/v1/wrapper.test.ts b/src/api/v1/wrapper.test.ts index 8cdd100..d702fc5 100644 --- a/src/api/v1/wrapper.test.ts +++ b/src/api/v1/wrapper.test.ts @@ -1,26 +1,26 @@ /* eslint-disable @typescript-eslint/no-empty-function */ -import { apiGatewayEvent } from 'serverless-plugin-test-helper'; -import { api, ApiSignature } from './wrapper'; +import { apiGatewayEvent } from "serverless-plugin-test-helper"; +import { api, ApiSignature } from "./wrapper"; -describe('API wrapper', () => { +describe("API wrapper", () => { const requestEvent = apiGatewayEvent({ - body: JSON.stringify({ hello: 'world' }), - pathParameters: { proxy: 'not today' }, - queryStringParameters: { name: 'a test' }, - headers: { 'content-type': 'application/json', 'Test-Request': 'true' }, + body: JSON.stringify({ hello: "world" }), + pathParameters: { proxy: "not today" }, + queryStringParameters: { name: "a test" }, + headers: { "content-type": "application/json", "test-request": "true" }, requestContext: { - connectionId: 'abc-123', + connectionId: "abc-123", }, }); const context = { callbackWaitsForEmptyEventLoop: false, - functionName: 'function-name', - functionVersion: '$LATEST', - invokedFunctionArn: 'arn:', - memoryLimitInMB: '128', - awsRequestId: 'request', - logGroupName: 'group', - logStreamName: 'stream', + functionName: "function-name", + functionVersion: "$LATEST", + invokedFunctionArn: "arn:", + memoryLimitInMB: "128", + awsRequestId: "request", + logGroupName: "group", + logStreamName: "stream", getRemainingTimeInMillis: () => 2, done: () => {}, fail: () => {}, @@ -28,7 +28,7 @@ describe('API wrapper', () => { }; const callback = jest.fn((err, result) => (err ? new Error(err) : result)); - it('Has expected properties and response functions', () => { + it("Has expected properties and response functions", () => { function customHandler({ event, websocket, @@ -47,11 +47,11 @@ describe('API wrapper', () => { custom, }: ApiSignature) { expect(event).toEqual(requestEvent); - expect(websocket.connectionId).toEqual('abc-123'); - expect(body).toEqual({ hello: 'world' }); - expect(path).toEqual({ proxy: 'not today' }); - expect(query).toEqual({ name: 'a test' }); - expect(headers['content-type']).toEqual('application/json'); + expect(websocket.connectionId).toEqual("abc-123"); + expect(body).toEqual({ hello: "world" }); + expect(path).toEqual({ proxy: "not today" }); + expect(query).toEqual({ name: "a test" }); + expect(headers["content-type"]).toEqual("application/json"); expect(testRequest).toEqual(true); expect(auth).toBeTruthy(); expect(success).toBeInstanceOf(Function); @@ -61,12 +61,12 @@ describe('API wrapper', () => { expect(redirect).toBeInstanceOf(Function); expect(error).toBeInstanceOf(Function); expect(custom).toBeInstanceOf(Function); - success({ body: 'success' }); + success({ body: "success" }); } api(customHandler)(requestEvent, context, callback); }); - it('Has expected properties and response functions with optional generic type', () => { + it("Has expected properties and response functions with optional generic type", () => { interface CustomType { Message: string; Id: number; @@ -89,11 +89,11 @@ describe('API wrapper', () => { custom, }: ApiSignature) { expect(event).toEqual(requestEvent); - expect(websocket.connectionId).toEqual('abc-123'); - expect(body).toEqual({ hello: 'world' }); - expect(path).toEqual({ proxy: 'not today' }); - expect(query).toEqual({ name: 'a test' }); - expect(headers['content-type']).toEqual('application/json'); + expect(websocket.connectionId).toEqual("abc-123"); + expect(body).toEqual({ hello: "world" }); + expect(path).toEqual({ proxy: "not today" }); + expect(query).toEqual({ name: "a test" }); + expect(headers["content-type"]).toEqual("application/json"); expect(testRequest).toEqual(true); expect(auth).toBeTruthy(); expect(success).toBeInstanceOf(Function); @@ -103,7 +103,7 @@ describe('API wrapper', () => { expect(redirect).toBeInstanceOf(Function); expect(error).toBeInstanceOf(Function); expect(custom).toBeInstanceOf(Function); - success({ body: 'success' }); + success({ body: "success" }); } api(customHandler)(requestEvent, context, callback); }); diff --git a/src/api/v2-http/parser.test.ts b/src/api/v2-http/parser.test.ts index 6d19b31..0683824 100644 --- a/src/api/v2-http/parser.test.ts +++ b/src/api/v2-http/parser.test.ts @@ -1,38 +1,38 @@ -import { stringify } from 'querystring'; -import { HttpApiEvent } from 'serverless-plugin-test-helper'; -import { Request, Body } from './parser'; +import { stringify } from "querystring"; +import { HttpApiEvent } from "serverless-plugin-test-helper"; +import { Request, Body } from "./parser"; -describe('HTTP API Body parsing', () => { - it('Parses json body', () => { - const json = { hello: 'world' }; - const headers = { 'content-type': 'application/json' }; +describe("HTTP API Body parsing", () => { + it("Parses json body", () => { + const json = { hello: "world" }; + const headers = { "content-type": "application/json" }; const body = new Body(JSON.stringify(json), headers).getParsedBody(); expect(body).toEqual(json); }); - it('Parses json body when charset is also defined in the content-type', () => { - const json = { hello: 'world' }; - const headers = { 'content-type': 'application/json;charset=UTF-8' }; + it("Parses json body when charset is also defined in the content-type", () => { + const json = { hello: "world" }; + const headers = { "content-type": "application/json;charset=UTF-8" }; const body = new Body(JSON.stringify(json), headers).getParsedBody(); expect(body).toEqual(json); }); - it('Parses form url encoded body', () => { - const form = { hello: 'world' }; - const headers = { 'content-type': 'application/x-www-form-urlencoded' }; + it("Parses form url encoded body", () => { + const form = { hello: "world" }; + const headers = { "content-type": "application/x-www-form-urlencoded" }; const body = new Body(stringify(form), headers).getParsedBody(); expect(body).toEqual(form); }); - it('Parses form url encoded body when charset is also defined in the content-type', () => { - const form = { hello: 'world' }; - const headers = { 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' }; + it("Parses form url encoded body when charset is also defined in the content-type", () => { + const form = { hello: "world" }; + const headers = { "content-type": "application/x-www-form-urlencoded;charset=UTF-8" }; const body = new Body(stringify(form), headers).getParsedBody(); expect(body).toEqual(form); }); it("Tries to parse body as JSON when content type isn't specified", () => { - const json = { hello: 'world' }; + const json = { hello: "world" }; const headers = undefined; const body = new Body(JSON.stringify(json), headers).getParsedBody(); expect(body).toEqual(json); @@ -40,39 +40,39 @@ describe('HTTP API Body parsing', () => { it("Errors when encoding and content-type don't match", () => { const invalid = '2["test" : 123]4}{'; - const headers = { 'content-type': 'application/json' }; + const headers = { "content-type": "application/json" }; const body = new Body(invalid, headers).getParsedBody(); expect(body).toEqual(invalid); }); - it('Returns empty body when none given', () => { + it("Returns empty body when none given", () => { let empty; - const headers = { 'content-type': 'application/x-www-form-urlencoded' }; + const headers = { "content-type": "application/x-www-form-urlencoded" }; const body = new Body(empty, headers).getParsedBody(); expect(body).toEqual(empty); }); }); -describe('Http API request parsing', () => { - it('Gets all fields with optional parameters', () => { +describe("Http API request parsing", () => { + it("Gets all fields with optional parameters", () => { const event = new HttpApiEvent({ - body: JSON.stringify({ hello: 'world' }), - rawPath: '/api/v1/nouns/id124', - pathParameters: { proxy: 'not today' }, - rawQueryString: 'name=atest', - queryStringParameters: { name: 'atest' }, - headers: { 'content-type': 'application/json', 'Test-Request': 'true' }, + body: JSON.stringify({ hello: "world" }), + rawPath: "/api/v1/nouns/id124", + pathParameters: { proxy: "not today" }, + rawQueryString: "name=atest", + queryStringParameters: { name: "atest" }, + headers: { "content-type": "application/json", "test-request": "true" }, }); const { body, path, rawPath, query, rawQueryString, auth, headers, testRequest } = new Request( event ).getProperties(); - expect(body).toEqual({ hello: 'world' }); - expect(path['proxy']).toEqual(event.pathParameters.proxy); + expect(body).toEqual({ hello: "world" }); + expect(path["proxy"]).toEqual(event.pathParameters.proxy); expect(rawPath).toEqual(event.rawPath); - expect(query['name']).toEqual(event.queryStringParameters.name); + expect(query["name"]).toEqual(event.queryStringParameters.name); expect(rawQueryString).toEqual(event.rawQueryString); - expect(headers['content-type']).toEqual('application/json'); + expect(headers["content-type"]).toEqual("application/json"); expect(testRequest).toEqual(true); expect(auth).toBeTruthy(); }); @@ -99,7 +99,7 @@ describe('Http API request parsing', () => { expect(testRequest).toBeFalsy(); }); - it('Supports default values in method signature', () => { + it("Supports default values in method signature", () => { const event = new HttpApiEvent(); delete event.body; delete event.headers; diff --git a/src/api/v2-http/parser.ts b/src/api/v2-http/parser.ts index 74c17a4..774e3d3 100644 --- a/src/api/v2-http/parser.ts +++ b/src/api/v2-http/parser.ts @@ -25,7 +25,7 @@ export class Request { const auth = this.getAuth(); const headers = event.headers || undefined; const body = new Body(event.body, headers).getParsedBody(); - const TEST_REQUEST_HEADER = process.env.TEST_REQUEST_HEADER || "Test-Request"; + const TEST_REQUEST_HEADER = process.env.TEST_REQUEST_HEADER || "test-request"; const testRequest = headers && headers[TEST_REQUEST_HEADER] ? JSON.parse(headers[TEST_REQUEST_HEADER]) : false; const parsed = { body, path, rawPath, query, rawQueryString, auth, headers, testRequest }; metrics.common(parsed, event); diff --git a/src/api/v2-http/wrapper.test.ts b/src/api/v2-http/wrapper.test.ts index cb2a2a7..b5db716 100644 --- a/src/api/v2-http/wrapper.test.ts +++ b/src/api/v2-http/wrapper.test.ts @@ -1,23 +1,23 @@ /* eslint-disable @typescript-eslint/no-empty-function */ -import { HttpApiEvent } from 'serverless-plugin-test-helper'; -import { httpApi, HttpApiSignature } from './wrapper'; +import { HttpApiEvent } from "serverless-plugin-test-helper"; +import { httpApi, HttpApiSignature } from "./wrapper"; -describe('HTTP API wrapper', () => { +describe("HTTP API wrapper", () => { const requestEvent = new HttpApiEvent({ - body: JSON.stringify({ hello: 'world' }), - pathParameters: { proxy: 'not today' }, - queryStringParameters: { name: 'a test' }, - headers: { 'content-type': 'application/json', 'Test-Request': 'true' }, + body: JSON.stringify({ hello: "world" }), + pathParameters: { proxy: "not today" }, + queryStringParameters: { name: "a test" }, + headers: { "content-type": "application/json", "test-request": "true" }, }); const context = { callbackWaitsForEmptyEventLoop: false, - functionName: 'function-name', - functionVersion: '$LATEST', - invokedFunctionArn: 'arn:', - memoryLimitInMB: '128', - awsRequestId: 'request', - logGroupName: 'group', - logStreamName: 'stream', + functionName: "function-name", + functionVersion: "$LATEST", + invokedFunctionArn: "arn:", + memoryLimitInMB: "128", + awsRequestId: "request", + logGroupName: "group", + logStreamName: "stream", getRemainingTimeInMillis: () => 2, done: () => {}, fail: () => {}, @@ -25,7 +25,7 @@ describe('HTTP API wrapper', () => { }; const callback = jest.fn((err, result) => (err ? new Error(err) : result)); - it('Has expected properties and response functions', () => { + it("Has expected properties and response functions", () => { function customHandler({ event, body, @@ -43,10 +43,10 @@ describe('HTTP API wrapper', () => { custom, }: HttpApiSignature) { expect(event).toEqual(requestEvent); - expect(body).toEqual({ hello: 'world' }); - expect(path['proxy']).toEqual('not today'); - expect(query['name']).toEqual('a test'); - expect(headers['content-type']).toEqual('application/json'); + expect(body).toEqual({ hello: "world" }); + expect(path["proxy"]).toEqual("not today"); + expect(query["name"]).toEqual("a test"); + expect(headers["content-type"]).toEqual("application/json"); expect(testRequest).toEqual(true); expect(auth).toBeTruthy(); expect(success).toBeInstanceOf(Function); @@ -56,12 +56,12 @@ describe('HTTP API wrapper', () => { expect(redirect).toBeInstanceOf(Function); expect(error).toBeInstanceOf(Function); expect(custom).toBeInstanceOf(Function); - success({ body: 'success' }); + success({ body: "success" }); } httpApi(customHandler)(requestEvent, context, callback); }); - it('Has expected properties and response functions with optional generic type', () => { + it("Has expected properties and response functions with optional generic type", () => { interface CustomType { Message: string; Id: number; @@ -83,10 +83,10 @@ describe('HTTP API wrapper', () => { custom, }: HttpApiSignature) { expect(event).toEqual(requestEvent); - expect(body).toEqual({ hello: 'world' }); - expect(path['proxy']).toEqual('not today'); - expect(query['name']).toEqual('a test'); - expect(headers['content-type']).toEqual('application/json'); + expect(body).toEqual({ hello: "world" }); + expect(path["proxy"]).toEqual("not today"); + expect(query["name"]).toEqual("a test"); + expect(headers["content-type"]).toEqual("application/json"); expect(testRequest).toEqual(true); expect(auth).toBeTruthy(); expect(success).toBeInstanceOf(Function); @@ -96,7 +96,7 @@ describe('HTTP API wrapper', () => { expect(redirect).toBeInstanceOf(Function); expect(error).toBeInstanceOf(Function); expect(custom).toBeInstanceOf(Function); - success({ body: 'success' }); + success({ body: "success" }); } httpApi(customHandler)(requestEvent, context, callback); }); diff --git a/src/api/v2-http/wrapper.ts b/src/api/v2-http/wrapper.ts index a0f8aae..d2441c4 100644 --- a/src/api/v2-http/wrapper.ts +++ b/src/api/v2-http/wrapper.ts @@ -1,6 +1,6 @@ -import { Context, Callback } from 'aws-lambda'; -import { HttpApiEvent } from './payload'; -import { Request } from './parser'; +import { Context, Callback } from "aws-lambda"; +import { HttpApiEvent } from "./payload"; +import { Request } from "./parser"; import { success, invalid, @@ -14,7 +14,7 @@ import { RedirectParameters, ErrorParameters, CustomParameters, -} from '../shared'; +} from "../shared"; export function httpApi( customHandler: (props: HttpApiSignature) => any