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('not_in validation rule', function() {
|
10 | it('should fail the value is in the set of comma separated values', function() {
|
11 | var validator = new Validator({
|
12 | username: 'skaterdav85'
|
13 | }, {
|
14 | username: 'not_in:skaterdav85,dtang,dtang85'
|
15 | });
|
16 | expect(validator.passes()).to.be.false;
|
17 | expect(validator.fails()).to.be.true;
|
18 | expect(validator.errors.first('username')).to.equal('The selected username is invalid.');
|
19 | });
|
20 |
|
21 | it('should pass when the value is not in the set of comma separated values', function() {
|
22 | var validator = new Validator({
|
23 | username: 'skatedav85'
|
24 | }, {
|
25 | username: 'not_in:user1,user2,user3'
|
26 | });
|
27 | expect(validator.passes()).to.be.true;
|
28 | expect(validator.fails()).to.be.false;
|
29 | });
|
30 |
|
31 | it('should fail when the numeric value is in the set of comma separated values', function() {
|
32 | var validator = new Validator({
|
33 | id: 1
|
34 | }, {
|
35 | id: 'not_in:0,1,2'
|
36 | });
|
37 | expect(validator.passes()).to.be.false;
|
38 | expect(validator.fails()).to.be.true;
|
39 | expect(validator.errors.first('id')).to.equal('The selected id is invalid.');
|
40 | });
|
41 |
|
42 | it('should pass when the value is not in the set of comma separated values', function() {
|
43 | var validator = new Validator({
|
44 | id: 10
|
45 | }, {
|
46 | id: 'not_in:0,1,2'
|
47 | });
|
48 | expect(validator.passes()).to.be.true;
|
49 | expect(validator.fails()).to.be.false;
|
50 | });
|
51 |
|
52 | it('should pass when the value is undefined', function() {
|
53 | var validator = new Validator({}, {
|
54 | country: 'not_in:China,Spain,France'
|
55 | });
|
56 | expect(validator.passes()).to.be.true;
|
57 | expect(validator.fails()).to.be.false;
|
58 | });
|
59 |
|
60 | it('should pass when the value is an empty string', function() {
|
61 | var validator = new Validator({
|
62 | country: ''
|
63 | }, {
|
64 | country: 'not_in:China,Spain,France'
|
65 | });
|
66 | expect(validator.passes()).to.be.true;
|
67 | expect(validator.fails()).to.be.false;
|
68 | });
|
69 | });
|