1
0
Fork 0

Fixed validation error detection.

This commit is contained in:
Alan Plum 2015-06-04 00:58:38 +02:00
parent 136897d9c9
commit f61671ded5
2 changed files with 6 additions and 12 deletions

View File

@ -35,6 +35,7 @@ var SwaggerDocs = require("org/arangodb/foxx/swaggerDocs").Docs,
internal = require("org/arangodb/foxx/internals"),
toJSONSchema = require("org/arangodb/foxx/schema").toJSONSchema,
is = require("org/arangodb/is"),
BadRequest = require("http-errors").BadRequest,
UnauthorizedError = require("org/arangodb/foxx/authentication").UnauthorizedError;
function createBodyParamExtractor(rootElement, paramName, allowInvalid) {
@ -100,7 +101,7 @@ function validateOrThrow(raw, schema, allowInvalid) {
}
var result = joi.validate(raw, schema);
if (result.error && !allowInvalid) {
throw result.error;
throw new BadRequest(result.error.message);
}
return result.value;
}

View File

@ -964,9 +964,7 @@ function DocumentationAndConstraintsSpec () {
paramName = 'flurb',
description = stub(),
requestBody = 'banana',
schema = joi.array().items({x: joi.number().integer().required()}),
called = false,
thrown = false;
schema = joi.array().items({x: joi.number().integer().required()});
allow(req)
.toReceive("body")
@ -979,15 +977,10 @@ function DocumentationAndConstraintsSpec () {
type: schema
});
try {
var callback = transformRoute(routes[0].action);
callback(req, res);
} catch(e) {
thrown = true;
}
var callback = transformRoute(routes[0].action);
callback(req, res);
assertTrue(thrown);
assertFalse(called);
assertEqual(res.responseCode, 400);
},
testSetParamForUndocumentedBodyParam: function () {