123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- var assert = require('assert');
- var M = require('../lib/Machine.constructor');
- describe('Custom `validate()` for an input', function() {
- ////////////////////////////////
- // Valid
- ////////////////////////////////
- it('should run when validate returns true', function(done) {
- var machine = {
- inputs: {
- foo: {
- validate: function(inputs, env) {
- return true;
- }
- }
- },
- exits: {
- success: {},
- error: {}
- },
- fn: function (inputs, exits, deps) {
- exits();
- }
- };
- M.build(machine)
- .configure({
- foo: {
- bar: 'hello',
- baz: 123
- }
- })
- .exec(function(err, result) {
- if(err) return done(err);
- done();
- });
- });
- ////////////////////////////////
- // Invalid
- ////////////////////////////////
- it('should fail when validate returns false', function(done) {
- var machine = {
- inputs: {
- foo: {
- validate: function(inputs, env) {
- return false;
- }
- }
- },
- exits: {
- success: {},
- error: {}
- },
- fn: function (inputs, exits, deps) {
- exits();
- }
- };
- M.build(machine)
- .configure({
- foo: {
- bar: 'hello',
- foo: 123
- }
- })
- .exec(function(err, result) {
- assert(err);
- done();
- });
- });
- it('should fail when an input is defined with a valid key', function() {
- var machine = {
- inputs: {
- foo: {
- valid: true
- }
- },
- exits: {
- success: {},
- error: {}
- },
- fn: function (inputs, exits, deps) {
- exits();
- }
- };
- assert.throws(function() {
- M.build(machine);
- });
- });
- });
|