blob: eb85cc67eb6aa924d57b0989da1b30433df52f41 (
plain) (
blame)
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
|
/* tslint:disable:no-unused-expression */
// Disabled to allow chai-style assertions.
import * as chai from 'chai';
chai.should();
import { ErrorResponseBlock, RequestError } from './errorware';
describe('RequestError', () => {
describe('constructor', () => {
it('constructs simple errors', () => {
const err: RequestError = new RequestError(
404, 'user_not_found'
);
err.code.should.equal(404);
err.name.should.equal('user_not_found');
});
it('constructs with sensible defaults', () => {
const err: RequestError = new RequestError();
err.code.should.not.be.undefined;
err.name.should.not.be.undefined;
});
});
describe('response generation', () => {
it('generates responses', () => {
const err: RequestError = new RequestError(
500, 'internal_server_error'
);
const response: ErrorResponseBlock =
err.responseBlock();
response.status.should.equal('error');
response.error.should.equal('internal_server_error');
});
});
});
|