dat-middleware
Advanced tools
Comparing version 1.9.0 to 1.9.1
{ | ||
"name": "dat-middleware", | ||
"version": "1.9.0", | ||
"version": "1.9.1", | ||
"description": "common request, response, body, query, and param validation, transformation, and flow control middleware", | ||
@@ -40,3 +40,3 @@ "main": "index.js", | ||
"fn-object": "^0.2.2", | ||
"keypather": "^1.7.0", | ||
"keypather": "^1.7.5", | ||
"map-utils": "~0.4.0", | ||
@@ -43,0 +43,0 @@ "middleware-flow": "^0.6.0" |
@@ -5,2 +5,3 @@ var createAppWithMiddleware = require('./fixtures/createAppWithMiddleware'); | ||
var request = require('./lib/superdupertest'); | ||
var keypather = require('keypather')(); | ||
var values = function (obj) { | ||
@@ -17,2 +18,4 @@ return Object.keys(obj).map(function (key) { | ||
describe('mw.body(keypath).require()', requireKeypath('body', 'foo.bar.baz')); | ||
describe('mw.body(keys...).require()', requireKeys('body')); | ||
@@ -61,2 +64,36 @@ describe('mw.query(keys...).require()', requireKeys('query')); | ||
function requireKeypath (dataType, keypath) { | ||
return function () { | ||
before(function () { | ||
this.keypath = keypath; | ||
this.app = createAppWithMiddleware(mw[dataType](this.keypath).require()); | ||
}); | ||
it('should error if required key not included', function (done) { | ||
var body = {}; | ||
var query = {}; | ||
var params = values({}); | ||
request(this.app) | ||
.post('/'+dataType, params, query) | ||
.send(body) | ||
.expect(400) | ||
.expect(function (res) { | ||
res.body.message.should.match(/required/); | ||
}) | ||
.end(done); | ||
}); | ||
it('should succeed if required key included', function (done) { | ||
var data = {}; | ||
keypather.set(data, this.keypath, 'value'); | ||
var body = dataType === 'body' ? data : {}; | ||
var query = dataType === 'query' ? data : {}; | ||
var params = dataType === 'params' ? values(data) : []; | ||
request(this.app) | ||
.post('/'+dataType, params, query) | ||
.send(data) | ||
.expect(200, data) | ||
.end(done); | ||
}); | ||
}; | ||
} | ||
function requireKeys (dataType) { | ||
@@ -63,0 +100,0 @@ return function () { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
74051
2063
Updatedkeypather@^1.7.5