@@ -37,6 +37,58 @@ import {
37
37
38
38
const ROUTER_ADDRESS = ServerAddress . fromUrl ( 'test.router.com:4242' )
39
39
40
+ class FakeSession {
41
+ constructor ( runResponse , fakeConnection ) {
42
+ this . _runResponse = runResponse
43
+ this . _fakeConnection = fakeConnection
44
+ this . _closed = false
45
+ }
46
+
47
+ static successful ( result ) {
48
+ return new FakeSession ( Promise . resolve ( result ) , null )
49
+ }
50
+
51
+ static failed ( error ) {
52
+ return new FakeSession ( Promise . reject ( error ) , null )
53
+ }
54
+
55
+ static withFakeConnection ( connection ) {
56
+ return new FakeSession ( null , connection )
57
+ }
58
+
59
+ _run ( ignoreQuery , ignoreParameters , queryRunner ) {
60
+ if ( this . _runResponse ) {
61
+ return this . _runResponse
62
+ }
63
+ queryRunner ( this . _fakeConnection )
64
+ return Promise . resolve ( )
65
+ }
66
+
67
+ withBookmark ( bookmark ) {
68
+ this . _lastBookmark = bookmark
69
+ return this
70
+ }
71
+
72
+ withDatabase ( database ) {
73
+ this . _database = database || ''
74
+ return this
75
+ }
76
+
77
+ withMode ( mode ) {
78
+ this . _mode = mode
79
+ return this
80
+ }
81
+
82
+ close ( ) {
83
+ this . _closed = true
84
+ return Promise . resolve ( )
85
+ }
86
+
87
+ isClosed ( ) {
88
+ return this . _closed
89
+ }
90
+ }
91
+
40
92
describe ( '#unit RoutingUtil' , ( ) => {
41
93
it ( 'should return retrieved records when query succeeds' , done => {
42
94
const session = FakeSession . successful ( { records : [ 'foo' , 'bar' , 'baz' ] } )
@@ -261,6 +313,18 @@ describe('#unit RoutingUtil', () => {
261
313
) )
262
314
} )
263
315
316
+ it ( 'should pass initial address while invoking routing procedure' , async ( ) => {
317
+ const connection = new FakeConnection ( ) . withServerVersion ( 'Neo4j/4.1.0' )
318
+ const session = FakeSession . withFakeConnection ( connection )
319
+ const util = new RoutingUtil ( { } , 'initialAddr' )
320
+
321
+ await util . callRoutingProcedure ( session , '' , ROUTER_ADDRESS )
322
+
323
+ expect ( connection . seenParameters ) . toEqual ( [
324
+ { context : { address : 'initialAddr' } , database : null }
325
+ ] )
326
+ } )
327
+
264
328
it ( 'should parse valid ttl' , ( ) => {
265
329
const clock = lolex . install ( )
266
330
try {
@@ -503,56 +567,4 @@ describe('#unit RoutingUtil', () => {
503
567
done ( )
504
568
} )
505
569
}
506
-
507
- class FakeSession {
508
- constructor ( runResponse , fakeConnection ) {
509
- this . _runResponse = runResponse
510
- this . _fakeConnection = fakeConnection
511
- this . _closed = false
512
- }
513
-
514
- static successful ( result ) {
515
- return new FakeSession ( Promise . resolve ( result ) , null )
516
- }
517
-
518
- static failed ( error ) {
519
- return new FakeSession ( Promise . reject ( error ) , null )
520
- }
521
-
522
- static withFakeConnection ( connection ) {
523
- return new FakeSession ( null , connection )
524
- }
525
-
526
- _run ( ignoreQuery , ignoreParameters , queryRunner ) {
527
- if ( this . _runResponse ) {
528
- return this . _runResponse
529
- }
530
- queryRunner ( this . _fakeConnection )
531
- return Promise . resolve ( )
532
- }
533
-
534
- withBookmark ( bookmark ) {
535
- this . _lastBookmark = bookmark
536
- return this
537
- }
538
-
539
- withDatabase ( database ) {
540
- this . _database = database || ''
541
- return this
542
- }
543
-
544
- withMode ( mode ) {
545
- this . _mode = mode
546
- return this
547
- }
548
-
549
- close ( ) {
550
- this . _closed = true
551
- return Promise . resolve ( )
552
- }
553
-
554
- isClosed ( ) {
555
- return this . _closed
556
- }
557
- }
558
570
} )
0 commit comments