Skip to content

Fix driver.rxSession initial bookmarks configuration and RxSession.lastBookmark return mapping #854

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/neo4j-driver/src/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class Driver extends CoreDriver {
return new RxSession({
session: this._newSession({
defaultAccessMode,
bookmarks,
bookmarkOrBookmarks: bookmarks,
database,
impersonatedUser,
reactive: true,
Expand Down
28 changes: 27 additions & 1 deletion packages/neo4j-driver/test/driver.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ import {
} from '../../bolt-connection/lib/pool/pool-config'
import { ServerVersion, VERSION_4_0_0 } from '../src/internal/server-version'
import testUtils from './internal/test-utils'
import { json } from 'neo4j-driver-core'
import { json, internal } from 'neo4j-driver-core'

const { bookmark } = internal

// As long as driver creation doesn't touch the network it's fine to run
// this as a unit test.
Expand Down Expand Up @@ -114,6 +116,30 @@ describe('#unit driver', () => {
})
).toThrow()
})

describe('.rxSession()', () => {
;[
[undefined, bookmark.Bookmark.empty()],
[null, bookmark.Bookmark.empty()],
['bookmark', new bookmark.Bookmark('bookmark')],
[['bookmark'], new bookmark.Bookmark(['bookmark'])],
[
['bookmark1', 'bookmark2'],
new bookmark.Bookmark(['bookmark1', 'bookmark2'])
]
].forEach(([bookmarks, expectedBookmarks]) => {
driver = neo4j.driver(
`bolt://${sharedNeo4j.hostname}`,
sharedNeo4j.authToken
)

it(`should create session using param bookmarks=${bookmark}`, () => {
const session = driver.rxSession({ bookmarks })

expect(session.lastBookmark()).toEqual(expectedBookmarks.values())
})
})
})
})

describe('#integration driver', () => {
Expand Down
9 changes: 9 additions & 0 deletions packages/neo4j-driver/test/types/driver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,15 @@ const rxSession9: RxSession = driver.rxSession({
bookmarks: ['bookmark1', 'bookmark2']
})

const rxSession10: RxSession = driver.rxSession({
defaultAccessMode: WRITE,
bookmarks: 'bookmark1'
})
const rxSession11: RxSession = driver.rxSession({
defaultAccessMode: WRITE,
bookmarks: ['bookmark1', 'bookmark2']
})

rxSession1
.run('RETURN 1')
.records()
Expand Down
2 changes: 1 addition & 1 deletion packages/neo4j-driver/test/types/session-rx.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const txConfig7: TransactionConfig = {
}

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

const observable1: Observable<number> = rxSession.readTransaction(
(tx: RxTransaction) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/neo4j-driver/types/session-rx.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ declare interface RxSession {

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

lastBookmark(): string | null
lastBookmark(): string[]

readTransaction<T>(
work: RxTransactionWork<T>,
Expand Down