Skip to content

Commit

Permalink
feat(middleware): create http server exception and middleware with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ianwremmel committed Oct 30, 2017
1 parent 5293eed commit 8ed433d
Show file tree
Hide file tree
Showing 10 changed files with 1,056 additions and 3 deletions.
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@
"lint:staged": "lint-staged",
"mocha-reporter-options": "[ -n \"${CI}\" ] && echo '--reporter xunit --reporter-options output=reports/junit/test.xml'",
"precommit": "npm run --silent lint:staged",
"test": "nyc --reporter=text mocha $(npm run --silent mocha-reporter-options) './src/**/*-spec.js'",
"test": "nyc --reporter=text mocha $(npm run --silent mocha-reporter-options) './src/**/*-spec.js' './test/integration/spec/**/*.js'",
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
},
"engines": {},
"keywords": [],
"author": "Ian W. Remmel <[email protected]>",
"license": "MIT",
"dependencies": {},
"dependencies": {
"@ianwremmel/exception": "^1.0.0"
},
"devDependencies": {
"@commitlint/cli": "^4.2.2",
"@commitlint/config-angular": "^4.2.1",
Expand All @@ -39,14 +41,17 @@
"condition-circle": "^1.5.0",
"coveralls": "^3.0.0",
"dependency-check": "^2.9.1",
"ejs": "^2.5.7",
"eslint": "^4.10.0",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-mocha": "^4.11.0",
"express": "^4.16.2",
"husky": "^0.14.3",
"lint-staged": "^4.3.0",
"mocha": "^4.0.1",
"nyc": "^11.2.1",
"semantic-release": "^8.2.0"
"semantic-release": "^8.2.0",
"supertest": "^3.0.0"
},
"lint-staged": {
"*.js": "lint:eslint",
Expand Down
145 changes: 145 additions & 0 deletions src/http-exception-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
'use strict';

/* eslint-env mocha */
/* eslint-disable require-jsdoc */
/* eslint-disable max-nested-callbacks */

const {assert} = require('chai');

const {
BadRequest,
Unauthorized,
PaymentRequired,
Forbidden,
NotFound,
MethodNotAllowed,
NotAcceptable,
ProxyAuthenticationRequired,
RequestTimeout,
Conflict,
Gone,
LengthRequired,
PreconditionFailed,
RequestEntityTooLarge,
RequestUriTooLong,
UnsupportedMediaType,
RequestRangeNotSatisfiable,
ExpectationFailed,
InternalServerError,
NotImplemented,
BadGateway,
ServiceUnavailable,
GatewayTimeout,
HttpVersionNotSupported
} = require('./http-exception');

[
[
BadRequest,
400
],
[
Unauthorized,
401
],
[
PaymentRequired,
402
],
[
Forbidden,
403
],
[
NotFound,
404
],
[
MethodNotAllowed,
405
],
[
NotAcceptable,
406
],
[
ProxyAuthenticationRequired,
407
],
[
RequestTimeout,
408
],
[
Conflict,
409
],
[
Gone,
410
],
[
LengthRequired,
411
],
[
PreconditionFailed,
412
],
[
RequestEntityTooLarge,
413
],
[
RequestUriTooLong,
414
],
[
UnsupportedMediaType,
415
],
[
RequestRangeNotSatisfiable,
416
],
[
ExpectationFailed,
417
],
[
InternalServerError,
500
],
[
NotImplemented,
501
],
[
BadGateway,
502
],
[
ServiceUnavailable,
503
],
[
GatewayTimeout,
504
],
[
HttpVersionNotSupported,
505
]
].forEach(([
Constructor,
code
]) => {
describe(Constructor.name, () => {
describe('#code', () => {
it('is defined', () => {
const e = new Constructor();
assert.equal(e.code, code);
});
});
});
});
Loading

0 comments on commit 8ed433d

Please sign in to comment.