@@ -24,13 +24,12 @@ describe('util', () => {
24
24
it ( 'should check empty objects' , ( ) => {
25
25
expect ( util . isEmptyObjectOrNull ( null ) ) . toBeTruthy ( ) ;
26
26
expect ( util . isEmptyObjectOrNull ( { } ) ) . toBeTruthy ( ) ;
27
- expect ( util . isEmptyObjectOrNull ( [ ] ) ) . toBeTruthy ( ) ;
27
+
28
+ expect ( util . isEmptyObjectOrNull ( [ ] ) ) . toBeFalsy ( ) ;
28
29
29
30
const func = ( ) => {
30
31
return 42 ;
31
32
} ;
32
- expect ( util . isEmptyObjectOrNull ( func ) ) . toBeTruthy ( ) ;
33
- func . foo = 'bar' ;
34
33
expect ( util . isEmptyObjectOrNull ( func ) ) . toBeFalsy ( ) ;
35
34
36
35
expect ( util . isEmptyObjectOrNull ( ) ) . toBeFalsy ( ) ;
@@ -74,6 +73,26 @@ describe('util', () => {
74
73
verifyInvalidCypherStatement ( console . log ) ;
75
74
} ) ;
76
75
76
+ it ( 'should check valid query parameters' , ( ) => {
77
+ verifyValidQueryParameters ( null ) ;
78
+ verifyValidQueryParameters ( undefined ) ;
79
+ verifyValidQueryParameters ( { } ) ;
80
+ verifyValidQueryParameters ( { a : 1 , b : 2 , c : 3 } ) ;
81
+ verifyValidQueryParameters ( { foo : 'bar' , baz : 'qux' } ) ;
82
+ } ) ;
83
+
84
+ it ( 'should check invalid query parameters' , ( ) => {
85
+ verifyInvalidQueryParameters ( 'parameter' ) ;
86
+ verifyInvalidQueryParameters ( 123 ) ;
87
+ verifyInvalidQueryParameters ( [ ] ) ;
88
+ verifyInvalidQueryParameters ( [ 1 , 2 , 3 ] ) ;
89
+ verifyInvalidQueryParameters ( [ null ] ) ;
90
+ verifyInvalidQueryParameters ( [ '1' , '2' , '3' ] ) ;
91
+ verifyInvalidQueryParameters ( ( ) => [ 1 , 2 , 3 ] ) ;
92
+ verifyInvalidQueryParameters ( ( ) => '' ) ;
93
+ verifyInvalidQueryParameters ( ( ) => null ) ;
94
+ } ) ;
95
+
77
96
function verifyValidString ( str ) {
78
97
expect ( util . assertString ( str , 'Test string' ) ) . toBe ( str ) ;
79
98
}
@@ -83,7 +102,15 @@ describe('util', () => {
83
102
}
84
103
85
104
function verifyInvalidCypherStatement ( str ) {
86
- expect ( ( ) => util . assertCypherStatement ( str ) ) . toThrowError ( TypeError ) ;
105
+ expect ( ( ) => util . validateStatementAndParameters ( str , { } ) ) . toThrowError ( TypeError ) ;
106
+ }
107
+
108
+ function verifyValidQueryParameters ( obj ) {
109
+ expect ( ( ) => util . validateStatementAndParameters ( 'RETURN 1' , obj ) ) . not . toThrow ( ) ;
110
+ }
111
+
112
+ function verifyInvalidQueryParameters ( obj ) {
113
+ expect ( ( ) => util . validateStatementAndParameters ( 'RETURN 1' , obj ) ) . toThrowError ( TypeError ) ;
87
114
}
88
115
89
116
} ) ;
0 commit comments