Skip to content

Commit

Permalink
Add flags for 201 & 422 responses
Browse files Browse the repository at this point in the history
  • Loading branch information
itsfadnis committed Mar 31, 2018
1 parent d70933c commit 386f702
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/response-base.js
Expand Up @@ -124,11 +124,13 @@ ResponseBase.prototype._setStatusProperties = function(status){
: false;

// sugar
this.created = 201 == status;
this.accepted = 202 == status;
this.noContent = 204 == status;
this.badRequest = 400 == status;
this.unauthorized = 401 == status;
this.notAcceptable = 406 == status;
this.forbidden = 403 == status;
this.notFound = 404 == status;
this.unprocessableEntity = 422 == status;
};
20 changes: 20 additions & 0 deletions test/node/flags.js
Expand Up @@ -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();
});
});
});
});
8 changes: 8 additions & 0 deletions test/support/server.js
Expand Up @@ -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');
Expand Down

0 comments on commit 386f702

Please sign in to comment.