Skip to content

Moving some Type and Transaction ITs to Testkit #724

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
Apr 21, 2021
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
161 changes: 1 addition & 160 deletions test/transaction.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,23 +188,6 @@ describe('#integration transaction', () => {
)
}, 60000)

it('should handle when committing when another query fails', async () => {
// When
const tx = session.beginTransaction()

await expectAsync(tx.run('CREATE (:TXNode1)')).toBeResolved()
await expectAsync(tx.run('THIS IS NOT CYHER')).toBeRejectedWith(
jasmine.objectContaining({
message: jasmine.stringMatching(/Invalid input/)
})
)
await expectAsync(tx.commit()).toBeRejectedWith(
jasmine.objectContaining({
message: jasmine.stringMatching(/Cannot commit this transaction/)
})
)
}, 60000)

it('should handle rollbacks', done => {
const tx = session.beginTransaction()
tx.run('CREATE (:TXNode1)')
Expand Down Expand Up @@ -232,147 +215,6 @@ describe('#integration transaction', () => {
.catch(console.log)
}, 60000)

it('should fail when committing on a rolled back query', async () => {
const tx = session.beginTransaction()
await tx.run('CREATE (:TXNode1)')
await tx.rollback()

await expectAsync(tx.commit()).toBeRejectedWith(
jasmine.objectContaining({
message: jasmine.stringMatching(
/Cannot commit this transaction, because .* rolled back/
)
})
)
}, 60000)

it('should fail when running on a rolled back transaction', async () => {
const tx = session.beginTransaction()
await tx.run('CREATE (:TXNode1)')
await tx.rollback()

await expectAsync(tx.run('RETURN 42')).toBeRejectedWith(
jasmine.objectContaining({
message: jasmine.stringMatching(
/Cannot run query in this transaction, because .* rolled back/
)
})
)
}, 60000)

it('should fail running when a previous query failed', async () => {
const tx = session.beginTransaction()

await expectAsync(tx.run('THIS IS NOT CYPHER')).toBeRejectedWith(
jasmine.stringMatching(/Invalid input/)
)

await expectAsync(tx.run('RETURN 42')).toBeRejectedWith(
jasmine.objectContaining({
message: jasmine.stringMatching(
/Cannot run query in this transaction, because .* an error/
)
})
)
await tx.rollback()
}, 60000)

it('should fail when trying to roll back a rolled back transaction', async () => {
const tx = session.beginTransaction()
await tx.run('CREATE (:TXNode1)')
await tx.rollback()

await expectAsync(tx.rollback()).toBeRejectedWith(
jasmine.objectContaining({
message: jasmine.stringMatching(
/Cannot rollback this transaction, because .* rolled back/
)
})
)
}, 60000)

it('should provide bookmark on commit', done => {
// new session without initial bookmark
session = driver.session()
expect(session.lastBookmark()).toEqual([])

const tx = session.beginTransaction()
tx.run('CREATE (:TXNode1)')
.then(() => {
tx.run('CREATE (:TXNode2)')
.then(() => {
tx.commit().then(() => {
expectValidLastBookmark(session)
done()
})
})
.catch(console.log)
})
.catch(console.log)
}, 60000)

it('should have bookmark when tx is rolled back', done => {
// new session without initial bookmark
session = driver.session()
expect(session.lastBookmark()).toEqual([])

const tx1 = session.beginTransaction()
tx1.run('CREATE ()').then(() => {
tx1.commit().then(() => {
expectValidLastBookmark(session)
const bookmarkBefore = session.lastBookmark()

const tx2 = session.beginTransaction()
tx2.run('CREATE ()').then(() => {
tx2.rollback().then(() => {
expectValidLastBookmark(session)
const bookmarkAfter = session.lastBookmark()
expect(bookmarkAfter).toEqual(bookmarkBefore)

const tx3 = session.beginTransaction()
tx3.run('CREATE ()').then(() => {
tx3.commit().then(() => {
expectValidLastBookmark(session)
done()
})
})
})
})
})
})
}, 60000)

it('should have no bookmark when tx fails', done => {
// new session without initial bookmark
session = driver.session()
expect(session.lastBookmark()).toEqual([])

const tx1 = session.beginTransaction()

tx1.run('CREATE ()').then(() => {
tx1.commit().then(() => {
expectValidLastBookmark(session)
const bookmarkBefore = session.lastBookmark()

const tx2 = session.beginTransaction()

tx2.run('RETURN').catch(error => {
expectSyntaxError(error)
const bookmarkAfter = session.lastBookmark()
expect(bookmarkAfter).toEqual(bookmarkBefore)

const tx3 = session.beginTransaction()
tx3.run('CREATE ()').then(() => {
tx3.commit().then(() => {
expectValidLastBookmark(session)
done()
})
})
})
})
})
}, 60000)

it('should throw when provided string (bookmark) parameter', () => {
expect(() => session.beginTransaction('bookmark')).toThrowError(TypeError)
}, 60000)
Expand All @@ -399,11 +241,10 @@ describe('#integration transaction', () => {
})
const tx2 = session2.beginTransaction()
tx2.run('CREATE ()').catch(error => {
const message = error.message
// Checking message text on <= 4.0, check code for >= 4.1
expect(
error.message.includes('not up to the requested version') ||
error.code == 'Neo.ClientError.Transaction.InvalidBookmark'
error.code === 'Neo.ClientError.Transaction.InvalidBookmark'
).toBeTruthy()
done()
})
Expand Down
31 changes: 0 additions & 31 deletions test/types.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ describe('#integration floating point values', () => {
})

describe('#integration integer values', () => {
it('should support integer 1 ', testValue(neo4j.int(1)))
it('should support integer 0 ', testValue(neo4j.int(0)))
it('should support integer -1 ', testValue(neo4j.int(-1)))
it(
'should support integer larger than JS Numbers can model',
testValue(neo4j.int('0x7fffffffffffffff'))
Expand All @@ -50,31 +47,17 @@ describe('#integration integer values', () => {

describe('#integration boolean values', () => {
it('should support true ', testValue(true))
it('should support false ', testValue(false))
})

describe('#integration string values', () => {
it('should support empty string ', testValue(''))
it('should support simple string ', testValue('abcdefghijklmnopqrstuvwxyz'))
it(
'should support awesome string ',
testValue('All makt åt Tengil, vår befriare.')
)
it('should support long string', testValue('*'.repeat(10000)))
})

describe('#integration list values', () => {
it('should support empty lists ', testValue([]))
it('should support sparse lists ', testValue([undefined, 4], [null, 4]))
it('should support float lists ', testValue([1, 2, 3]))
it('should support boolean lists ', testValue([true, false]))
it('should support string lists ', testValue(['', 'hello!']))
it('should support list lists ', testValue([[], [1, 2, 3]]))
it('should support map lists ', testValue([{}, { a: 12 }]))
it(
'should support long list',
testValue(Array.from({ length: 1000 }, (v, i) => i))
)
})

describe('#integration map values', () => {
Expand All @@ -83,20 +66,6 @@ describe('#integration map values', () => {
'should support basic maps ',
testValue({ a: 1, b: {}, c: [], d: { e: 1 } })
)
it(
'should support sparse maps ',
testValue({ foo: undefined, bar: null }, { bar: null })
)

function longMap () {
const map = {}
for (let i = 0; i < 1000; i++) {
map['key' + i] = i
}
return map
}

it('should support long maps', testValue(longMap()))
})

describe('#integration node values', () => {
Expand Down