Skip to content

Commit 4b94cbb

Browse files
authored
Fix driver.rxSession initial bookmarks configuration and RxSession.lastBookmark return mapping (#854)
The initial bookmark configuration for the RxSession were not working since the wrong parameter were being passed to the Session. The typescript mapping for `RxSession.lastBookmark` was also wrong, `lastBookmark` always returns an string array.
1 parent 264d222 commit 4b94cbb

File tree

5 files changed

+39
-4
lines changed

5 files changed

+39
-4
lines changed

packages/neo4j-driver/src/driver.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Driver extends CoreDriver {
6767
return new RxSession({
6868
session: this._newSession({
6969
defaultAccessMode,
70-
bookmarks,
70+
bookmarkOrBookmarks: bookmarks,
7171
database,
7272
impersonatedUser,
7373
reactive: true,

packages/neo4j-driver/test/driver.test.js

+27-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ import {
2626
} from '../../bolt-connection/lib/pool/pool-config'
2727
import { ServerVersion, VERSION_4_0_0 } from '../src/internal/server-version'
2828
import testUtils from './internal/test-utils'
29-
import { json } from 'neo4j-driver-core'
29+
import { json, internal } from 'neo4j-driver-core'
30+
31+
const { bookmark } = internal
3032

3133
// As long as driver creation doesn't touch the network it's fine to run
3234
// this as a unit test.
@@ -114,6 +116,30 @@ describe('#unit driver', () => {
114116
})
115117
).toThrow()
116118
})
119+
120+
describe('.rxSession()', () => {
121+
;[
122+
[undefined, bookmark.Bookmark.empty()],
123+
[null, bookmark.Bookmark.empty()],
124+
['bookmark', new bookmark.Bookmark('bookmark')],
125+
[['bookmark'], new bookmark.Bookmark(['bookmark'])],
126+
[
127+
['bookmark1', 'bookmark2'],
128+
new bookmark.Bookmark(['bookmark1', 'bookmark2'])
129+
]
130+
].forEach(([bookmarks, expectedBookmarks]) => {
131+
driver = neo4j.driver(
132+
`bolt://${sharedNeo4j.hostname}`,
133+
sharedNeo4j.authToken
134+
)
135+
136+
it(`should create session using param bookmarks=${bookmark}`, () => {
137+
const session = driver.rxSession({ bookmarks })
138+
139+
expect(session.lastBookmark()).toEqual(expectedBookmarks.values())
140+
})
141+
})
142+
})
117143
})
118144

119145
describe('#integration driver', () => {

packages/neo4j-driver/test/types/driver.test.ts

+9
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,15 @@ const rxSession9: RxSession = driver.rxSession({
135135
bookmarks: ['bookmark1', 'bookmark2']
136136
})
137137

138+
const rxSession10: RxSession = driver.rxSession({
139+
defaultAccessMode: WRITE,
140+
bookmarks: 'bookmark1'
141+
})
142+
const rxSession11: RxSession = driver.rxSession({
143+
defaultAccessMode: WRITE,
144+
bookmarks: ['bookmark1', 'bookmark2']
145+
})
146+
138147
rxSession1
139148
.run('RETURN 1')
140149
.records()

packages/neo4j-driver/test/types/session-rx.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const txConfig7: TransactionConfig = {
7474
}
7575

7676
const tx1: Observable<RxTransaction> = rxSession.beginTransaction()
77-
const bookmark: null | string = <null>rxSession.lastBookmark()
77+
const bookmark: string[] = rxSession.lastBookmark()
7878

7979
const observable1: Observable<number> = rxSession.readTransaction(
8080
(tx: RxTransaction) => {

packages/neo4j-driver/types/session-rx.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ declare interface RxSession {
3333

3434
beginTransaction(config?: TransactionConfig): Observable<RxTransaction>
3535

36-
lastBookmark(): string | null
36+
lastBookmark(): string[]
3737

3838
readTransaction<T>(
3939
work: RxTransactionWork<T>,

0 commit comments

Comments
 (0)