hmpo-form-controller
Advanced tools
Comparing version 0.3.0 to 0.4.0
var _ = require('underscore'); | ||
function FormError(key, options) { | ||
function FormError(key, options/*, req*/) { | ||
options = _.extend({ | ||
@@ -5,0 +5,0 @@ type: 'default' |
@@ -120,5 +120,5 @@ /*eslint no-unused-vars: [2, {"vars": "all", "args": "none"}]*/ | ||
if (error.group) { | ||
errors[error.group] = new this.Error(error.group, error); | ||
errors[error.group] = new this.Error(error.group, error, req); | ||
} else { | ||
errors[error.key] = new this.Error(error.key, error); | ||
errors[error.key] = new this.Error(error.key, error, req); | ||
} | ||
@@ -173,7 +173,10 @@ } | ||
var redirect = req.path; | ||
var redirectedError = _.find(err, function (error) { | ||
var redirectError = _.all(err, function (error) { | ||
return error.redirect; | ||
}); | ||
if (redirectedError) { | ||
redirect = redirectedError.redirect; | ||
if (redirectError) { | ||
redirect = _.find(err, function (error) { | ||
return error.redirect; | ||
}).redirect; | ||
} | ||
@@ -180,0 +183,0 @@ if (req.baseUrl !== '/') { |
{ | ||
"name": "hmpo-form-controller", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -436,2 +436,25 @@ var Form = require('../../'); | ||
it('creates instances of Error class with validation errors', function (done) { | ||
validators.required.returns(false); | ||
req.body = { field: 'value', email: 'foo', name: 'John' }; | ||
form.post(req, res, function (err) { | ||
_.each(err, function (e) { | ||
e.should.be.an.instanceOf(form.Error); | ||
}); | ||
done(); | ||
}); | ||
}); | ||
it('passes the request object into error constructor', function (done) { | ||
sinon.stub(form, 'Error'); | ||
validators.required.returns(false); | ||
req.body = { field: 'value', email: 'foo', name: 'John' }; | ||
form.post(req, res, function (err) { | ||
form.Error.should.have.been.calledWithExactly('field', sinon.match({ type: 'required' }), req); | ||
form.Error.should.have.been.calledWithExactly('email', sinon.match({ type: 'required' }), req); | ||
form.Error.should.have.been.calledWithExactly('name', sinon.match({ type: 'required' }), req); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
@@ -539,3 +562,12 @@ | ||
it('redirects to error redirect if any error has a redirect property', function () { | ||
it('redirects to req.path if not all errors have a redirect value', function () { | ||
err = { | ||
'field-a': new Form.Error('field-a'), | ||
'field-b': new Form.Error('field-b', { redirect: '/exitpage' }) | ||
}; | ||
form.errorHandler(err, req, res); | ||
res.redirect.should.have.been.calledWith('/index'); | ||
}); | ||
it('redirects to error redirect if all errors have a redirect value', function () { | ||
err.redirect = '/exitpage'; | ||
@@ -542,0 +574,0 @@ form.errorHandler({ field: err }, req, res); |
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
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
67880
20
1667
0