-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathtest.ts
More file actions
116 lines (102 loc) · 4.4 KB
/
test.ts
File metadata and controls
116 lines (102 loc) · 4.4 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/* eslint-disable @typescript-eslint/no-var-requires */
import * as DataFormat from '../src/index';
/* eslint-disable @typescript-eslint/no-unused-expressions */
describe('Request Network Data Validator', () => {
it('should validate a correct invoice 0.0.1 format', async () => {
const dataJson = require('./data/example-valid-0.0.1.json');
const result = DataFormat.validate(dataJson);
// 'result.valid should be true'
expect(result.valid).toBe(true);
});
it('should validate a correct invoice 0.0.2 format', () => {
const dataJson = require('./data/example-valid-0.0.2.json');
const result = DataFormat.validate(dataJson);
// 'result.valid should be true'
expect(result.valid).toBe(true);
});
it('should validate a correct invoice 0.0.3 format', () => {
const dataJson = require('./data/example-valid-0.0.3.json');
const result = DataFormat.validate(dataJson);
// 'result.valid should be true'
expect(result.valid).toBe(true);
});
it('should not validate an invalid invoice 0.0.2 format', () => {
const dataJson = require('./data/example-invalid-0.0.2.json');
const result = DataFormat.validate(dataJson);
// 'result.valid should be false'
expect(result.valid).toBe(false);
// 'result.errors is wrong'
expect(result.errors[0].message).toBe('must be string');
});
it('should not validate an invalid invoice 0.0.3 format', () => {
const dataJson = require('./data/example-invalid-0.0.3.json');
const result = DataFormat.validate(dataJson);
// 'result.valid should be false'
expect(result.valid).toBe(false);
// 'result.errors is wrong'
expect(result.errors[0].message).toBe('must be string');
});
it('should not validate a json without meta', () => {
const dataJson = require('./data/example-no-meta.json');
const result = DataFormat.validate(dataJson);
// 'result.valid should be false'
expect(result.valid).toBe(false);
// 'result.errors is wrong'
expect(result.errors[0].message).toBe('meta not found');
});
it('should not validate a json with meta unknown', () => {
const dataJson = require('./data/example-meta-unknown.json');
const result = DataFormat.validate(dataJson);
// 'result.valid should be false'
expect(result.valid).toBe(false);
// 'result.errors is wrong'
expect(result.errors[0].message).toBe('format not found');
});
it('should not validate a json with schema error', () => {
const dataJson = require('./data/example-schema-errors.json');
const result = DataFormat.validate(dataJson);
// 'result.valid should be false'
expect(result.valid).toBe(false);
// 'result.errors is wrong'
expect(result.errors[0].message).toBe('must match format "date-time"');
});
it('should not validate a json with required parameter missing', () => {
const dataJson = require('./data/example-schema-missing.json');
const result = DataFormat.validate(dataJson);
// 'result.valid should be false'
expect(result.valid).toBe(false);
// 'result.errors is wrong'
expect(result.errors[0].message).toBe(`must have required property \'name\'`);
});
it('should not validate a json with meta.format missing', () => {
const dataJson = { meta: {} };
const result = DataFormat.validate(dataJson);
// 'result.valid should be false'
expect(result.valid).toBe(false);
// 'result.errors is wrong'
expect(result.errors[0].message).toBe('meta.format not found');
});
it('should not validate a json with meta.version missing', () => {
const dataJson = { meta: { format: 'rnf_invoice' } };
const result = DataFormat.validate(dataJson);
// 'result.valid should be false'
expect(result.valid).toBe(false);
// 'result.errors is wrong'
expect(result.errors[0].message).toBe('meta.version not found');
});
it('should not know a json with meta.format unknown', () => {
const dataJson = { meta: { format: 'rnf-unknown' } };
// 'should be false'
expect(DataFormat.isKnownFormat(dataJson)).toBe(false);
});
it('should know a valid json', () => {
const dataJson = require('./data/example-valid-0.0.1.json');
// 'should be true'
expect(DataFormat.isKnownFormat(dataJson)).toBe(true);
});
it('should not know an unvalid json but with format known', () => {
const dataJson = { meta: { format: 'rnf_invoice' } };
// 'should be true'
expect(DataFormat.isKnownFormat(dataJson)).toBe(true);
});
});