@@ -24,13 +24,12 @@ describe('util', () => {
2424 it ( 'should check empty objects' , ( ) => {
2525 expect ( util . isEmptyObjectOrNull ( null ) ) . toBeTruthy ( ) ;
2626 expect ( util . isEmptyObjectOrNull ( { } ) ) . toBeTruthy ( ) ;
27- expect ( util . isEmptyObjectOrNull ( [ ] ) ) . toBeTruthy ( ) ;
27+
28+ expect ( util . isEmptyObjectOrNull ( [ ] ) ) . toBeFalsy ( ) ;
2829
2930 const func = ( ) => {
3031 return 42 ;
3132 } ;
32- expect ( util . isEmptyObjectOrNull ( func ) ) . toBeTruthy ( ) ;
33- func . foo = 'bar' ;
3433 expect ( util . isEmptyObjectOrNull ( func ) ) . toBeFalsy ( ) ;
3534
3635 expect ( util . isEmptyObjectOrNull ( ) ) . toBeFalsy ( ) ;
@@ -74,6 +73,26 @@ describe('util', () => {
7473 verifyInvalidCypherStatement ( console . log ) ;
7574 } ) ;
7675
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+
7796 function verifyValidString ( str ) {
7897 expect ( util . assertString ( str , 'Test string' ) ) . toBe ( str ) ;
7998 }
@@ -83,7 +102,15 @@ describe('util', () => {
83102 }
84103
85104 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 ) ;
87114 }
88115
89116} ) ;
0 commit comments