@@ -16,6 +16,8 @@ import {
1616 EsDataTypeRangeTerm ,
1717 EsDataTypeSingle ,
1818 EsDataTypeUnion ,
19+ ExceptionListTypeEnum ,
20+ OperatorEnum ,
1921 Type ,
2022 esDataTypeGeoPoint ,
2123 esDataTypeGeoPointRange ,
@@ -25,60 +27,10 @@ import {
2527 esDataTypeUnion ,
2628 exceptionListType ,
2729 operator ,
28- operator_type as operatorType ,
2930 type ,
3031} from './schemas' ;
3132
3233describe ( 'Common schemas' , ( ) => {
33- describe ( 'operatorType' , ( ) => {
34- test ( 'it should validate for "match"' , ( ) => {
35- const payload = 'match' ;
36- const decoded = operatorType . decode ( payload ) ;
37- const message = pipe ( decoded , foldLeftRight ) ;
38-
39- expect ( getPaths ( left ( message . errors ) ) ) . toEqual ( [ ] ) ;
40- expect ( message . schema ) . toEqual ( payload ) ;
41- } ) ;
42-
43- test ( 'it should validate for "match_any"' , ( ) => {
44- const payload = 'match_any' ;
45- const decoded = operatorType . decode ( payload ) ;
46- const message = pipe ( decoded , foldLeftRight ) ;
47-
48- expect ( getPaths ( left ( message . errors ) ) ) . toEqual ( [ ] ) ;
49- expect ( message . schema ) . toEqual ( payload ) ;
50- } ) ;
51-
52- test ( 'it should validate for "list"' , ( ) => {
53- const payload = 'list' ;
54- const decoded = operatorType . decode ( payload ) ;
55- const message = pipe ( decoded , foldLeftRight ) ;
56-
57- expect ( getPaths ( left ( message . errors ) ) ) . toEqual ( [ ] ) ;
58- expect ( message . schema ) . toEqual ( payload ) ;
59- } ) ;
60-
61- test ( 'it should validate for "exists"' , ( ) => {
62- const payload = 'exists' ;
63- const decoded = operatorType . decode ( payload ) ;
64- const message = pipe ( decoded , foldLeftRight ) ;
65-
66- expect ( getPaths ( left ( message . errors ) ) ) . toEqual ( [ ] ) ;
67- expect ( message . schema ) . toEqual ( payload ) ;
68- } ) ;
69-
70- test ( 'it should contain 4 keys' , ( ) => {
71- // Might seem like a weird test, but its meant to
72- // ensure that if operatorType is updated, you
73- // also update the OperatorTypeEnum, a workaround
74- // for io-ts not yet supporting enums
75- // https://github.com/gcanti/io-ts/issues/67
76- const keys = Object . keys ( operatorType . keys ) ;
77-
78- expect ( keys . length ) . toEqual ( 4 ) ;
79- } ) ;
80- } ) ;
81-
8234 describe ( 'operator' , ( ) => {
8335 test ( 'it should validate for "included"' , ( ) => {
8436 const payload = 'included' ;
@@ -98,15 +50,16 @@ describe('Common schemas', () => {
9850 expect ( message . schema ) . toEqual ( payload ) ;
9951 } ) ;
10052
101- test ( 'it should contain 2 keys' , ( ) => {
53+ test ( 'it should contain same amount of keys as enum ' , ( ) => {
10254 // Might seem like a weird test, but its meant to
10355 // ensure that if operator is updated, you
10456 // also update the operatorEnum, a workaround
10557 // for io-ts not yet supporting enums
10658 // https://github.com/gcanti/io-ts/issues/67
107- const keys = Object . keys ( operator . keys ) ;
59+ const keys = Object . keys ( operator . keys ) . sort ( ) . join ( ',' ) . toLowerCase ( ) ;
60+ const enumKeys = Object . keys ( OperatorEnum ) . sort ( ) . join ( ',' ) . toLowerCase ( ) ;
10861
109- expect ( keys . length ) . toEqual ( 2 ) ;
62+ expect ( keys ) . toEqual ( enumKeys ) ;
11063 } ) ;
11164 } ) ;
11265
@@ -129,15 +82,16 @@ describe('Common schemas', () => {
12982 expect ( message . schema ) . toEqual ( payload ) ;
13083 } ) ;
13184
132- test ( 'it should contain 2 keys' , ( ) => {
85+ test ( 'it should contain same amount of keys as enum ' , ( ) => {
13386 // Might seem like a weird test, but its meant to
13487 // ensure that if exceptionListType is updated, you
13588 // also update the ExceptionListTypeEnum, a workaround
13689 // for io-ts not yet supporting enums
13790 // https://github.com/gcanti/io-ts/issues/67
138- const keys = Object . keys ( exceptionListType . keys ) ;
91+ const keys = Object . keys ( exceptionListType . keys ) . sort ( ) . join ( ',' ) . toLowerCase ( ) ;
92+ const enumKeys = Object . keys ( ExceptionListTypeEnum ) . sort ( ) . join ( ',' ) . toLowerCase ( ) ;
13993
140- expect ( keys . length ) . toEqual ( 2 ) ;
94+ expect ( keys ) . toEqual ( enumKeys ) ;
14195 } ) ;
14296 } ) ;
14397
0 commit comments