-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathvars.js
36 lines (32 loc) · 1.03 KB
/
vars.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
var expect = require('chai').expect
, Schema = require('../../index')
, Model = require('../fixtures/model')
, descriptor = require('../fixtures/schema/vars');
describe('async-validate:', function() {
before(function(done) {
// load plugin definition
Schema.plugin([require('../fixtures/vars-plugin')]);
done();
});
it('should error with vars option and missing id', function(done) {
var schema = new Schema(descriptor)
, opts = {vars: {model: new Model()}}
, source = {id: 'qux'};
schema.validate(source, opts, function(err, res) {
expect(res.errors.length).to.eql(1);
expect(res.errors[0].message).to.eql(
'user not found for id qux');
done();
});
});
it('should validate with vars option', function(done) {
var schema = new Schema(descriptor)
, opts = {vars: {model: new Model()}}
, source = {id: 'foo'};
schema.validate(source, opts, function(err, res) {
expect(err).to.eql(null);
expect(res).to.eql(null);
done();
});
});
});