-
Notifications
You must be signed in to change notification settings - Fork 10
/
indonesia-id-card-number-province.spec.js
79 lines (60 loc) · 2.33 KB
/
indonesia-id-card-number-province.spec.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { expect } from 'chai';
import validator from '../../lib';
describe('Indonesia id card number province validator', () => {
const rules = {
idCard: ['indonesiaIdCardNumberProvince:province']
};
it('should success when given empty id card', () => {
const result = validator.validate(rules, {});
const err = result.messages;
expect(result.success).to.equal(true);
expect(err).to.not.have.property('indonesiaIdCardNumberProvince:$1');
});
it('should success when id card province code matches province code', () => {
const result = validator.validate(rules, {
idCard: '1100000000000000',
province: 'ACEH'
});
const err = result.messages;
expect(result.success).to.equal(true);
expect(err).to.not.have.property('idCard');
});
it('should success when id card province code matches province code (inputted province is not upper case)', () => {
const result = validator.validate(rules, {
idCard: '1100000000000000',
province: 'aceh'
});
const err = result.messages;
expect(result.success).to.equal(true);
expect(err).to.not.have.property('idCard');
});
it('should fail when id card province code does not match province code', () => {
const result = validator.validate(rules, {
idCard: '1100000000000000',
province: 'RIAU'
});
const err = result.messages;
expect(result.success).to.equal(false);
expect(err.idCard).to.have.property('indonesiaIdCardNumberProvince:$1')
.that.equals('Id Card province code does not match province input.');
});
it('should fail when province is invalid', () => {
const result = validator.validate(rules, {
idCard: '1100000000000000',
province: 'DI ACEH'
});
const err = result.messages;
expect(result.success).to.equal(false);
expect(err.idCard).to.have.property('indonesiaIdCardNumberProvince:$1')
.that.equals('Id Card province code does not match province input.');
});
it('should fail when no province is given', () => {
const result = validator.validate(rules, {
idCard: '1100000000000000'
});
const err = result.messages;
expect(result.success).to.equal(false);
expect(err.idCard).to.have.property('indonesiaIdCardNumberProvince:$1')
.that.equals('Id Card province code does not match province input.');
});
});