import { expect } from 'chai'; import { Request } from '../../src/http'; import { BadRequest } from '../../src/http/errors'; import { getMockAPIEvent } from '../support/mockapievent'; describe('A Request object', () => { let data = { "foo": 123, "bar": true }; let event = getMockAPIEvent(); event.body = JSON.stringify(data); let request = new Request(event); it('should be constructed from an APIGatewayEvent', () => { expect(request).to.exist; }); it('should have the original APIGatewayEvent', () => { expect(request.event).to.equal(event); }); it('should automatically convert a JSON body to an object', () => { expect(request.data).to.exist; expect(request.data).to.deep.equal(data); }); it('should not accept an invalid JSON body', () => { let event = getMockAPIEvent(); event.body = '{123: foo}'; try { new Request(event); throw new Error('Expected exception was not raised.'); } catch (err) { expect(err).to.be.instanceOf(BadRequest); } }); });