diff --git a/lib/response-base.js b/lib/response-base.js index 7ea430879..3ec014fee 100644 --- a/lib/response-base.js +++ b/lib/response-base.js @@ -124,6 +124,7 @@ ResponseBase.prototype._setStatusProperties = function(status){ : false; // sugar + this.created = 201 == status; this.accepted = 202 == status; this.noContent = 204 == status; this.badRequest = 400 == status; @@ -131,4 +132,5 @@ ResponseBase.prototype._setStatusProperties = function(status){ this.notAcceptable = 406 == status; this.forbidden = 403 == status; this.notFound = 404 == status; + this.unprocessableEntity = 422 == status; }; diff --git a/test/node/flags.js b/test/node/flags.js index 94e28d5eb..9e83fef80 100644 --- a/test/node/flags.js +++ b/test/node/flags.js @@ -82,4 +82,24 @@ describe("flags", () => { }); }); }); + + describe("with 201 Created", () => { + it("should set res.created", done => { + request.post(`${base}/created`).end((err, res) => { + assert(!err); + assert(res.created, "response should be .created"); + done(); + }); + }); + }); + + describe("with 422 Unprocessable Entity", () => { + it("should set res.unprocessableEntity", done => { + request.post(`${base}/unprocessable-entity`).end((err, res) => { + assert(err); + assert(res.unprocessableEntity, "response should be .unprocessableEntity"); + done(); + }); + }); + }); }); diff --git a/test/support/server.js b/test/support/server.js index ca9cab11b..cc3295f43 100644 --- a/test/support/server.js +++ b/test/support/server.js @@ -310,6 +310,14 @@ app.delete('/no-content', function(req, res){ res.sendStatus(204); }); +app.post('/created', function(req, res) { + res.status(201).send('created'); +}); + +app.post('/unprocessable-entity', function(req, res) { + res.status(422).send('unprocessable entity'); +}); + app.get('/arraybuffer', function(req, res) { var content = new ArrayBuffer(1000); res.set('Content-Type', 'application/vnd.superagent');