17
17
* limitations under the License.
18
18
*/
19
19
20
- var neo4j = require ( "../../lib/v1" ) ;
20
+ var neo4jv1 = require ( "../../lib/v1" ) ;
21
21
22
22
var _console = console ;
23
23
24
- describe ( 'examples' , function ( ) {
24
+ /**
25
+ * The tests below are examples that get pulled into the Driver Manual using the tags inside the tests.
26
+ *
27
+ * DO NOT add tests to this file that are not for that exact purpose.
28
+ * DO NOT modify these tests without ensuring they remain consistent with the equivalent examples in other drivers
29
+ */
30
+ fdescribe ( 'examples' , function ( ) {
25
31
26
32
var driver , session , out , console ;
27
33
28
34
beforeEach ( function ( done ) {
29
- driver = neo4j . driver ( "bolt://localhost" , neo4j . auth . basic ( "neo4j" , "neo4j" ) ) ;
35
+ var neo4j = neo4jv1 ;
36
+ // tag::construct-driver[]
37
+ driver = neo4j . driver ( "bolt://localhost" , neo4jv1 . auth . basic ( "neo4j" , "neo4j" ) ) ;
38
+ //end::construct-driver[]
30
39
session = driver . session ( ) ;
31
40
32
41
// Override console.log, to assert on stdout output
@@ -40,13 +49,18 @@ describe('examples', function() {
40
49
driver . close ( ) ;
41
50
} ) ;
42
51
43
- it ( 'should document a minimum viable snippet' , function ( done ) {
44
- // tag::minimum-snippet[]
52
+ it ( 'should document a minimal import and usage example' , function ( done ) {
53
+ //OH my is this a hack
54
+ var require = function ( arg ) {
55
+ return { v1 : neo4jv1 }
56
+ } ;
57
+ // tag::minimal-example-import[]
58
+ var neo4j = require ( 'neo4j-driver' ) . v1 ;
59
+ // end::minimal-example-import[]
60
+ // tag::minimal-example[]
45
61
var driver = neo4j . driver ( "bolt://localhost" , neo4j . auth . basic ( "neo4j" , "neo4j" ) ) ;
46
62
var session = driver . session ( ) ;
47
-
48
63
session . run ( "CREATE (neo:Person {name:'Neo', age:23})" ) ;
49
-
50
64
session
51
65
. run ( "MATCH (p:Person) WHERE p.name = 'Neo' RETURN p.age" )
52
66
. then ( function ( result ) {
@@ -56,14 +70,30 @@ describe('examples', function() {
56
70
driver . close ( ) ;
57
71
done ( ) ;
58
72
} ) ;
59
- // end::minimum-snippet[]
73
+ // tag::minimal-example[]
74
+ } ) ;
75
+
76
+ it ( 'should be able to configure session pool size' , function ( done ) {
77
+ var neo4j = neo4jv1 ;
78
+ // tag::configuration[]
79
+ driver = neo4j . driver ( "bolt://localhost" , neo4jv1 . auth . basic ( "neo4j" , "neo4j" ) , { connectionPoolSize : 10 } ) ;
80
+ //end::configuration[]
81
+
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 ( ) ;
87
+ driver . close ( ) ;
88
+ done ( ) ;
89
+ } ) ;
60
90
} ) ;
61
91
62
92
it ( 'should document a statement' , function ( done ) {
63
93
var resultPromise =
64
94
// tag::statement[]
65
95
session
66
- . run ( "CREATE (p:Person { name: {name} })" , { " name" : "The One" } )
96
+ . run ( "CREATE (p:Person { name: {name} })" , { name : "The One" } )
67
97
. then ( function ( result ) {
68
98
var theOnesCreated = result . summary . updateStatistics . nodesCreated ( ) ;
69
99
console . log ( "There were " + theOnesCreated + " the ones created." )
@@ -96,6 +126,112 @@ describe('examples', function() {
96
126
} )
97
127
} ) ;
98
128
129
+ it ( 'should be able to iterate results' , function ( done ) {
130
+ // tag::retain-result-query[]
131
+ session
132
+ . run ( "MATCH (p:Person { name: {name} }) RETURN p.age" , { name : "The One" } )
133
+ . subscribe ( {
134
+ onNext : function ( record ) {
135
+ console . log ( record ) ;
136
+ } ,
137
+ onCompleted : function ( ) {
138
+ // Completed!
139
+ session . close ( ) ;
140
+ } ,
141
+ onError : function ( error ) {
142
+ console . log ( error ) ;
143
+ }
144
+ } ) ;
145
+ // end::result-cursor[]
146
+ // Then
147
+ done ( ) ;
148
+ } ) ;
149
+
150
+ it ( 'should be able to do nested queries' , function ( done ) {
151
+ session . run ( "CREATE (:Person {name:'The One'})" ) . then ( function ( ) {
152
+ // tag::result-cursor[]
153
+ session
154
+ . run ( "MATCH (p:Person { name: {name} }) RETURN id(p)" , { name : "The One" } )
155
+ . then ( function ( result ) {
156
+ var id = result . records [ 0 ] . get ( 'id(p)' ) ;
157
+ session . run ( "MATCH (p) WHERE id(p) = {id} CREATE (p)-[:HAS_TRAIT]->(:Trait {type:'Immortal'})" , { id : id } )
158
+ . then ( function ( neoRecord ) {
159
+ var immortalsCreated = neoRecord . summary . updateStatistics . nodesCreated ( ) ;
160
+ var relationshipCreated = neoRecord . summary . updateStatistics . relationshipsCreated ( ) ;
161
+ console . log ( "There were " + immortalsCreated + " immortal and " + relationshipCreated +
162
+ " relationships created" ) ;
163
+ } ) ;
164
+ } ) ;
165
+ // tag::result-cursor[]
166
+ } ) ;
167
+
168
+ //await the result
169
+ setTimeout ( function ( ) {
170
+ expect ( out [ 0 ] ) . toBe ( "There were 1 immortal and 1 relationships created" ) ;
171
+ done ( ) ;
172
+ } , 500 ) ;
173
+ } ) ;
174
+
175
+ it ( 'should be able to retain for later processing' , function ( done ) {
176
+ session . run ( "CREATE (:Person {name:'The One', age: 23})" ) . then ( function ( ) {
177
+ // tag::retain-result-process[]
178
+ session
179
+ . run ( "MATCH (p:Person { name: {name} }) RETURN p.age" , { name : "The One" } )
180
+ . then ( function ( result ) {
181
+ for ( i = 0 ; i < result . records . length ; i ++ ) {
182
+ result . records [ i ] . forEach ( function ( value , key , record ) {
183
+ console . log ( "Value for key " + key + " has value " + value ) ;
184
+ } ) ;
185
+ }
186
+
187
+ } ) ;
188
+ // end::retain-result-process[]
189
+ } ) ;
190
+
191
+ //await the result
192
+ setTimeout ( function ( ) {
193
+ expect ( out [ 0 ] ) . toBe ( "Value for key p.age has value 23" ) ;
194
+ done ( ) ;
195
+ } , 500 ) ;
196
+ } ) ;
197
+
198
+
199
+ it ( 'should be able to profile' , function ( done ) {
200
+ session . run ( "CREATE (:Person {name:'The One', age: 23})" ) . then ( function ( ) {
201
+ // tag::retain-result-process[]
202
+ session
203
+ . run ( "PROFILE MATCH (p:Person { name: {name} }) RETURN id(p)" , { name : "The One" } )
204
+ . then ( function ( result ) {
205
+ console . log ( result . summary . profile ) ;
206
+ } ) ;
207
+ // end::retain-result-process[]
208
+ } ) ;
209
+
210
+ //await the result
211
+ setTimeout ( function ( ) {
212
+ expect ( out . length ) . toBe ( 1 ) ;
213
+ done ( ) ;
214
+ } , 500 ) ;
215
+ } ) ;
216
+
217
+ it ( 'should be able to see notifications' , function ( done ) {
218
+ // tag::retain-result-process[]
219
+ session
220
+ . run ( "EXPLAIN MATCH (a), (b) RETURN a,b" )
221
+ . then ( function ( result ) {
222
+ var notifications = result . summary . notifications , i ;
223
+ for ( i = 0 ; i < notifications . length ; i ++ ) {
224
+ console . log ( notifications [ i ] . code ) ;
225
+ }
226
+ } ) ;
227
+ // end::retain-result-process[]
228
+
229
+ setTimeout ( function ( ) {
230
+ expect ( out [ 0 ] ) . toBe ( "Neo.ClientNotification.Statement.CartesianProductWarning" ) ;
231
+ done ( ) ;
232
+ } , 500 ) ;
233
+ } ) ;
234
+
99
235
it ( 'should document committing a transaction' , function ( ) {
100
236
// tag::transaction-commit[]
101
237
var tx = session . beginTransaction ( ) ;
@@ -113,6 +249,7 @@ describe('examples', function() {
113
249
} ) ;
114
250
115
251
it ( 'should document how to require encryption' , function ( ) {
252
+ var neo4j = neo4jv1 ;
116
253
// tag::tls-require-encryption[]
117
254
var driver = neo4j . driver ( "bolt://localhost" , neo4j . auth . basic ( "neo4j" , "neo4j" ) , {
118
255
// In NodeJS, encryption is on by default. In the web bundle, it is off.
@@ -123,6 +260,7 @@ describe('examples', function() {
123
260
} ) ;
124
261
125
262
it ( 'should document how to configure trust-on-first-use' , function ( ) {
263
+ var neo4j = neo4jv1 ;
126
264
// tag::tls-trust-on-first-use[]
127
265
var driver = neo4j . driver ( "bolt://localhost" , neo4j . auth . basic ( "neo4j" , "neo4j" ) , {
128
266
// Note that trust-on-first-use is not available in the browser bundle,
@@ -136,6 +274,7 @@ describe('examples', function() {
136
274
} ) ;
137
275
138
276
it ( 'should document how to configure a trusted signing certificate' , function ( ) {
277
+ var neo4j = neo4jv1 ;
139
278
// tag::tls-signed[]
140
279
var driver = neo4j . driver ( "bolt://localhost" , neo4j . auth . basic ( "neo4j" , "neo4j" ) , {
141
280
trust : "TRUST_SIGNED_CERTIFICATES" ,
0 commit comments