@@ -34,11 +34,15 @@ describe('examples', () => {
34
34
let testResultPromise ;
35
35
let resolveTestResultPromise ;
36
36
37
+ const user = 'neo4j' ;
38
+ const password = 'neo4j' ;
39
+ const uri = 'bolt://localhost:7687' ;
40
+
37
41
beforeAll ( ( ) => {
38
42
originalTimeout = jasmine . DEFAULT_TIMEOUT_INTERVAL ;
39
43
jasmine . DEFAULT_TIMEOUT_INTERVAL = 10000 ;
40
44
41
- driverGlobal = neo4j . driver ( 'bolt://localhost:7687' , neo4j . auth . basic ( 'neo4j' , 'neo4j' ) ) ;
45
+ driverGlobal = neo4j . driver ( uri , neo4j . auth . basic ( 'neo4j' , 'neo4j' ) ) ;
42
46
} ) ;
43
47
44
48
beforeEach ( done => {
@@ -89,11 +93,8 @@ describe('examples', () => {
89
93
} ) ;
90
94
91
95
it ( 'basic auth example' , done => {
92
- const user = 'neo4j' ;
93
- const password = 'neo4j' ;
94
-
95
96
// tag::basic-auth[]
96
- const driver = neo4j . driver ( 'bolt://localhost:7687' , neo4j . auth . basic ( user , password ) ) ;
97
+ const driver = neo4j . driver ( uri , neo4j . auth . basic ( user , password ) ) ;
97
98
// end::basic-auth[]
98
99
99
100
driver . onCompleted = ( ) => {
@@ -107,12 +108,9 @@ describe('examples', () => {
107
108
} ) ;
108
109
109
110
it ( 'config max retry time example' , done => {
110
- const user = 'neo4j' ;
111
- const password = 'neo4j' ;
112
-
113
111
// tag::config-max-retry-time[]
114
112
const maxRetryTimeMs = 15 * 1000 ; // 15 seconds
115
- const driver = neo4j . driver ( 'bolt://localhost:7687' , neo4j . auth . basic ( user , password ) ,
113
+ const driver = neo4j . driver ( uri , neo4j . auth . basic ( user , password ) ,
116
114
{
117
115
maxTransactionRetryTime : maxRetryTimeMs
118
116
}
@@ -130,11 +128,8 @@ describe('examples', () => {
130
128
} ) ;
131
129
132
130
it ( 'config trust example' , done => {
133
- const user = 'neo4j' ;
134
- const password = 'neo4j' ;
135
-
136
131
// tag::config-trust[]
137
- const driver = neo4j . driver ( 'bolt://localhost:7687' , neo4j . auth . basic ( user , password ) ,
132
+ const driver = neo4j . driver ( uri , neo4j . auth . basic ( user , password ) ,
138
133
{
139
134
encrypted : 'ENCRYPTION_ON' ,
140
135
trust : 'TRUST_ALL_CERTIFICATES'
@@ -158,11 +153,8 @@ describe('examples', () => {
158
153
} ) ;
159
154
160
155
it ( 'config unencrypted example' , done => {
161
- const user = 'neo4j' ;
162
- const password = 'neo4j' ;
163
-
164
156
// tag::config-unencrypted[]
165
- const driver = neo4j . driver ( 'bolt://localhost:7687' , neo4j . auth . basic ( user , password ) ,
157
+ const driver = neo4j . driver ( uri , neo4j . auth . basic ( user , password ) ,
166
158
{
167
159
encrypted : 'ENCRYPTION_OFF'
168
160
}
@@ -179,21 +171,25 @@ describe('examples', () => {
179
171
} ) ;
180
172
} ) ;
181
173
182
- it ( 'custom auth example' , ( ) => {
183
- const principal = 'principal' ;
184
- const credentials = 'credentials' ;
185
- const realm = 'realm' ;
186
- const scheme = 'scheme ' ;
174
+ it ( 'custom auth example' , done => {
175
+ const principal = user ;
176
+ const credentials = password ;
177
+ const realm = undefined ;
178
+ const scheme = 'basic ' ;
187
179
const parameters = { } ;
188
180
189
181
// tag::custom-auth[]
190
- const driver = neo4j . driver (
191
- 'bolt://localhost:7687' ,
192
- neo4j . auth . custom ( principal , credentials , realm , scheme , parameters )
193
- ) ;
182
+ const driver = neo4j . driver ( uri , neo4j . auth . custom ( principal , credentials , realm , scheme , parameters ) ) ;
194
183
// end::custom-auth[]
195
184
196
- expect ( driver ) . toBeDefined ( ) ;
185
+ driver . onCompleted = ( ) => {
186
+ done ( ) ;
187
+ } ;
188
+
189
+ const session = driver . session ( ) ;
190
+ session . run ( 'RETURN 1' ) . then ( ( ) => {
191
+ session . close ( ) ;
192
+ } ) ;
197
193
} ) ;
198
194
199
195
it ( 'cypher error example' , done => {
@@ -221,11 +217,8 @@ describe('examples', () => {
221
217
} ) ;
222
218
223
219
it ( 'driver lifecycle example' , done => {
224
- const user = 'neo4j' ;
225
- const password = 'neo4j' ;
226
-
227
220
// tag::driver-lifecycle[]
228
- const driver = neo4j . driver ( 'bolt://localhost:7687' , neo4j . auth . basic ( user , password ) ) ;
221
+ const driver = neo4j . driver ( uri , neo4j . auth . basic ( user , password ) ) ;
229
222
230
223
driver . onCompleted = metadata => {
231
224
console . log ( 'Driver created' ) ;
@@ -251,11 +244,8 @@ describe('examples', () => {
251
244
} ) ;
252
245
253
246
it ( 'hello world example' , done => {
254
- const user = 'neo4j' ;
255
- const password = 'neo4j' ;
256
-
257
247
// tag::hello-world[]
258
- const driver = neo4j . driver ( 'bolt://localhost:7687' , neo4j . auth . basic ( user , password ) ) ;
248
+ const driver = neo4j . driver ( uri , neo4j . auth . basic ( user , password ) ) ;
259
249
const session = driver . session ( ) ;
260
250
261
251
const resultPromise = session . writeTransaction ( tx => tx . run (
@@ -395,11 +385,11 @@ describe('examples', () => {
395
385
} ) ;
396
386
397
387
it ( 'service unavailable example' , done => {
398
- const user = 'neo4j' ;
388
+ const uri = 'bolt://localhost:7688' ; // wrong port
399
389
const password = 'wrongPassword' ;
400
390
401
391
// tag::service-unavailable[]
402
- const driver = neo4j . driver ( 'bolt://localhost:7688' , neo4j . auth . basic ( user , password ) , { maxTransactionRetryTime : 3000 } ) ;
392
+ const driver = neo4j . driver ( uri , neo4j . auth . basic ( user , password ) , { maxTransactionRetryTime : 3000 } ) ;
403
393
const session = driver . session ( ) ;
404
394
405
395
const writeTxPromise = session . writeTransaction ( tx => tx . run ( 'CREATE (a:Item)' ) ) ;
0 commit comments