@@ -41,19 +41,19 @@ module.exports = function () {
4141 var map = { } ;
4242 for ( var i = 0 ; i < size ; i ++ ) {
4343 if ( type === 'String' ) {
44- map [ "a" + tempSizeOfObject ( this . M ) ] = stringOfSize ( 3 ) ;
44+ map [ "a" + sizeOfObject ( this . M ) ] = stringOfSize ( 3 ) ;
4545 }
4646 if ( type === 'Integer' ) {
47- map [ "a" + tempSizeOfObject ( this . M ) ] = randomInt ( ) ;
47+ map [ "a" + sizeOfObject ( this . M ) ] = randomInt ( ) ;
4848 }
4949 if ( type === 'Boolean' ) {
50- map [ "a" + tempSizeOfObject ( this . M ) ] = randomBool ( ) ;
50+ map [ "a" + sizeOfObject ( this . M ) ] = randomBool ( ) ;
5151 }
5252 if ( type === 'Float' ) {
53- map [ "a" + tempSizeOfObject ( this . M ) ] = randomFloat ( ) ;
53+ map [ "a" + sizeOfObject ( this . M ) ] = randomFloat ( ) ;
5454 }
5555 if ( type === 'Null' ) {
56- map [ "a" + tempSizeOfObject ( this . M ) ] = null ;
56+ map [ "a" + sizeOfObject ( this . M ) ] = null ;
5757 }
5858 }
5959 this . expectedValue = map ;
@@ -96,71 +96,58 @@ module.exports = function () {
9696 this . Given ( / ^ a d d i n g a t a b l e o f v a l u e s t o t h e m a p M $ / , function ( table ) {
9797 var rows = table . rows ( ) ;
9898 for ( var i = 0 , len = rows . length ; i < len ; i ++ ) {
99- this . M [ "a" + tempSizeOfObject ( this . M ) ] = toParameter ( rows [ i ] [ 0 ] , rows [ i ] [ 1 ] ) ;
99+ this . M [ "a" + sizeOfObject ( this . M ) ] = toParameter ( rows [ i ] [ 0 ] , rows [ i ] [ 1 ] ) ;
100100 }
101101 } ) ;
102102
103103 this . When ( / ^ a d d i n g a t a b l e o f l i s t s t o t h e m a p M $ / , function ( table ) {
104104 var rows = table . rows ( ) ;
105105 for ( var i = 0 , len = rows . length ; i < len ; i ++ ) {
106- this . M [ "a" + tempSizeOfObject ( this . M ) ] = getListFromString ( rows [ i ] [ 0 ] , rows [ i ] [ 1 ] ) ;
106+ this . M [ "a" + sizeOfObject ( this . M ) ] = getListFromString ( rows [ i ] [ 0 ] , rows [ i ] [ 1 ] ) ;
107107 }
108108 } ) ;
109109
110110 this . When ( / ^ a d d i n g a c o p y o f m a p M t o m a p M $ / , function ( ) {
111111 var copyt_of_map = Object . assign ( { } , this . M ) ;
112- this . M [ "a" + tempSizeOfObject ( this . M ) ] = copyt_of_map ;
112+ this . M [ "a" + sizeOfObject ( this . M ) ] = copyt_of_map ;
113113 } ) ;
114114
115115 this . When ( / ^ t h e d r i v e r a s k s t h e s e r v e r t o e c h o t h i s v a l u e b a c k $ / , function ( ) {
116- echoExpectedValue ( this ) ;
116+ echoExpectedValue . call ( this ) ;
117117 } ) ;
118118
119119 this . When ( / ^ t h e d r i v e r a s k s t h e s e r v e r t o e c h o t h i s l i s t b a c k $ / , function ( ) {
120120 this . expectedValue = this . L ;
121- echoExpectedValue ( this ) ;
121+ echoExpectedValue . call ( this ) ;
122122 } ) ;
123123
124124 this . When ( / ^ t h e d r i v e r a s k s t h e s e r v e r t o e c h o t h i s m a p b a c k $ / , function ( ) {
125125 this . expectedValue = this . M ;
126- echoExpectedValue ( this ) ;
126+ echoExpectedValue . call ( this ) ;
127127 } ) ;
128128
129- this . Then ( / ^ t h e r e s u l t r e t u r n e d f r o m t h e s e r v e r s h o u l d b e a s i n g l e r e c o r d w i t h a s i n g l e v a l u e $ / , function ( callback ) {
129+ this . Then ( / ^ t h e v a l u e g i v e n i n t h e r e s u l t s h o u l d b e t h e s a m e a s w h a t w a s s e n t $ / , function ( callback ) {
130130 var self = this ;
131- this . setWithParam . then ( function ( res ) {
132- if ( Object . keys ( res [ 0 ] ) . length != 1 || Object . keys ( res [ 0 ] ) [ 0 ] . length != 1 ) {
133- callback ( new Error ( "Expected the parameterized statement to return a single row, single field record. Got: " + Object . keys ( res [ 0 ] ) . length + " records and: " + Object . keys ( res [ 0 ] ) [ 0 ] . length + " values" ) ) ;
134- } else {
135- self . paramResult = res [ 0 ] [ 'x' ] ;
136- }
137- } , function ( err ) { callback ( new Error ( "Rejected Promise: " + err ) ) } ) ;
138- this . setWithLiteral . then ( function ( res ) {
139- if ( Object . keys ( res [ 0 ] ) . length != 1 || Object . keys ( res [ 0 ] ) [ 0 ] . length != 1 ) {
140- callback ( new Error ( "Expected the parameterized statement to return a single row, single field record. Got: " + Object . keys ( res [ 0 ] ) . length + " records and: " + Object . keys ( res [ 0 ] ) [ 0 ] . length + " values" ) ) ;
141- } else {
142- self . literalResult = res [ 0 ] [ 'x' ] ;
143- callback ( ) ;
144- }
145- } , function ( err ) { callback ( new Error ( "Rejected Promise: " + err ) ) } ) ;
146- } ) ;
147-
148-
149- this . Then ( / ^ t h e v a l u e g i v e n i n t h e r e s u l t s h o u l d b e t h e s a m e a s w h a t w a s s e n t $ / , function ( ) {
150- if ( ! compareValues ( this . paramResult , this . expectedValue ) ) {
151- throw new Error ( "Expected the parameterized statement to return same as what was sent. Got: " + this . paramResult + " Expected: " + this . expectedValue ) ;
152- }
153- if ( ! compareValues ( this . literalResult , this . expectedValue ) ) {
154- throw new Error ( "Expected the literal statement to return same as what was sent. Got: " + this . literalResult + " Expected: " + this . expectedValue ) ;
131+ var errorCallback = function ( err ) { callback ( new Error ( "Rejected Promise: " + err ) ) }
132+ var successCallback = function ( res ) {
133+ if ( Object . keys ( res [ 0 ] ) . length != 1 || Object . keys ( res [ 0 ] ) [ 0 ] . length != 1 ) {
134+ callback ( new Error ( "Expected the statement to return a single row, single field record. Got: " + Object . keys ( res [ 0 ] ) . length + " records and: " + Object . keys ( res [ 0 ] ) [ 0 ] . length + " values" ) ) ;
135+ }
136+ if ( ! compareValues ( res [ 0 ] [ 'x' ] , self . expectedValue ) ) {
137+ callback ( new Error ( "Expected the statement to return same as what was sent. Got: " + res [ 0 ] [ 'x' ] + " Expected: " + self . expectedValue ) ) ;
138+ }
139+ callback ( ) ;
155140 }
141+ this . withParamPromise . then ( successCallback ) . catch ( errorCallback ) ;
142+ this . withLiteralPromise . then ( successCallback ) . catch ( errorCallback ) ;
143+
156144 } ) ;
157145
158146 this . After ( function ( ) {
159147 this . driver . close ( )
160148 } ) ;
161149
162- //Should not be used in final!!!!
163- function tempSizeOfObject ( obj ) {
150+ function sizeOfObject ( obj ) {
164151 var size = 0 , key ;
165152 for ( key in obj ) {
166153 if ( obj . hasOwnProperty ( key ) ) size ++ ;
@@ -266,7 +253,7 @@ module.exports = function () {
266253 }
267254 else if ( typeof one === "object" && one instanceof Array ) {
268255 if ( one === other ) return true ;
269- if ( tempSizeOfObject ( one ) != tempSizeOfObject ( other ) ) return false ;
256+ if ( sizeOfObject ( one ) != sizeOfObject ( other ) ) return false ;
270257 for ( var i = 0 ; i < one . length ; ++ i ) {
271258 if ( ! compareValues ( one [ i ] , other [ i ] ) ) {
272259 console . log ( "Miss-match at index: [" + i + "] Values should be same but was : [" + one [ i ] + "] and : [" + other [ i ] + "]" ) ;
@@ -304,8 +291,8 @@ module.exports = function () {
304291 return list ;
305292 }
306293
307- function echoExpectedValue ( self ) {
308- self . setWithParam = self . session . run ( "RETURN {x} as x" , { x :self . expectedValue } ) ;
309- self . setWithLiteral = self . session . run ( "RETURN " + jsToCypherLiteral ( self . expectedValue ) + " as x" ) ;
294+ function echoExpectedValue ( ) {
295+ this . withParamPromise = this . session . run ( "RETURN {x} as x" , { x :this . expectedValue } ) ;
296+ this . withLiteralPromise = this . session . run ( "RETURN " + jsToCypherLiteral ( this . expectedValue ) + " as x" ) ;
310297 }
311298} ;
0 commit comments