@@ -201,6 +201,43 @@ describe('#integration-rx summary', () => {
201201 shouldReturnNotification ( serverVersion , txc ) )
202202 } )
203203
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+
204241 /**
205242 * @param {ServerVersion } version
206243 * @param {RxSession|RxTransaction } runnable
@@ -269,6 +306,37 @@ describe('#integration-rx summary', () => {
269306 await verifyStatementType ( runnable , 'CREATE (n) RETURN n' , 'rw' )
270307 }
271308
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+
272340 /**
273341 * @param {ServerVersion } version
274342 * @param {RxSession|RxTransaction } runnable
@@ -281,7 +349,7 @@ describe('#integration-rx summary', () => {
281349 return
282350 }
283351
284- await verifyCounters (
352+ await verifyUpdates (
285353 runnable ,
286354 'CREATE (n:Label1 {id: $id1})-[:KNOWS]->(m:Label2 {id: $id2}) RETURN n, m' ,
287355 { id1 : 10 , id2 : 20 } ,
@@ -316,7 +384,7 @@ describe('#integration-rx summary', () => {
316384 // first create the to-be-deleted nodes
317385 await shouldReturnSummaryWithUpdateStatisticsForCreate ( version , runnable )
318386
319- await verifyCounters (
387+ await verifyUpdates (
320388 runnable ,
321389 'MATCH (n:Label1)-[r:KNOWS]->(m:Label2) DELETE n, r' ,
322390 null ,
@@ -348,7 +416,7 @@ describe('#integration-rx summary', () => {
348416 return
349417 }
350418
351- await verifyCounters ( runnable , 'CREATE INDEX on :Label(prop)' , null , {
419+ await verifyUpdates ( runnable , 'CREATE INDEX on :Label(prop)' , null , {
352420 nodesCreated : 0 ,
353421 nodesDeleted : 0 ,
354422 relationshipsCreated : 0 ,
@@ -384,7 +452,7 @@ describe('#integration-rx summary', () => {
384452 await session . close ( )
385453 }
386454
387- await verifyCounters ( runnable , 'DROP INDEX on :Label(prop)' , null , {
455+ await verifyUpdates ( runnable , 'DROP INDEX on :Label(prop)' , null , {
388456 nodesCreated : 0 ,
389457 nodesDeleted : 0 ,
390458 relationshipsCreated : 0 ,
@@ -411,7 +479,7 @@ describe('#integration-rx summary', () => {
411479 return
412480 }
413481
414- await verifyCounters (
482+ await verifyUpdates (
415483 runnable ,
416484 'CREATE CONSTRAINT ON (book:Book) ASSERT book.isbn IS UNIQUE' ,
417485 null ,
@@ -454,7 +522,7 @@ describe('#integration-rx summary', () => {
454522 await session . close ( )
455523 }
456524
457- await verifyCounters (
525+ await verifyUpdates (
458526 runnable ,
459527 'DROP CONSTRAINT ON (book:Book) ASSERT book.isbn IS UNIQUE' ,
460528 null ,
@@ -628,27 +696,42 @@ describe('#integration-rx summary', () => {
628696 * @param {RxSession|RxTransaction } runnable
629697 * @param {string } statement
630698 * @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> }
632719 */
633- async function verifyCounters ( runnable , statement , parameters , counters ) {
720+ async function verifySystemUpdates (
721+ runnable ,
722+ statement ,
723+ parameters ,
724+ systemUpdates
725+ ) {
634726 const summary = await runnable
635727 . run ( statement , parameters )
636728 . summary ( )
637729 . toPromise ( )
638730 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 ( )
652735 }
653736
654737 async function dropConstraintsAndIndices ( driver ) {
0 commit comments