Skip to content

Commit bd25cb7

Browse files
committed
Added tests for invalid and unreachable bookmarks
1 parent 8291a56 commit bd25cb7

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

test/v1/transaction.test.js

+46-1
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,16 @@ import neo4j from "../../lib/v1";
2020

2121
describe('transaction', () => {
2222

23-
let driver, session, server;
23+
let driver;
24+
let session;
25+
let server;
26+
let originalTimeout;
2427

2528
beforeEach(done => {
29+
// make jasmine timeout high enough to test unreachable bookmarks
30+
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
31+
jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000;
32+
2633
driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"));
2734
driver.onCompleted = meta => {
2835
server = meta['server'];
@@ -33,6 +40,7 @@ describe('transaction', () => {
3340
});
3441

3542
afterEach(() => {
43+
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
3644
driver.close();
3745
});
3846

@@ -281,6 +289,43 @@ describe('transaction', () => {
281289
});
282290
});
283291

292+
it('should fail for invalid bookmark', done => {
293+
if (neo4jVersionOlderThan31(done)) {
294+
return;
295+
}
296+
297+
const invalidBookmark = 'hi, this is an invalid bookmark';
298+
const tx = session.beginTransaction(invalidBookmark);
299+
tx.run('RETURN 1').catch(error => {
300+
expect(error.fields[0].code).toBe('Neo.ClientError.Transaction.InvalidBookmark');
301+
done();
302+
});
303+
});
304+
305+
it('should fail to run query for unreachable bookmark', done => {
306+
if (neo4jVersionOlderThan31(done)) {
307+
return;
308+
}
309+
310+
const tx1 = session.beginTransaction();
311+
tx1.run('CREATE ()').then(result => {
312+
expect(result.summary.counters.nodesCreated()).toBe(1);
313+
314+
tx1.commit().then(() => {
315+
expectValidLastBookmark(session);
316+
317+
const unreachableBookmark = session.lastBookmark() + "0";
318+
const tx2 = session.beginTransaction(unreachableBookmark);
319+
tx2.run('CREATE ()').catch(error => {
320+
const message = error.fields[0].message;
321+
const expectedPrefix = message.indexOf('Database not up to the requested version') === 0;
322+
expect(expectedPrefix).toBeTruthy();
323+
done();
324+
});
325+
}).catch(console.log);
326+
}).catch(console.log);
327+
});
328+
284329
it('should rollback when very first run fails', done => {
285330
const tx1 = session.beginTransaction();
286331
tx1.run('RETURN foo').catch(error => {

0 commit comments

Comments
 (0)