@@ -201,6 +201,43 @@ describe('#integration-rx summary', () => {
201
201
shouldReturnNotification ( serverVersion , txc ) )
202
202
} )
203
203
204
+ describe ( 'system' , ( ) => {
205
+ let driver
206
+ /** @type {RxSession } */
207
+ let session
208
+ /** @type {ServerVersion } */
209
+ let serverVersion
210
+
211
+ beforeEach ( async ( ) => {
212
+ driver = neo4j . driver ( 'bolt://localhost' , sharedNeo4j . authToken )
213
+ session = driver . rxSession ( { database : 'system' } )
214
+ //
215
+
216
+ const normalSession = driver . session ( )
217
+ try {
218
+ const result = await normalSession . run ( 'MATCH (n) DETACH DELETE n' )
219
+ serverVersion = ServerVersion . fromString ( result . summary . server . version )
220
+ } finally {
221
+ await normalSession . close ( )
222
+ }
223
+
224
+ await dropConstraintsAndIndices ( driver )
225
+ } )
226
+
227
+ afterEach ( async ( ) => {
228
+ if ( session ) {
229
+ await session . close ( ) . toPromise ( )
230
+ }
231
+ await driver . close ( )
232
+ } )
233
+
234
+ it ( 'session should return summary with correct system updates for create' , ( ) =>
235
+ shouldReturnSummaryWithSystemUpdates ( serverVersion , session ) )
236
+
237
+ it ( 'transaction should return summary with correct system updates for create' , ( ) =>
238
+ shouldReturnSummaryWithSystemUpdates ( serverVersion , session , true ) )
239
+ } )
240
+
204
241
/**
205
242
* @param {ServerVersion } version
206
243
* @param {RxSession|RxTransaction } runnable
@@ -269,6 +306,37 @@ describe('#integration-rx summary', () => {
269
306
await verifyStatementType ( runnable , 'CREATE (n) RETURN n' , 'rw' )
270
307
}
271
308
309
+ /**
310
+ * @param {ServerVersion } version
311
+ * @param {RxSession } session
312
+ * @param {boolean } useTransaction
313
+ */
314
+ async function shouldReturnSummaryWithSystemUpdates (
315
+ version ,
316
+ session ,
317
+ useTransaction = false
318
+ ) {
319
+ if ( version . compareTo ( VERSION_4_0_0 ) < 0 ) {
320
+ return
321
+ }
322
+
323
+ let runnable = session
324
+ if ( useTransaction ) {
325
+ runnable = await session . beginTransaction ( ) . toPromise ( )
326
+ }
327
+
328
+ try {
329
+ await verifySystemUpdates (
330
+ runnable ,
331
+ "CREATE USER foo SET PASSWORD 'bar'" ,
332
+ { } ,
333
+ 1
334
+ )
335
+ } finally {
336
+ await verifySystemUpdates ( runnable , 'DROP USER foo' , { } , 1 )
337
+ }
338
+ }
339
+
272
340
/**
273
341
* @param {ServerVersion } version
274
342
* @param {RxSession|RxTransaction } runnable
@@ -281,7 +349,7 @@ describe('#integration-rx summary', () => {
281
349
return
282
350
}
283
351
284
- await verifyCounters (
352
+ await verifyUpdates (
285
353
runnable ,
286
354
'CREATE (n:Label1 {id: $id1})-[:KNOWS]->(m:Label2 {id: $id2}) RETURN n, m' ,
287
355
{ id1 : 10 , id2 : 20 } ,
@@ -316,7 +384,7 @@ describe('#integration-rx summary', () => {
316
384
// first create the to-be-deleted nodes
317
385
await shouldReturnSummaryWithUpdateStatisticsForCreate ( version , runnable )
318
386
319
- await verifyCounters (
387
+ await verifyUpdates (
320
388
runnable ,
321
389
'MATCH (n:Label1)-[r:KNOWS]->(m:Label2) DELETE n, r' ,
322
390
null ,
@@ -348,7 +416,7 @@ describe('#integration-rx summary', () => {
348
416
return
349
417
}
350
418
351
- await verifyCounters ( runnable , 'CREATE INDEX on :Label(prop)' , null , {
419
+ await verifyUpdates ( runnable , 'CREATE INDEX on :Label(prop)' , null , {
352
420
nodesCreated : 0 ,
353
421
nodesDeleted : 0 ,
354
422
relationshipsCreated : 0 ,
@@ -384,7 +452,7 @@ describe('#integration-rx summary', () => {
384
452
await session . close ( )
385
453
}
386
454
387
- await verifyCounters ( runnable , 'DROP INDEX on :Label(prop)' , null , {
455
+ await verifyUpdates ( runnable , 'DROP INDEX on :Label(prop)' , null , {
388
456
nodesCreated : 0 ,
389
457
nodesDeleted : 0 ,
390
458
relationshipsCreated : 0 ,
@@ -411,7 +479,7 @@ describe('#integration-rx summary', () => {
411
479
return
412
480
}
413
481
414
- await verifyCounters (
482
+ await verifyUpdates (
415
483
runnable ,
416
484
'CREATE CONSTRAINT ON (book:Book) ASSERT book.isbn IS UNIQUE' ,
417
485
null ,
@@ -454,7 +522,7 @@ describe('#integration-rx summary', () => {
454
522
await session . close ( )
455
523
}
456
524
457
- await verifyCounters (
525
+ await verifyUpdates (
458
526
runnable ,
459
527
'DROP CONSTRAINT ON (book:Book) ASSERT book.isbn IS UNIQUE' ,
460
528
null ,
@@ -628,27 +696,42 @@ describe('#integration-rx summary', () => {
628
696
* @param {RxSession|RxTransaction } runnable
629
697
* @param {string } statement
630
698
* @param {* } parameters
631
- * @param {* } counters
699
+ * @param {* } stats
700
+ */
701
+ async function verifyUpdates ( runnable , statement , parameters , stats ) {
702
+ const summary = await runnable
703
+ . run ( statement , parameters )
704
+ . summary ( )
705
+ . toPromise ( )
706
+ expect ( summary ) . toBeDefined ( )
707
+ expect ( summary . counters . containsUpdates ( ) ) . toBeTruthy ( )
708
+ expect ( summary . counters . updates ( ) ) . toEqual ( stats )
709
+ expect ( summary . counters . containsSystemUpdates ( ) ) . toBeFalsy ( )
710
+ }
711
+
712
+ /**
713
+ *
714
+ * @param {RxSession|RxTransaction } runnable
715
+ * @param {string } statement
716
+ * @param {* } parameters
717
+ * @param {number } systemUpdates
718
+ * @returns {Promise<void> }
632
719
*/
633
- async function verifyCounters ( runnable , statement , parameters , counters ) {
720
+ async function verifySystemUpdates (
721
+ runnable ,
722
+ statement ,
723
+ parameters ,
724
+ systemUpdates
725
+ ) {
634
726
const summary = await runnable
635
727
. run ( statement , parameters )
636
728
. summary ( )
637
729
. toPromise ( )
638
730
expect ( summary ) . toBeDefined ( )
639
- expect ( {
640
- nodesCreated : summary . counters . nodesCreated ( ) ,
641
- nodesDeleted : summary . counters . nodesDeleted ( ) ,
642
- relationshipsCreated : summary . counters . relationshipsCreated ( ) ,
643
- relationshipsDeleted : summary . counters . relationshipsDeleted ( ) ,
644
- propertiesSet : summary . counters . propertiesSet ( ) ,
645
- labelsAdded : summary . counters . labelsAdded ( ) ,
646
- labelsRemoved : summary . counters . labelsRemoved ( ) ,
647
- indexesAdded : summary . counters . indexesAdded ( ) ,
648
- indexesRemoved : summary . counters . indexesRemoved ( ) ,
649
- constraintsAdded : summary . counters . constraintsAdded ( ) ,
650
- constraintsRemoved : summary . counters . constraintsRemoved ( )
651
- } ) . toEqual ( counters )
731
+
732
+ expect ( summary . counters . containsSystemUpdates ( ) ) . toBeTruthy ( )
733
+ expect ( summary . counters . systemUpdates ( ) ) . toBe ( systemUpdates )
734
+ expect ( summary . counters . containsUpdates ( ) ) . toBeFalsy ( )
652
735
}
653
736
654
737
async function dropConstraintsAndIndices ( driver ) {
0 commit comments