@@ -27,26 +27,27 @@ var _console = console;
27
27
* DO NOT add tests to this file that are not for that exact purpose.
28
28
* DO NOT modify these tests without ensuring they remain consistent with the equivalent examples in other drivers
29
29
*/
30
- xdescribe ( 'examples' , function ( ) {
30
+ describe ( 'examples' , function ( ) {
31
31
32
- var driver , session , out , console ;
32
+ var driverGlobal , sessionGlobal , out , console ;
33
33
34
34
beforeEach ( function ( done ) {
35
35
var neo4j = neo4jv1 ;
36
36
// 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" ) ) ;
38
38
//end::construct-driver[]
39
- session = driver . session ( ) ;
39
+ sessionGlobal = driverGlobal . session ( ) ;
40
40
41
41
// Override console.log, to assert on stdout output
42
42
out = [ ] ;
43
43
console = { log : function ( msg ) { out . push ( msg ) ; } } ;
44
44
45
- session . run ( "MATCH (n) DETACH DELETE n" ) . then ( done ) ;
45
+ sessionGlobal . run ( "MATCH (n) DETACH DELETE n" ) . then ( done ) ;
46
46
} ) ;
47
47
48
48
afterEach ( function ( ) {
49
- driver . close ( ) ;
49
+ sessionGlobal . close ( ) ;
50
+ driverGlobal . close ( ) ;
50
51
} ) ;
51
52
52
53
it ( 'should document a minimal import and usage example' , function ( done ) {
@@ -65,31 +66,39 @@ xdescribe('examples', function() {
65
66
. run ( "MATCH (p:Person) WHERE p.name = 'Neo' RETURN p.age" )
66
67
. then ( function ( result ) {
67
68
console . log ( "Neo is " + result . records [ 0 ] . get ( "p.age" ) . toInt ( ) + " years old." ) ;
68
-
69
69
session . close ( ) ;
70
70
driver . close ( ) ;
71
- done ( ) ;
72
71
} ) ;
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 ) ;
74
77
} ) ;
75
78
76
79
it ( 'should be able to configure session pool size' , function ( done ) {
77
80
var neo4j = neo4jv1 ;
78
81
// 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 } ) ;
80
83
//end::configuration[]
81
84
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 ( ) ;
87
91
driver . close ( ) ;
88
- done ( ) ;
89
92
} ) ;
93
+
94
+ setTimeout ( function ( ) {
95
+ expect ( out [ 0 ] ) . toBe ( 1 ) ;
96
+ done ( ) ;
97
+ } , 500 ) ;
90
98
} ) ;
91
99
92
100
it ( 'should document a statement' , function ( done ) {
101
+ var session = sessionGlobal ;
93
102
var resultPromise =
94
103
// tag::statement[]
95
104
session
@@ -108,6 +117,7 @@ xdescribe('examples', function() {
108
117
} ) ;
109
118
110
119
it ( 'should document a statement without parameters' , function ( done ) {
120
+ var session = sessionGlobal ;
111
121
var resultPromise =
112
122
// tag::statement-without-parameters[]
113
123
session
@@ -127,6 +137,7 @@ xdescribe('examples', function() {
127
137
} ) ;
128
138
129
139
it ( 'should be able to iterate results' , function ( done ) {
140
+ var session = sessionGlobal ;
130
141
// tag::retain-result-query[]
131
142
session
132
143
. run ( "MATCH (p:Person { name: {name} }) RETURN p.age" , { name : "The One" } )
@@ -142,12 +153,14 @@ xdescribe('examples', function() {
142
153
console . log ( error ) ;
143
154
}
144
155
} ) ;
145
- // end::result-cursor []
156
+ // end::retain- result-query []
146
157
// Then
147
158
done ( ) ;
148
159
} ) ;
149
160
150
161
it ( 'should be able to do nested queries' , function ( done ) {
162
+ var session = sessionGlobal ;
163
+
151
164
session . run ( "CREATE (:Person {name:'The One'})" ) . then ( function ( ) {
152
165
// tag::result-cursor[]
153
166
session
@@ -173,6 +186,8 @@ xdescribe('examples', function() {
173
186
} ) ;
174
187
175
188
it ( 'should be able to retain for later processing' , function ( done ) {
189
+ var session = sessionGlobal ;
190
+
176
191
session . run ( "CREATE (:Person {name:'The One', age: 23})" ) . then ( function ( ) {
177
192
// tag::retain-result-process[]
178
193
session
@@ -195,16 +210,30 @@ xdescribe('examples', function() {
195
210
} , 500 ) ;
196
211
} ) ;
197
212
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
+ } ) ;
198
225
199
226
it ( 'should be able to profile' , function ( done ) {
227
+ var session = sessionGlobal ;
228
+
200
229
session . run ( "CREATE (:Person {name:'The One', age: 23})" ) . then ( function ( ) {
201
- // tag::retain- result-process []
230
+ // tag::result-summary-query-profile []
202
231
session
203
232
. run ( "PROFILE MATCH (p:Person { name: {name} }) RETURN id(p)" , { name : "The One" } )
204
233
. then ( function ( result ) {
205
234
console . log ( result . summary . profile ) ;
206
235
} ) ;
207
- // end::retain- result-process []
236
+ // end::result-summary-query-profile []
208
237
} ) ;
209
238
210
239
//await the result
@@ -215,7 +244,9 @@ xdescribe('examples', function() {
215
244
} ) ;
216
245
217
246
it ( 'should be able to see notifications' , function ( done ) {
218
- // tag::retain-result-process[]
247
+ var session = sessionGlobal ;
248
+
249
+ // tag::result-summary-notifications[]
219
250
session
220
251
. run ( "EXPLAIN MATCH (a), (b) RETURN a,b" )
221
252
. then ( function ( result ) {
@@ -224,7 +255,7 @@ xdescribe('examples', function() {
224
255
console . log ( notifications [ i ] . code ) ;
225
256
}
226
257
} ) ;
227
- // end::retain- result-process []
258
+ // end::result-summary-notifications []
228
259
229
260
setTimeout ( function ( ) {
230
261
expect ( out [ 0 ] ) . toBe ( "Neo.ClientNotification.Statement.CartesianProductWarning" ) ;
@@ -233,6 +264,8 @@ xdescribe('examples', function() {
233
264
} ) ;
234
265
235
266
it ( 'should document committing a transaction' , function ( ) {
267
+ var session = sessionGlobal ;
268
+
236
269
// tag::transaction-commit[]
237
270
var tx = session . beginTransaction ( ) ;
238
271
tx . run ( "CREATE (p:Person { name: 'The One' })" ) ;
@@ -241,6 +274,8 @@ xdescribe('examples', function() {
241
274
} ) ;
242
275
243
276
it ( 'should document rolling back a transaction' , function ( ) {
277
+ var session = sessionGlobal ;
278
+
244
279
// tag::transaction-rollback[]
245
280
var tx = session . beginTransaction ( ) ;
246
281
tx . run ( "CREATE (p:Person { name: 'The One' })" ) ;
@@ -249,6 +284,8 @@ xdescribe('examples', function() {
249
284
} ) ;
250
285
251
286
it ( 'should document how to require encryption' , function ( ) {
287
+ var session = sessionGlobal ;
288
+
252
289
var neo4j = neo4jv1 ;
253
290
// tag::tls-require-encryption[]
254
291
var driver = neo4j . driver ( "bolt://localhost" , neo4j . auth . basic ( "neo4j" , "neo4j" ) , {
0 commit comments