1 | if (typeof require !== 'undefined') {
|
2 | var Validator = require('../src/validator.js');
|
3 | var expect = require('chai').expect;
|
4 | } else {
|
5 | var Validator = window.Validator;
|
6 | var expect = window.chai.expect;
|
7 | }
|
8 |
|
9 | describe('different validation rule', function() {
|
10 | it('should fail when the 2 attributes are the same', function() {
|
11 | var validator = new Validator({
|
12 | field1: 'abc',
|
13 | field2: 'abc'
|
14 | }, {
|
15 | field2: 'different:field1'
|
16 | });
|
17 | expect(validator.passes()).to.be.false;
|
18 | expect(validator.fails()).to.be.true;
|
19 | });
|
20 |
|
21 | it('should pass when the 2 attributes are different', function() {
|
22 | var validator = new Validator({
|
23 | field1: 'abc',
|
24 | field2: 'abcd'
|
25 | }, {
|
26 | field2: 'different:field1'
|
27 | });
|
28 | expect(validator.passes()).to.be.true;
|
29 | expect(validator.fails()).to.be.false;
|
30 | });
|
31 |
|
32 | it('should pass if one of the 2 attributes is a nested path', function() {
|
33 | var validator = new Validator({
|
34 | payload: {
|
35 | pw: 'abc123',
|
36 | username: 'test123',
|
37 | },
|
38 | username: 'test',
|
39 | }, {
|
40 | username: 'different:payload.username'
|
41 | });
|
42 | expect(validator.passes()).to.be.true;
|
43 | expect(validator.fails()).to.be.false;
|
44 | });
|
45 |
|
46 | it('should fail if one of the 2 attributes is an invalid nested path', function() {
|
47 | var validator = new Validator({
|
48 | payload: {
|
49 | pw: 'abc123',
|
50 | username: 'test123',
|
51 | },
|
52 | username: 'test123',
|
53 | }, {
|
54 | username: 'different:payload.username'
|
55 | });
|
56 | expect(validator.fails()).to.be.true;
|
57 | expect(validator.passes()).to.be.false;
|
58 | expect(validator.errors.first('username')).to.equal('The username and payload.username must be different.');
|
59 | });
|
60 | });
|