@@ -41,19 +41,19 @@ module.exports = function () {
41
41
var map = { } ;
42
42
for ( var i = 0 ; i < size ; i ++ ) {
43
43
if ( type === 'String' ) {
44
- map [ "a" + tempSizeOfObject ( this . M ) ] = stringOfSize ( 3 ) ;
44
+ map [ "a" + sizeOfObject ( this . M ) ] = stringOfSize ( 3 ) ;
45
45
}
46
46
if ( type === 'Integer' ) {
47
- map [ "a" + tempSizeOfObject ( this . M ) ] = randomInt ( ) ;
47
+ map [ "a" + sizeOfObject ( this . M ) ] = randomInt ( ) ;
48
48
}
49
49
if ( type === 'Boolean' ) {
50
- map [ "a" + tempSizeOfObject ( this . M ) ] = randomBool ( ) ;
50
+ map [ "a" + sizeOfObject ( this . M ) ] = randomBool ( ) ;
51
51
}
52
52
if ( type === 'Float' ) {
53
- map [ "a" + tempSizeOfObject ( this . M ) ] = randomFloat ( ) ;
53
+ map [ "a" + sizeOfObject ( this . M ) ] = randomFloat ( ) ;
54
54
}
55
55
if ( type === 'Null' ) {
56
- map [ "a" + tempSizeOfObject ( this . M ) ] = null ;
56
+ map [ "a" + sizeOfObject ( this . M ) ] = null ;
57
57
}
58
58
}
59
59
this . expectedValue = map ;
@@ -96,71 +96,58 @@ module.exports = function () {
96
96
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 ) {
97
97
var rows = table . rows ( ) ;
98
98
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 ] ) ;
100
100
}
101
101
} ) ;
102
102
103
103
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 ) {
104
104
var rows = table . rows ( ) ;
105
105
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 ] ) ;
107
107
}
108
108
} ) ;
109
109
110
110
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 ( ) {
111
111
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 ;
113
113
} ) ;
114
114
115
115
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 ) ;
117
117
} ) ;
118
118
119
119
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 ( ) {
120
120
this . expectedValue = this . L ;
121
- echoExpectedValue ( this ) ;
121
+ echoExpectedValue . call ( this ) ;
122
122
} ) ;
123
123
124
124
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 ( ) {
125
125
this . expectedValue = this . M ;
126
- echoExpectedValue ( this ) ;
126
+ echoExpectedValue . call ( this ) ;
127
127
} ) ;
128
128
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 ) {
130
130
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 ( ) ;
155
140
}
141
+ this . withParamPromise . then ( successCallback ) . catch ( errorCallback ) ;
142
+ this . withLiteralPromise . then ( successCallback ) . catch ( errorCallback ) ;
143
+
156
144
} ) ;
157
145
158
146
this . After ( function ( ) {
159
147
this . driver . close ( )
160
148
} ) ;
161
149
162
- //Should not be used in final!!!!
163
- function tempSizeOfObject ( obj ) {
150
+ function sizeOfObject ( obj ) {
164
151
var size = 0 , key ;
165
152
for ( key in obj ) {
166
153
if ( obj . hasOwnProperty ( key ) ) size ++ ;
@@ -266,7 +253,7 @@ module.exports = function () {
266
253
}
267
254
else if ( typeof one === "object" && one instanceof Array ) {
268
255
if ( one === other ) return true ;
269
- if ( tempSizeOfObject ( one ) != tempSizeOfObject ( other ) ) return false ;
256
+ if ( sizeOfObject ( one ) != sizeOfObject ( other ) ) return false ;
270
257
for ( var i = 0 ; i < one . length ; ++ i ) {
271
258
if ( ! compareValues ( one [ i ] , other [ i ] ) ) {
272
259
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 () {
304
291
return list ;
305
292
}
306
293
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" ) ;
310
297
}
311
298
} ;
0 commit comments