@@ -160,24 +160,52 @@ describe('byte arrays', () => {
160
160
jasmine . DEFAULT_TIMEOUT_INTERVAL = originalTimeout ;
161
161
} ) ;
162
162
163
- it ( 'should support returning empty byte array' , done => {
164
- if ( ! serverSupportsByteArrays ) {
163
+ it ( 'should support returning empty byte array if server supports byte arrays ' , done => {
164
+ if ( ! serverSupportsByteArrays ) {
165
165
done ( ) ;
166
166
return ;
167
167
}
168
168
169
169
testValue ( new Int8Array ( 0 ) ) ( done ) ;
170
170
} ) ;
171
171
172
- it ( 'should support returning empty byte array' , conditionalTestValues ( serverSupportsByteArrays , new Int8Array ( 0 ) ) ) ;
172
+ it ( 'should support returning empty byte array if server supports byte arrays' , done => {
173
+ if ( ! serverSupportsByteArrays ) {
174
+ done ( ) ;
175
+ return ;
176
+ }
177
+
178
+ testValues ( [ new Int8Array ( 0 ) ] ) ( done ) ;
179
+ } ) ;
180
+
181
+ it ( 'should support returning short byte arrays if server supports byte arrays' , done => {
182
+ if ( ! serverSupportsByteArrays ) {
183
+ done ( ) ;
184
+ return ;
185
+ }
186
+
187
+ testValues ( randomByteArrays ( 100 , 1 , 255 ) ) ( done ) ;
188
+ } ) ;
189
+
190
+ it ( 'should support returning medium byte arrays if server supports byte arrays' , done => {
191
+ if ( ! serverSupportsByteArrays ) {
192
+ done ( ) ;
193
+ return ;
194
+ }
173
195
174
- it ( 'should support returning short byte arrays' , conditionalTestValues ( serverSupportsByteArrays , randomByteArrays ( 100 , 1 , 255 ) ) ) ;
196
+ testValues ( randomByteArrays ( 50 , 256 , 65535 ) ) ( done ) ;
197
+ } ) ;
175
198
176
- it ( 'should support returning medium byte arrays' , conditionalTestValues ( serverSupportsByteArrays , randomByteArrays ( 50 , 256 , 65535 ) ) ) ;
199
+ it ( 'should support returning long byte arrays if server supports byte arrays' , done => {
200
+ if ( ! serverSupportsByteArrays ) {
201
+ done ( ) ;
202
+ return ;
203
+ }
177
204
178
- it ( 'should support returning long byte arrays' , conditionalTestValues ( serverSupportsByteArrays , randomByteArrays ( 10 , 65536 , 2 * 65536 ) ) ) ;
205
+ testValues ( randomByteArrays ( 10 , 65536 , 2 * 65536 ) ) ( done ) ;
206
+ } ) ;
179
207
180
- it ( 'should fail to return byte array' , done => {
208
+ it ( 'should fail to return byte array if server does not support byte arrays ' , done => {
181
209
if ( serverSupportsByteArrays ) {
182
210
done ( ) ;
183
211
return ;
@@ -193,28 +221,35 @@ describe('byte arrays', () => {
193
221
} ) ;
194
222
} ) ;
195
223
196
- function conditionalTestValues ( condition , values ) {
197
- if ( ! condition ) {
198
- return done => done ( ) ;
199
- }
200
-
201
- const driver = neo4j . driver ( 'bolt://localhost' , sharedNeo4j . authToken ) ;
202
- const queriesPromise = values . reduce ( ( acc , value ) =>
203
- acc . then ( ( ) => runReturnQuery ( driver , value ) ) , Promise . resolve ( ) ) ;
204
- return asTestFunction ( queriesPromise , driver ) ;
205
- }
206
-
207
224
function testValue ( actual , expected ) {
208
- const driver = neo4j . driver ( 'bolt://localhost' , sharedNeo4j . authToken ) ;
209
- const queryPromise = runReturnQuery ( driver , actual , expected ) ;
210
- return asTestFunction ( queryPromise , driver ) ;
225
+ return done => {
226
+ const driver = neo4j . driver ( 'bolt://localhost' , sharedNeo4j . authToken ) ;
227
+ const queryPromise = runReturnQuery ( driver , actual , expected ) ;
228
+
229
+ queryPromise . then ( ( ) => {
230
+ driver . close ( ) ;
231
+ done ( ) ;
232
+ } ) . catch ( error => {
233
+ driver . close ( ) ;
234
+ console . log ( error ) ;
235
+ } ) ;
236
+ } ;
211
237
}
212
238
213
239
function testValues ( values ) {
214
- const driver = neo4j . driver ( 'bolt://localhost' , sharedNeo4j . authToken ) ;
215
- const queriesPromise = values . reduce ( ( acc , value ) =>
216
- acc . then ( ( ) => runReturnQuery ( driver , value ) ) , Promise . resolve ( ) ) ;
217
- return asTestFunction ( queriesPromise , driver ) ;
240
+ return done => {
241
+ const driver = neo4j . driver ( 'bolt://localhost' , sharedNeo4j . authToken ) ;
242
+ const queriesPromise = values . reduce ( ( acc , value ) =>
243
+ acc . then ( ( ) => runReturnQuery ( driver , value ) ) , Promise . resolve ( ) ) ;
244
+
245
+ queriesPromise . then ( ( ) => {
246
+ driver . close ( ) ;
247
+ done ( ) ;
248
+ } ) . catch ( error => {
249
+ driver . close ( ) ;
250
+ console . log ( error ) ;
251
+ } ) ;
252
+ } ;
218
253
}
219
254
220
255
function runReturnQuery ( driver , actual , expected ) {
@@ -230,17 +265,6 @@ function runReturnQuery(driver, actual, expected) {
230
265
} ) ;
231
266
}
232
267
233
- function asTestFunction ( promise , driver ) {
234
- return done =>
235
- promise . then ( ( ) => {
236
- driver . close ( ) ;
237
- done ( ) ;
238
- } ) . catch ( error => {
239
- driver . close ( ) ;
240
- console . log ( error ) ;
241
- } ) ;
242
- }
243
-
244
268
function randomByteArrays ( count , minLength , maxLength ) {
245
269
return _ . range ( count ) . map ( ( ) => {
246
270
const length = _ . random ( minLength , maxLength ) ;
0 commit comments