1
1
const { generateSchema } = require ( '../../../lib/schema-generator/index' )
2
- const Ajv = require ( " ajv" )
2
+ const Ajv = require ( ' ajv' )
3
3
const validator = new Ajv ( )
4
4
5
5
const TESTCASES = [
@@ -9,91 +9,90 @@ const TESTCASES = [
9
9
true ,
10
10
null ,
11
11
{ } ,
12
- { a : 1 , b : 2 , c : null , d : [ 1 , 2 , 3 ] } ,
13
- { a : { b : { c : 1 } } } ,
12
+ { a : 1 , b : 2 , c : null , d : [ 1 , 2 , 3 ] } ,
13
+ { a : { b : { c : 1 } } } ,
14
14
[ ] ,
15
- [ 1 , 2 , 3 ] ,
16
- [ 'a' , 'b' , 'c' ] ,
15
+ [ 1 , 2 , 3 ] ,
16
+ [ 'a' , 'b' , 'c' ] ,
17
17
[ true , 'a' , 1 ] ,
18
- [ { a : 1 } , { b : 'abc' } ] ,
18
+ [ { a : 1 } , { b : 'abc' } ] ,
19
19
{
20
- "Account" : {
21
- "Account Name" : "Firefly" ,
22
- "Order" : [
23
- {
24
- "OrderID" : "order103" ,
25
- "Product" : [
20
+ Account : {
21
+ 'Account Name' : 'Firefly' ,
22
+ Order : [
26
23
{
27
- "Product Name" : "Bowler Hat" ,
28
- "ProductID" : 858383 ,
29
- "SKU" : "0406654608" ,
30
- "Description" : {
31
- "Colour" : "Purple" ,
32
- "Width" : 300 ,
33
- "Height" : 200 ,
34
- "Depth" : 210 ,
35
- "Weight" : 0.75
36
- } ,
37
- "Price" : 34.45 ,
38
- "Quantity" : 2
24
+ OrderID : 'order103' ,
25
+ Product : [
26
+ {
27
+ 'Product Name' : 'Bowler Hat' ,
28
+ ProductID : 858383 ,
29
+ SKU : '0406654608' ,
30
+ Description : {
31
+ Colour : 'Purple' ,
32
+ Width : 300 ,
33
+ Height : 200 ,
34
+ Depth : 210 ,
35
+ Weight : 0.75
36
+ } ,
37
+ Price : 34.45 ,
38
+ Quantity : 2
39
+ } ,
40
+ {
41
+ 'Product Name' : 'Trilby hat' ,
42
+ ProductID : 858236 ,
43
+ SKU : '0406634348' ,
44
+ Description : {
45
+ Colour : 'Orange' ,
46
+ Width : 300 ,
47
+ Height : 200 ,
48
+ Depth : 210 ,
49
+ Weight : 0.6
50
+ } ,
51
+ Price : 21.67 ,
52
+ Quantity : 1
53
+ }
54
+ ]
39
55
} ,
40
56
{
41
- "Product Name" : "Trilby hat" ,
42
- "ProductID" : 858236 ,
43
- "SKU" : "0406634348" ,
44
- "Description" : {
45
- "Colour" : "Orange" ,
46
- "Width" : 300 ,
47
- "Height" : 200 ,
48
- "Depth" : 210 ,
49
- "Weight" : 0.6
50
- } ,
51
- "Price" : 21.67 ,
52
- "Quantity" : 1
57
+ OrderID : 'order104' ,
58
+ Product : [
59
+ {
60
+ 'Product Name' : 'Bowler Hat' ,
61
+ ProductID : 858383 ,
62
+ SKU : '040657863' ,
63
+ Description : {
64
+ Colour : 'Purple' ,
65
+ Width : 300 ,
66
+ Height : 200 ,
67
+ Depth : 210 ,
68
+ Weight : 0.75
69
+ } ,
70
+ Price : 34.45 ,
71
+ Quantity : 4
72
+ } ,
73
+ {
74
+ ProductID : 345664 ,
75
+ SKU : '0406654603' ,
76
+ 'Product Name' : 'Cloak' ,
77
+ Description : {
78
+ Colour : 'Black' ,
79
+ Width : 30 ,
80
+ Height : 20 ,
81
+ Depth : 210 ,
82
+ Weight : 2
83
+ } ,
84
+ Price : 107.99 ,
85
+ Quantity : 1
86
+ }
87
+ ]
53
88
}
54
- ]
55
- } ,
56
- {
57
- "OrderID" : "order104" ,
58
- "Product" : [
59
- {
60
- "Product Name" : "Bowler Hat" ,
61
- "ProductID" : 858383 ,
62
- "SKU" : "040657863" ,
63
- "Description" : {
64
- "Colour" : "Purple" ,
65
- "Width" : 300 ,
66
- "Height" : 200 ,
67
- "Depth" : 210 ,
68
- "Weight" : 0.75
69
- } ,
70
- "Price" : 34.45 ,
71
- "Quantity" : 4
72
- } ,
73
- {
74
- "ProductID" : 345664 ,
75
- "SKU" : "0406654603" ,
76
- "Product Name" : "Cloak" ,
77
- "Description" : {
78
- "Colour" : "Black" ,
79
- "Width" : 30 ,
80
- "Height" : 20 ,
81
- "Depth" : 210 ,
82
- "Weight" : 2
83
- } ,
84
- "Price" : 107.99 ,
85
- "Quantity" : 1
86
- }
87
- ]
88
- }
89
- ]
89
+ ]
90
90
}
91
- }
91
+ }
92
92
]
93
93
94
94
describe ( 'Schema Generator' , function ( ) {
95
-
96
- TESTCASES . forEach ( ( value , index ) => {
95
+ TESTCASES . forEach ( ( value , index ) => {
97
96
it ( 'generates valid schema ' + index , function ( ) {
98
97
const schema = generateSchema ( value )
99
98
const validate = validator . compile ( schema )
@@ -107,4 +106,3 @@ describe('Schema Generator', function () {
107
106
} )
108
107
} )
109
108
} )
110
-
0 commit comments