aboutsummaryrefslogtreecommitdiff
path: root/src/errors/errorware.test.ts
diff options
context:
space:
mode:
authorTom Harley2018-02-22 16:57:42 +0000
committerTom Harley2018-02-22 16:57:42 +0000
commit9858d16011dd91add5b7c2bf637c433ed6b74f0f (patch)
tree2e1827ee9d94c9a64242a80b1e117962b76a3421 /src/errors/errorware.test.ts
parentMerge branch 'trh/yarn' into trh/payload-checker (diff)
downloadmedicine-9858d16011dd91add5b7c2bf637c433ed6b74f0f.tar.gz
medicine-9858d16011dd91add5b7c2bf637c433ed6b74f0f.zip

Add error-handling middleware with basic tests

Diffstat (limited to 'src/errors/errorware.test.ts')
-rw-r--r--src/errors/errorware.test.ts35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/errors/errorware.test.ts b/src/errors/errorware.test.ts
new file mode 100644
index 0000000..eb85cc6
--- /dev/null
+++ b/src/errors/errorware.test.ts
@@ -0,0 +1,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');
+ });
+ });
+});