Skip to content

Commit 888759a

Browse files
committed
Prettier ✨
1 parent 4f69827 commit 888759a

File tree

5 files changed

+31
-29
lines changed

5 files changed

+31
-29
lines changed

src/__tests__/integrationV1.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ import { defineLambdaTestSuite } from './defineLambdaTestSuite';
22
import { createMockV1Server } from './mockAPIGatewayV1Server';
33

44
describe('lambdaHandlerV1', () => {
5-
defineLambdaTestSuite(createMockV1Server)
5+
defineLambdaTestSuite(createMockV1Server);
66
});

src/__tests__/mockALBServer.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,28 @@ import type { IncomingMessage } from 'http';
33
import type { ALBEvent, ALBResult, Handler } from 'aws-lambda';
44
import { createMockServer } from './mockServer';
55

6-
export function createMockALBServer(handler: Handler<ALBEvent, ALBResult>, shouldBase64Encode: boolean) {
6+
export function createMockALBServer(
7+
handler: Handler<ALBEvent, ALBResult>,
8+
shouldBase64Encode: boolean,
9+
) {
710
return createMockServer(handler, albEventFromRequest(shouldBase64Encode));
811
}
912

1013
function albEventFromRequest(shouldBase64Encode: boolean) {
1114
return function (req: IncomingMessage, body: string): ALBEvent {
1215
const urlObject = url.parse(req.url || '', false);
1316
const searchParams = new URLSearchParams(urlObject.search ?? '');
14-
17+
1518
const multiValueQueryStringParameters: ALBEvent['multiValueQueryStringParameters'] =
1619
{};
17-
20+
1821
for (const [key] of searchParams.entries()) {
1922
const all = searchParams.getAll(key);
2023
if (all.length > 1) {
2124
multiValueQueryStringParameters[key] = all;
2225
}
2326
}
24-
27+
2528
return {
2629
requestContext: {
2730
elb: {
@@ -41,9 +44,10 @@ function albEventFromRequest(shouldBase64Encode: boolean) {
4144
}),
4245
),
4346
multiValueQueryStringParameters,
44-
body: shouldBase64Encode ? Buffer.from(body, 'utf8').toString('base64') : body,
47+
body: shouldBase64Encode
48+
? Buffer.from(body, 'utf8').toString('base64')
49+
: body,
4550
isBase64Encoded: shouldBase64Encode,
4651
};
47-
}
52+
};
4853
}
49-

src/__tests__/mockAPIGatewayV1Server.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,18 @@ export function createMockV1Server(
1515
}
1616

1717
function v1EventFromRequest(shouldBase64Encode: boolean) {
18-
return function (
19-
req: IncomingMessage,
20-
body: string,
21-
): APIGatewayProxyEvent {
18+
return function (req: IncomingMessage, body: string): APIGatewayProxyEvent {
2219
const urlObject = url.parse(req.url || '', false);
2320
const searchParams = new URLSearchParams(urlObject.search ?? '');
24-
21+
2522
const multiValueQueryStringParameters: Record<string, string[]> = {};
2623
for (const [key] of searchParams.entries()) {
2724
const all = searchParams.getAll(key);
2825
if (all.length > 1) {
2926
multiValueQueryStringParameters[key] = all;
3027
}
3128
}
32-
29+
3330
// simplify the V1 event down to what our integration actually cares about
3431
const event: Partial<APIGatewayProxyEvent> = {
3532
// @ts-expect-error (version actually can exist on v1 events, this seems to be a typing error)
@@ -45,13 +42,14 @@ function v1EventFromRequest(shouldBase64Encode: boolean) {
4542
}),
4643
),
4744
queryStringParameters: Object.fromEntries(searchParams.entries()),
48-
body: shouldBase64Encode ? Buffer.from(body, 'utf8').toString('base64') : body,
45+
body: shouldBase64Encode
46+
? Buffer.from(body, 'utf8').toString('base64')
47+
: body,
4948
isBase64Encoded: shouldBase64Encode,
5049
multiValueQueryStringParameters,
5150
multiValueHeaders: {},
5251
};
53-
52+
5453
return event as APIGatewayProxyEvent;
55-
}
56-
54+
};
5755
}

src/__tests__/mockAPIGatewayV2Server.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,10 @@ export function createMockV2Server(
1414
return createMockServer(handler, v2EventFromRequest(shouldBase64Encode));
1515
}
1616

17-
function v2EventFromRequest(shouldBase64Encode: boolean){
18-
return function (
19-
req: IncomingMessage,
20-
body: string,
21-
): APIGatewayProxyEventV2 {
17+
function v2EventFromRequest(shouldBase64Encode: boolean) {
18+
return function (req: IncomingMessage, body: string): APIGatewayProxyEventV2 {
2219
const urlObject = url.parse(req.url || '', false);
23-
20+
2421
// simplify the V2 event down to what our integration actually cares about,
2522
// but keep it defined in terms of the original type so we know the fields
2623
// we _are_ populating are correct.
@@ -33,10 +30,12 @@ function v2EventFromRequest(shouldBase64Encode: boolean){
3330
>;
3431
}
3532
>;
36-
33+
3734
const event: TestEventType = {
3835
version: '2.0',
39-
body: shouldBase64Encode ? Buffer.from(body, 'utf8').toString('base64') : body,
36+
body: shouldBase64Encode
37+
? Buffer.from(body, 'utf8').toString('base64')
38+
: body,
4039
rawQueryString: urlObject.search?.replace(/^\?/, '') ?? '',
4140
headers: Object.fromEntries(
4241
Object.entries(req.headers).map(([name, value]) => {
@@ -56,6 +55,5 @@ function v2EventFromRequest(shouldBase64Encode: boolean){
5655
isBase64Encoded: shouldBase64Encode,
5756
};
5857
return event as APIGatewayProxyEventV2;
59-
}
60-
58+
};
6159
}

src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ function parseBody(
136136
isBase64: boolean,
137137
): object | string {
138138
if (body) {
139-
const parsedBody = isBase64 ? Buffer.from(body, 'base64').toString('utf8') : body;
139+
const parsedBody = isBase64
140+
? Buffer.from(body, 'base64').toString('utf8')
141+
: body;
140142
if (contentType?.startsWith('application/json')) {
141143
return JSON.parse(parsedBody);
142144
}

0 commit comments

Comments
 (0)