@@ -37,6 +37,58 @@ import {
3737
3838const ROUTER_ADDRESS = ServerAddress . fromUrl ( 'test.router.com:4242' )
3939
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+
4092describe ( '#unit RoutingUtil' , ( ) => {
4193 it ( 'should return retrieved records when query succeeds' , done => {
4294 const session = FakeSession . successful ( { records : [ 'foo' , 'bar' , 'baz' ] } )
@@ -261,6 +313,18 @@ describe('#unit RoutingUtil', () => {
261313 ) )
262314 } )
263315
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+
264328 it ( 'should parse valid ttl' , ( ) => {
265329 const clock = lolex . install ( )
266330 try {
@@ -503,56 +567,4 @@ describe('#unit RoutingUtil', () => {
503567 done ( )
504568 } )
505569 }
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- }
558570} )
0 commit comments