@@ -27,26 +27,27 @@ var _console = console;
2727* DO NOT add tests to this file that are not for that exact purpose.
2828* DO NOT modify these tests without ensuring they remain consistent with the equivalent examples in other drivers
2929*/
30- xdescribe ( 'examples' , function ( ) {
30+ describe ( 'examples' , function ( ) {
3131
32- var driver , session , out , console ;
32+ var driverGlobal , sessionGlobal , out , console ;
3333
3434 beforeEach ( function ( done ) {
3535 var neo4j = neo4jv1 ;
3636 // tag::construct-driver[]
37- driver = neo4j . driver ( "bolt://localhost" , neo4jv1 . auth . basic ( "neo4j" , "neo4j" ) ) ;
37+ driverGlobal = neo4j . driver ( "bolt://localhost" , neo4jv1 . auth . basic ( "neo4j" , "neo4j" ) ) ;
3838 //end::construct-driver[]
39- session = driver . session ( ) ;
39+ sessionGlobal = driverGlobal . session ( ) ;
4040
4141 // Override console.log, to assert on stdout output
4242 out = [ ] ;
4343 console = { log : function ( msg ) { out . push ( msg ) ; } } ;
4444
45- session . run ( "MATCH (n) DETACH DELETE n" ) . then ( done ) ;
45+ sessionGlobal . run ( "MATCH (n) DETACH DELETE n" ) . then ( done ) ;
4646 } ) ;
4747
4848 afterEach ( function ( ) {
49- driver . close ( ) ;
49+ sessionGlobal . close ( ) ;
50+ driverGlobal . close ( ) ;
5051 } ) ;
5152
5253 it ( 'should document a minimal import and usage example' , function ( done ) {
@@ -65,31 +66,39 @@ xdescribe('examples', function() {
6566 . run ( "MATCH (p:Person) WHERE p.name = 'Neo' RETURN p.age" )
6667 . then ( function ( result ) {
6768 console . log ( "Neo is " + result . records [ 0 ] . get ( "p.age" ) . toInt ( ) + " years old." ) ;
68-
6969 session . close ( ) ;
7070 driver . close ( ) ;
71- done ( ) ;
7271 } ) ;
73- // tag::minimal-example[]
72+ // end::minimal-example[]
73+ setTimeout ( function ( ) {
74+ expect ( out [ 0 ] ) . toBe ( "Neo is 23 years old." ) ;
75+ done ( ) ;
76+ } , 500 ) ;
7477 } ) ;
7578
7679 it ( 'should be able to configure session pool size' , function ( done ) {
7780 var neo4j = neo4jv1 ;
7881 // tag::configuration[]
79- driver = neo4j . driver ( "bolt://localhost" , neo4jv1 . auth . basic ( "neo4j" , "neo4j" ) , { connectionPoolSize : 10 } ) ;
82+ var driver = neo4j . driver ( "bolt://localhost" , neo4jv1 . auth . basic ( "neo4j" , "neo4j" ) , { connectionPoolSize : 50 } ) ;
8083 //end::configuration[]
8184
82- session . run ( "CREATE (neo:Person {name:'Neo', age:23})" ) ;
83- session
84- . run ( "MATCH (p:Person) WHERE p.name = 'Neo' RETURN p.age" )
85- . then ( function ( result ) {
86- session . close ( ) ;
85+ var s = driver . session ( ) ;
86+ s . run ( "CREATE (p:Person { name: {name} })" , { name : "The One" } )
87+ . then ( function ( result ) {
88+ var theOnesCreated = result . summary . updateStatistics . nodesCreated ( ) ;
89+ console . log ( theOnesCreated ) ;
90+ s . close ( ) ;
8791 driver . close ( ) ;
88- done ( ) ;
8992 } ) ;
93+
94+ setTimeout ( function ( ) {
95+ expect ( out [ 0 ] ) . toBe ( 1 ) ;
96+ done ( ) ;
97+ } , 500 ) ;
9098 } ) ;
9199
92100 it ( 'should document a statement' , function ( done ) {
101+ var session = sessionGlobal ;
93102 var resultPromise =
94103 // tag::statement[]
95104 session
@@ -108,6 +117,7 @@ xdescribe('examples', function() {
108117 } ) ;
109118
110119 it ( 'should document a statement without parameters' , function ( done ) {
120+ var session = sessionGlobal ;
111121 var resultPromise =
112122 // tag::statement-without-parameters[]
113123 session
@@ -127,6 +137,7 @@ xdescribe('examples', function() {
127137 } ) ;
128138
129139 it ( 'should be able to iterate results' , function ( done ) {
140+ var session = sessionGlobal ;
130141 // tag::retain-result-query[]
131142 session
132143 . run ( "MATCH (p:Person { name: {name} }) RETURN p.age" , { name : "The One" } )
@@ -142,12 +153,14 @@ xdescribe('examples', function() {
142153 console . log ( error ) ;
143154 }
144155 } ) ;
145- // end::result-cursor []
156+ // end::retain- result-query []
146157 // Then
147158 done ( ) ;
148159 } ) ;
149160
150161 it ( 'should be able to do nested queries' , function ( done ) {
162+ var session = sessionGlobal ;
163+
151164 session . run ( "CREATE (:Person {name:'The One'})" ) . then ( function ( ) {
152165 // tag::result-cursor[]
153166 session
@@ -173,6 +186,8 @@ xdescribe('examples', function() {
173186 } ) ;
174187
175188 it ( 'should be able to retain for later processing' , function ( done ) {
189+ var session = sessionGlobal ;
190+
176191 session . run ( "CREATE (:Person {name:'The One', age: 23})" ) . then ( function ( ) {
177192 // tag::retain-result-process[]
178193 session
@@ -195,16 +210,30 @@ xdescribe('examples', function() {
195210 } , 500 ) ;
196211 } ) ;
197212
213+ it ( 'should be able to handle cypher error' , function ( done ) {
214+ var session = sessionGlobal ;
215+
216+ // tag::handle-cypher-error[]
217+ session
218+ . run ( "Then will cause a syntax error" )
219+ . catch ( function ( err ) {
220+ expect ( err . fields [ 0 ] . code ) . toBe ( "Neo.ClientError.Statement.SyntaxError" ) ;
221+ done ( ) ;
222+ } ) ;
223+ // end::handle-cypher-error[]
224+ } ) ;
198225
199226 it ( 'should be able to profile' , function ( done ) {
227+ var session = sessionGlobal ;
228+
200229 session . run ( "CREATE (:Person {name:'The One', age: 23})" ) . then ( function ( ) {
201- // tag::retain- result-process []
230+ // tag::result-summary-query-profile []
202231 session
203232 . run ( "PROFILE MATCH (p:Person { name: {name} }) RETURN id(p)" , { name : "The One" } )
204233 . then ( function ( result ) {
205234 console . log ( result . summary . profile ) ;
206235 } ) ;
207- // end::retain- result-process []
236+ // end::result-summary-query-profile []
208237 } ) ;
209238
210239 //await the result
@@ -215,7 +244,9 @@ xdescribe('examples', function() {
215244 } ) ;
216245
217246 it ( 'should be able to see notifications' , function ( done ) {
218- // tag::retain-result-process[]
247+ var session = sessionGlobal ;
248+
249+ // tag::result-summary-notifications[]
219250 session
220251 . run ( "EXPLAIN MATCH (a), (b) RETURN a,b" )
221252 . then ( function ( result ) {
@@ -224,7 +255,7 @@ xdescribe('examples', function() {
224255 console . log ( notifications [ i ] . code ) ;
225256 }
226257 } ) ;
227- // end::retain- result-process []
258+ // end::result-summary-notifications []
228259
229260 setTimeout ( function ( ) {
230261 expect ( out [ 0 ] ) . toBe ( "Neo.ClientNotification.Statement.CartesianProductWarning" ) ;
@@ -233,6 +264,8 @@ xdescribe('examples', function() {
233264 } ) ;
234265
235266 it ( 'should document committing a transaction' , function ( ) {
267+ var session = sessionGlobal ;
268+
236269 // tag::transaction-commit[]
237270 var tx = session . beginTransaction ( ) ;
238271 tx . run ( "CREATE (p:Person { name: 'The One' })" ) ;
@@ -241,6 +274,8 @@ xdescribe('examples', function() {
241274 } ) ;
242275
243276 it ( 'should document rolling back a transaction' , function ( ) {
277+ var session = sessionGlobal ;
278+
244279 // tag::transaction-rollback[]
245280 var tx = session . beginTransaction ( ) ;
246281 tx . run ( "CREATE (p:Person { name: 'The One' })" ) ;
@@ -249,6 +284,8 @@ xdescribe('examples', function() {
249284 } ) ;
250285
251286 it ( 'should document how to require encryption' , function ( ) {
287+ var session = sessionGlobal ;
288+
252289 var neo4j = neo4jv1 ;
253290 // tag::tls-require-encryption[]
254291 var driver = neo4j . driver ( "bolt://localhost" , neo4j . auth . basic ( "neo4j" , "neo4j" ) , {
0 commit comments