@@ -41,6 +41,7 @@ describe('#integration examples', () => {
41
41
let consoleOverride
42
42
let consoleOverridePromise
43
43
let consoleOverridePromiseResolve
44
+ let consoleOverridePromiseReject
44
45
45
46
const user = sharedNeo4j . username
46
47
const password = sharedNeo4j . password
@@ -53,8 +54,12 @@ describe('#integration examples', () => {
53
54
beforeEach ( async ( ) => {
54
55
consoleOverridePromise = new Promise ( ( resolve , reject ) => {
55
56
consoleOverridePromiseResolve = resolve
57
+ consoleOverridePromiseReject = reject
56
58
} )
57
- consoleOverride = { log : msg => consoleOverridePromiseResolve ( msg ) }
59
+ consoleOverride = {
60
+ log : msg => consoleOverridePromiseResolve ( msg ) ,
61
+ error : msg => consoleOverridePromiseReject ( msg )
62
+ }
58
63
59
64
protocolVersion = await sharedNeo4j . cleanupAndGetProtocolVersion (
60
65
driverGlobal
@@ -416,29 +421,35 @@ describe('#integration examples', () => {
416
421
// end::driver-introduction-example-variables[]
417
422
418
423
// tag::driver-introduction-example[]
419
- const driver = neo4j . driver ( uri , neo4j . auth . basic ( user , password ) )
424
+ const driver = neo4j . driver ( uri , neo4j . auth . basic ( user , password ) , {
425
+ // Enabling driver logging info into the console.
426
+ // Supported levels: 'error', 'warn', 'info' and 'debug'
427
+ logging : neo4j . logging . console ( 'info' )
428
+ } )
420
429
const session = driver . session ( )
421
430
422
431
const person1Name = 'Alice'
423
432
const person2Name = 'David'
433
+ const knowsFrom = 'School'
424
434
425
435
try {
426
436
// To learn more about the Cypher syntax, see https://neo4j.com/docs/cypher-manual/current/
427
437
// The Reference Card is also a good resource for keywords https://neo4j.com/docs/cypher-refcard/current/
428
438
const writeQuery = `MERGE (p1:Person { name: $person1Name })
429
439
MERGE (p2:Person { name: $person2Name })
430
- MERGE (p1)-[:KNOWS]->(p2)
431
- RETURN p1, p2`
440
+ MERGE (p1)-[k :KNOWS { from: $knowsFrom } ]->(p2)
441
+ RETURN p1, p2, k `
432
442
433
443
// Write transactions allow the driver to handle retries and transient errors
434
444
const writeResult = await session . writeTransaction ( tx =>
435
- tx . run ( writeQuery , { person1Name, person2Name } )
445
+ tx . run ( writeQuery , { person1Name, person2Name, knowsFrom } )
436
446
)
437
447
writeResult . records . forEach ( record => {
438
448
const person1Node = record . get ( 'p1' )
439
449
const person2Node = record . get ( 'p2' )
450
+ const knowsRel = record . get ( 'k' )
440
451
console . log (
441
- `Created friendship between: ${ person1Node . properties . name } , ${ person2Node . properties . name } `
452
+ `Created friendship between: ${ person1Node . properties . name } , ${ person2Node . properties . name } from ${ knowsRel . properties . from } `
442
453
)
443
454
} )
444
455
@@ -452,7 +463,7 @@ describe('#integration examples', () => {
452
463
console . log ( `Found person: ${ record . get ( 'name' ) } ` )
453
464
} )
454
465
} catch ( error ) {
455
- console . error ( 'Something went wrong: ' , error )
466
+ console . error ( error )
456
467
} finally {
457
468
await session . close ( )
458
469
}
@@ -462,7 +473,7 @@ describe('#integration examples', () => {
462
473
// end::driver-introduction-example[]
463
474
464
475
expect ( await consoleLoggedMsg ) . toEqual (
465
- `Created friendship between: ${ person1Name } , ${ person2Name } `
476
+ `Created friendship between: ${ person1Name } , ${ person2Name } from ${ knowsFrom } `
466
477
)
467
478
} , 60000 )
468
479
0 commit comments