Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hmpo-form-controller

Package Overview
Dependencies
Maintainers
3
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hmpo-form-controller - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

9

lib/form.js

@@ -52,3 +52,3 @@ var util = require('util'),

}
res.render(this.options.template, _.extend({
_.extend(res.locals, {
errors: errors,

@@ -58,3 +58,4 @@ errorlist: _.map(errors, _.identity),

options: this.options
}, this.locals(req, res)));
}, this.locals(req, res));
this.render(req, res, callback);
}.bind(this));

@@ -64,2 +65,3 @@ },

debug('Received POST for ' + req.path);
this.setErrors(null, req, res);
this._process(req, res, function (err) {

@@ -90,2 +92,5 @@ if (err) {

},
render: function (req, res/*, callback*/) {
res.render(this.options.template);
},
// placeholder methods for persisting error messages between POST and GET

@@ -92,0 +97,0 @@ getErrors: function (/*req, res*/) {

{
"name": "hmpo-form-controller",
"version": "0.0.1",
"version": "0.0.2",
"description": "",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -122,3 +122,4 @@ var Form = require('../../');

res = {
render: sinon.stub()
render: sinon.stub(),
locals: {}
};

@@ -128,2 +129,3 @@ cb = sinon.stub();

sinon.stub(Form.prototype, 'getErrors').returns({});
sinon.stub(Form.prototype, 'render');
});

@@ -134,2 +136,3 @@

Form.prototype.getErrors.restore();
Form.prototype.render.restore();
});

@@ -143,18 +146,12 @@

it('renders the provided template', function () {
form = new Form({ template: 'test' });
it('calls form.render', function () {
form.get(req, res, cb);
res.render.should.have.been.calledWith('test');
form.render.should.have.been.calledOnce;
form.render.should.have.been.calledWithExactly(req, res, cb);
});
it('if path is "/" and no template is provided uses "index for template', function () {
form = new Form({ template: 'index' });
form.get(req, res, cb);
res.render.should.have.been.calledWith('index');
});
it('passes any errors to the rendered template', function () {
form.getErrors.returns({ field: { message: 'error' } });
form.get(req, res, cb);
res.render.args[0][1].errors.should.eql({ field: { message: 'error' } });
res.locals.errors.should.eql({ field: { message: 'error' } });
});

@@ -166,3 +163,3 @@

form.get(req, res, cb);
res.render.args[0][1].values.should.eql({ values: [1] });
res.locals.values.should.eql({ values: [1] });
});

@@ -180,3 +177,3 @@

form.get(req, res, cb);
res.render.args[0][1].options.should.eql(form.options);
res.locals.options.should.eql(form.options);
});

@@ -235,2 +232,3 @@

sinon.stub(Form.prototype, 'validate').yields(null);
sinon.stub(Form.prototype, 'setErrors');
sinon.stub(Form.prototype, 'saveValues').yields(null);

@@ -245,2 +243,3 @@ sinon.stub(Form.prototype, 'successHandler');

Form.prototype.validate.restore();
Form.prototype.setErrors.restore();
Form.prototype.saveValues.restore();

@@ -264,2 +263,7 @@ Form.prototype.successHandler.restore();

it('sets errors to null', function () {
form.post(req, res, cb);
form.setErrors.should.have.been.calledWithExactly(null, req, res);
});
it('call callback with error if _process fails', function () {

@@ -407,2 +411,27 @@ var cb = sinon.stub();

describe('render', function () {
var form, req, res, cb;
beforeEach(function () {
form = new Form({
template: 'index',
next: '/next',
fields: {
field: 'name'
}
});
res = {
render: sinon.stub()
};
cb = sinon.stub();
});
it('renders the provided template', function () {
form.render(req, res, cb);
res.render.should.have.been.calledWith('index');
});
});
describe('successHandler', function () {

@@ -409,0 +438,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc