dat-middleware
Advanced tools
Comparing version 1.6.1 to 1.7.0
@@ -417,4 +417,2 @@ var error = require('./error'); | ||
var dataTypeRE = new RegExp('^'+this.dataType+'.'); | ||
var filter = this.required ? | ||
returnTrue : reqValueNotUndefined; | ||
if (this.orTheValidations) { | ||
@@ -425,4 +423,3 @@ return step.validate(req); | ||
var keypaths = this._keys | ||
.map(keypath) | ||
.filter(filter); | ||
.map(keypath); | ||
keypaths | ||
@@ -429,0 +426,0 @@ .map(reqValueForKeypath) |
{ | ||
"name": "dat-middleware", | ||
"version": "1.6.1", | ||
"version": "1.7.0", | ||
"description": "common request, response, body, query, and param validation, transformation, and flow control middleware", | ||
@@ -27,2 +27,5 @@ "main": "index.js", | ||
"author": "Tejesh Mehta", | ||
"contributors": [ | ||
"Bryan Kendall <bryan@bryankendall.com>" | ||
], | ||
"license": "MIT", | ||
@@ -40,3 +43,3 @@ "bugs": { | ||
"map-utils": "~0.4.0", | ||
"middleware-flow": "^0.4.1" | ||
"middleware-flow": "^0.5.0" | ||
}, | ||
@@ -43,0 +46,0 @@ "devDependencies": { |
@@ -36,2 +36,32 @@ var createAppWithMiddleware = require('./fixtures/createAppWithMiddleware'); | ||
}); | ||
describe('only then, failing', function () { | ||
before(function () { | ||
this.app = createAppWithMiddleware( | ||
mw.body('nonexistant').require() | ||
.then(appendReqBody('key', '3')) | ||
); | ||
}); | ||
it('should not execute "then-middlewares" the validation passes', function (done) { | ||
request(this.app) | ||
.post('/body') | ||
.send({ key: 'val' }) | ||
.expect({ key: 'val' }) | ||
.end(done); | ||
}); | ||
}); | ||
describe('match, only then, failing', function () { | ||
before(function () { | ||
this.app = createAppWithMiddleware( | ||
mw.body('nonexistant').matches(/^nope$/) | ||
.then(appendReqBody('key', '3')) | ||
); | ||
}); | ||
it('should not execute "then-middlewares" the validation passes', function (done) { | ||
request(this.app) | ||
.post('/body') | ||
.send({ key: 'val' }) | ||
.expect({ key: 'val' }) | ||
.end(done); | ||
}); | ||
}); | ||
describe('else', function () { | ||
@@ -53,2 +83,2 @@ before(function () { | ||
}); | ||
}); | ||
}); |
@@ -20,2 +20,4 @@ var express = require('express'); | ||
middleware, | ||
middleware2, | ||
middleware3, | ||
mw.body().send()); | ||
@@ -25,2 +27,4 @@ app.all('/query', | ||
middleware, | ||
middleware2, | ||
middleware3, | ||
mw.query().send()); | ||
@@ -30,2 +34,4 @@ app.all('/headers', | ||
middleware, | ||
middleware2, | ||
middleware3, | ||
mw.headers().send()); | ||
@@ -35,2 +41,4 @@ app.all('/params/:key1?/:key2?/:key3?/:key4?/:key5?', | ||
middleware, | ||
middleware2, | ||
middleware3, | ||
mw.params().send()); | ||
@@ -37,0 +45,0 @@ return app; |
@@ -61,3 +61,3 @@ var createAppWithMiddleware = require('./fixtures/createAppWithMiddleware'); | ||
}); | ||
it('should succeed if key does not exist', function (done) { | ||
it('should fail if key does not exist', function (done) { | ||
var data = {}; | ||
@@ -72,4 +72,3 @@ var body = dataType === 'body' ? data : {}; | ||
.send(body) | ||
.expect(200) | ||
.expect(checkResponseMatch(dataType, headers, data)) | ||
.expect(400) | ||
.end(done); | ||
@@ -89,3 +88,3 @@ }); | ||
} | ||
} | ||
}; | ||
} | ||
@@ -99,3 +98,3 @@ | ||
}); | ||
it('should succeed if all keys are not included', function (done) { | ||
it('should fail if all keys are not included', function (done) { | ||
var data = {}; | ||
@@ -110,4 +109,3 @@ var body = dataType === 'body' ? data : {}; | ||
.send(body) | ||
.expect(200) | ||
.expect(checkResponseMatch(dataType, headers, data)) | ||
.expect(400) | ||
.end(done); | ||
@@ -140,3 +138,3 @@ }); | ||
.expect(function (res) { | ||
res.body.message.should.match(new RegExp(keys[1])); | ||
res.body.message.should.match(new RegExp(keys[0])); | ||
res.body.message.should.match(reRE); | ||
@@ -143,0 +141,0 @@ }) |
@@ -67,3 +67,3 @@ var createAppWithMiddleware = require('./fixtures/createAppWithMiddleware'); | ||
}); | ||
it('should succeed if key does not exist', function (done) { | ||
it('should fail if key does not exist', function (done) { | ||
var data = {}; | ||
@@ -76,3 +76,3 @@ var body = dataType === 'body' ? data : {}; | ||
.send(body) | ||
.expect(200, data) | ||
.expect(400) | ||
.end(done); | ||
@@ -89,3 +89,3 @@ }); | ||
}); | ||
it('should succeed if all keys are not included', function (done) { | ||
it('should fail if all keys are not included', function (done) { | ||
var data = {}; | ||
@@ -98,3 +98,3 @@ var body = dataType === 'body' ? data : {}; | ||
.send(body) | ||
.expect(200, data) | ||
.expect(400) | ||
.end(done); | ||
@@ -127,3 +127,3 @@ }); | ||
.expect(function (res) { | ||
res.body.message.should.match(new RegExp(keys[1])); | ||
res.body.message.should.match(new RegExp(keys[0])); | ||
res.body.message.should.match(typeRE); | ||
@@ -150,2 +150,2 @@ }) | ||
}; | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
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
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
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
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
77760
1944
5
+ Addedmiddleware-flow@0.5.1(transitive)
- Removed101@0.3.4(transitive)
- Removedamdefine@1.0.1(transitive)
- Removedassertion-error@1.0.0(transitive)
- Removedasync@0.2.100.8.0(transitive)
- Removedchai@1.10.0(transitive)
- Removeddiff@1.4.0(transitive)
- Removedesprima@1.2.5(transitive)
- Removedhandlebars@1.3.0(transitive)
- Removedlab@3.1.4(transitive)
- Removedmiddleware-flow@0.4.1(transitive)
- Removedminimist@0.0.10(transitive)
- Removedoptimist@0.3.70.6.1(transitive)
- Removedsource-map@0.1.43(transitive)
- Removeduglify-js@2.3.6(transitive)
- Removedwordwrap@0.0.3(transitive)
Updatedmiddleware-flow@^0.5.0