import { expect } from 'chai'; import { Response, Errors } from '../../src/http'; describe('An HTTP Error module', () => { it('should have a base error constructed from an optional code and message', () => { let err = new Errors.HTTPError(123, 'Fake message'); expect(err.code).to.equal(123); expect(err.message).to.equal('Fake message'); err = new Errors.HTTPError(); expect(err.code).to.equal(500); expect(err.message).to.exist; }); it('should implement returning a Response representation', () => { let err = new Errors.HTTPError(123, 'Fake message'); let response = err.toResponse(); expect(response instanceof Response).to.equal(true); }); it('should copy headers from the provided response', () => { let res = new Response(200); res.headers['foo'] = 'bar'; let err = new Errors.HTTPError(123, 'Fake message'); let response = err.toResponse(res); expect(response instanceof Response).to.equal(true); expect(response.code).to.equal(123); expect(response.headers['foo']).to.exist; expect(response.headers['foo']).to.equal('bar'); }); it(`should have an implementation of BadRequest`, () => { let err = new Errors.BadRequest(); expect(err.code).to.equal(400); expect(err.message).to.exist; }); it(`should have an implementation of Unauthorized`, () => { let err = new Errors.Unauthorized(); expect(err.code).to.equal(401); expect(err.message).to.exist; }); it(`should have an implementation of Forbidden`, () => { let err = new Errors.Forbidden(); expect(err.code).to.equal(403); expect(err.message).to.exist; }); it(`should have an implementation of NotFound`, () => { let err = new Errors.NotFound(); expect(err.code).to.equal(404); expect(err.message).to.exist; }); it(`should have an implementation of MethodNotAllowed`, () => { let err = new Errors.MethodNotAllowed(); expect(err.code).to.equal(405); expect(err.message).to.exist; }); it(`should have an implementation of InternalError`, () => { let err = new Errors.InternalError(); expect(err.code).to.equal(500); expect(err.message).to.exist; }); });