aboutsummaryrefslogtreecommitdiff
path: root/test/unit/errorware.unit.test.ts
diff options
context:
space:
mode:
authorTom Harley2018-03-06 16:59:39 +0000
committerTom Harley2018-03-06 16:59:39 +0000
commit375da6ab2d518665415eacca85d5c0bb8b72a885 (patch)
treec2ad547542878b6725d8a77dbbda826d04adf3f3 /test/unit/errorware.unit.test.ts
parentMerge branch 'trh/payload-checker' of gitlab.cs.st-andrews.ac.uk:cs3099group-... (diff)
parentMerge branch 'trh/payload-checker' into testing-middleware (diff)
downloadmedicine-375da6ab2d518665415eacca85d5c0bb8b72a885.tar.gz
medicine-375da6ab2d518665415eacca85d5c0bb8b72a885.zip

Merge ‘origin/testing-middleware’ into trh/payload-checker

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