-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
70 lines (56 loc) · 1.83 KB
/
index.test.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
import {
error,
isValid,
splitContainerNumber,
getCheckDigit,
getContainerNumberWithoutCheckDigit,
getNumericalValues,
calculateCheckDigit,
validation
} from './index';
describe('isValid', () => {
it('Shoud match container number pattern', () => {
expect(isValid('')).toBe(false);
expect(isValid('dfsj7122007')).toBe(false);
expect(isValid('dfsu7122007')).toBe(true);
expect(isValid('cmau0902910')).toBe(true);
});
});
describe('splitContainerNumber', () => {
it('Should split container number to diffrent part', () => {
expect(splitContainerNumber('')).toBe(error('invalidContainerNumber'));
expect(splitContainerNumber('dfsu7162007')).toEqual({
ownerCode: 'dfs',
productGroupCode: 'u',
registration: '716200',
checkDigit: '7'
});
expect(splitContainerNumber('cmau0902910')).toEqual({
ownerCode: 'cma',
productGroupCode: 'u',
registration: '090291',
checkDigit: '0'
});
});
});
test('getCheckDigit', () => {
expect(getCheckDigit('cmau0902910')).toBe(0);
});
test('getContainerNumberWithoutCheckDigit', ()=>{
expect(getContainerNumberWithoutCheckDigit('dfsu7162007')).toBe('dfsu716200');
});
test('getNumericalValues', ()=>{
expect(getNumericalValues('dfsu7162007')).toEqual([14,16,30,32,7,1,6,2,0,0]);
expect(getNumericalValues('dfsu716200')).toEqual([14,16,30,32,7,1,6,2,0,0]);
});
test('calculateCheckDigit', () => {
expect(calculateCheckDigit('dfsu7162007')).toBe(7);
expect(calculateCheckDigit('cmau0902910')).toBe(0);
expect(calculateCheckDigit('cmau090291')).toBe(0);
expect(calculateCheckDigit('dfsu716200')).toBe(7);
});
test('validation', () => {
expect(validation('dfsu7162007').valid).toBe(true);
expect(validation('dfsu7162008').valid).toBe(false);
expect(validation('cmau0902910').valid).toBe(true);
});