-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(middleware): create http server exception and middleware with tests
- Loading branch information
1 parent
5293eed
commit 8ed433d
Showing
10 changed files
with
1,056 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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", | ||
|
@@ -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", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.