11
22var neo4j = require ( "../build/node/neo4j" ) ;
3+ var StatementType = require ( "../build/node/result" ) . statementType ;
34
45describe ( 'session' , function ( ) {
56 it ( 'should expose basic run/subscribe ' , function ( done ) {
@@ -10,7 +11,7 @@ describe('session', function() {
1011 var records = [ ] ;
1112 driver . session ( ) . run ( "RETURN 1.0 AS a" ) . subscribe ( {
1213 onNext : function ( record ) {
13- records . push ( record ) ;
14+ records . push ( record ) ;
1415 } ,
1516 onCompleted : function ( ) {
1617 expect ( records . length ) . toBe ( 1 ) ;
@@ -52,7 +53,7 @@ describe('session', function() {
5253 )
5354 } ) ;
5455
55- it ( 'should expose summarize method ' , function ( done ) {
56+ it ( 'should expose summarize method for basic metadata ' , function ( done ) {
5657 // Given
5758 var driver = neo4j . driver ( "neo4j://localhost" ) ;
5859 var statement = "CREATE (n:Label {prop:{prop}}) RETURN n" ;
@@ -65,7 +66,49 @@ describe('session', function() {
6566 expect ( sum . statement . parameters ) . toBe ( params ) ;
6667 expect ( sum . statistics . containsUpdates ( ) ) . toBe ( true ) ;
6768 expect ( sum . statistics . nodesCreated ( ) ) . toBe ( 1 ) ;
68- expect ( sum . statementType ) . toBe ( 'rw' ) ;
69+ expect ( sum . statementType ) . toBe ( StatementType . READ_WRITE ) ;
70+ driver . close ( ) ;
71+ done ( ) ;
72+ } ) ;
73+ } ) ;
74+
75+ it ( 'should expose plan ' , function ( done ) {
76+ // Given
77+ var driver = neo4j . driver ( "neo4j://localhost" ) ;
78+ var statement = "EXPLAIN CREATE (n:Label {prop:{prop}}) RETURN n" ;
79+ var params = { prop : "string" }
80+ // When & Then
81+ var result = driver . session ( ) . run ( statement , params ) ;
82+ result . then ( function ( records ) {
83+ var sum = result . summarize ( ) ;
84+ expect ( sum . hasPlan ( ) ) . toBe ( true ) ;
85+ expect ( sum . hasProfile ( ) ) . toBe ( false ) ;
86+ expect ( sum . plan . operatorType ) . toBe ( 'ProduceResults' ) ;
87+ expect ( sum . plan . arguments . runtime ) . toBe ( 'INTERPRETED' ) ;
88+ expect ( sum . plan . identifiers [ 0 ] ) . toBe ( 'n' ) ;
89+ expect ( sum . plan . children [ 0 ] . operatorType ) . toBe ( 'CreateNode' ) ;
90+ driver . close ( ) ;
91+ done ( ) ;
92+ } ) ;
93+ } ) ;
94+
95+ it ( 'should expose profile ' , function ( done ) {
96+ // Given
97+ var driver = neo4j . driver ( "neo4j://localhost" ) ;
98+ var statement = "PROFILE MATCH (n:Label {prop:{prop}}) RETURN n" ;
99+ var params = { prop : "string" }
100+ // When & Then
101+ var result = driver . session ( ) . run ( statement , params ) ;
102+ result . then ( function ( records ) {
103+ var sum = result . summarize ( ) ;
104+ expect ( sum . hasPlan ( ) ) . toBe ( true ) ; //When there's a profile, there's a plan
105+ expect ( sum . hasProfile ( ) ) . toBe ( true ) ;
106+ expect ( sum . profile . operatorType ) . toBe ( 'ProduceResults' ) ;
107+ expect ( sum . profile . arguments . runtime ) . toBe ( 'INTERPRETED' ) ;
108+ expect ( sum . profile . identifiers [ 0 ] ) . toBe ( 'n' ) ;
109+ expect ( sum . profile . children [ 0 ] . operatorType ) . toBe ( 'Filter' ) ;
110+ expect ( sum . profile . rows ) . toBeGreaterThan ( 0 ) ;
111+ //expect(sum.profile.dbHits).toBeGreaterThan(0);
69112 driver . close ( ) ;
70113 done ( ) ;
71114 } ) ;
0 commit comments