Skip to content

Commit

Permalink
Merge pull request #108 from holidayextras/all-validation-errors
Browse files Browse the repository at this point in the history
Return all validation errors
  • Loading branch information
theninj4 committed Apr 8, 2016
2 parents 4e923f4 + afa0b39 commit 88bb555
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
4 changes: 2 additions & 2 deletions lib/routes/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ var _ = {

helper.validate = function(someObject, someDefinition, callback) {
debug.validationInput(JSON.stringify(someObject));
Joi.validate(someObject, someDefinition, function (err, sanitisedObject) {
Joi.validate(someObject, someDefinition, { abortEarly: false }, function (err, sanitisedObject) {
if (err) {
return callback({
status: "403",
code: "EFORBIDDEN",
title: "Param validation failed",
detail: err
detail: err.details
});
}
_.assign(someObject, sanitisedObject);
Expand Down
15 changes: 4 additions & 11 deletions test/post-resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,22 @@ describe("Testing jsonapi-server", function() {
it("errors if resource doesnt validate", function(done) {
var data = {
method: "post",
url: "http://localhost:16006/rest/photos",
url: "http://localhost:16006/rest/articles",
headers: {
"Content-Type": "application/vnd.api+json"
},
body: JSON.stringify({
"data": {
"type": "photos",
"attributes": {
"title": "Ember Hamster",
"height": 512,
"width": 1024
},
"relationships": {
"photographer": {
"data": { "type": "people", "id": "cc5cca2e-0dd8-4b95-8cfc-a11230e73116" }
}
}
"attributes": { },
"relationships": { }
}
})
};
helpers.request(data, function(err, res, json) {
assert.equal(err, null);
json = helpers.validateError(json);
assert.equal(json.errors[0].detail.length, 2, "Expecting several validation errors");
assert.equal(res.statusCode, "403", "Expecting 403");

done();
Expand Down

0 comments on commit 88bb555

Please sign in to comment.