-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
37 lines (31 loc) · 944 Bytes
/
index.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { randAddress } from '@ngneat/falso';
import httpJsonBodyParserMiddleware from './index.js';
describe('middy-json-body-parser', () => {
let middleware;
const address = randAddress();
const cases = [
['json payload, no parse needed, should warn', address, address, false],
[
'json stringified payload, parse needed',
JSON.stringify(address),
address,
false,
],
[
'base64 json stringified payload, parse needed',
Buffer.from(JSON.stringify(address), 'ascii').toString('base64'),
address,
true,
],
];
beforeEach(() => {
middleware = httpJsonBodyParserMiddleware();
});
test.each(cases)('%s', async (caseName, body, expected, base64) => {
const request = { event: { body, isBase64Encoded: base64 } };
await middleware.before(request);
expect(request).toEqual({
event: { body: expected, isBase64Encoded: base64 },
});
});
});