Skip to content

Commit

Permalink
feat: support AWS JSON 1.0 and 1.1 content-types
Browse files Browse the repository at this point in the history
  • Loading branch information
ybonnefond committed Oct 6, 2021
1 parent 9d83ac8 commit 1811453
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/middlewares/bodyJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,12 @@ import { json } from 'body-parser';
* @internal
*/
export function bodyJson() {
return json();
return json({
type: [
'json',
'application/json',
'application/x-amz-json-1.0',
'application/x-amz-json-1.1',
],
});
}
34 changes: 34 additions & 0 deletions test/specs/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,40 @@ describe('index', () => {
const body = JSON.parse(res.body as string);
expect(body).toStrictEqual({ key: 'ok' });
});

it('should support AWS json 1.0 content type and parse body', async () => {
sb.post('/', { input: 'something' })
.setHeader('Content-Type', 'application/x-amz-json-1.1')
.setResponseBody({ output: 'anything' })
.logDiffOn501();

const res = await request('/', {
method: 'post',
body: '{"input": "something"}',
responseType: 'json',
headers: { 'Content-Type': 'application/x-amz-json-1.1' },
});
expect(res).toReplyWith(STATUS_CODES.SUCCESS);

expect(res.body).toStrictEqual({ output: 'anything' });
});

it('should support AWS json 1.1 content type and parse body', async () => {
sb.post('/', { input: 'something' })
.setHeader('Content-Type', 'application/x-amz-json-1.1')
.setResponseBody({ output: 'anything' })
.logDiffOn501();

const res = await request('/', {
method: 'post',
body: '{"input": "something"}',
responseType: 'json',
headers: { 'Content-Type': 'application/x-amz-json-1.1' },
});
expect(res).toReplyWith(STATUS_CODES.SUCCESS);

expect(res.body).toStrictEqual({ output: 'anything' });
});
});

describe('Query', () => {
Expand Down

0 comments on commit 1811453

Please sign in to comment.