Skip to content

Commit b51a5bb

Browse files
author
Peter Wilhelmsson
authored
Fixed tests that were too sensitive to error text changes (#569)
* Fixed tests that were too sensitive to error text changes Tests were red on 4.1 due to error texts changed in the server. Make sure to only check for keywords that are very likely to exist in the message. * Different type of error returned for transaction timeout, support both
1 parent 009d9e4 commit b51a5bb

File tree

3 files changed

+30
-27
lines changed

3 files changed

+30
-27
lines changed

test/bolt-v3.test.js

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,21 @@ describe('#integration Bolt V3 API', () => {
8585
await tx.run('MATCH (n:Node) SET n.prop = 1') // lock dummy node but keep the transaction open
8686

8787
// run a query in an auto-commit transaction with timeout and try to update the locked dummy node
88-
await expectAsync(
89-
session.run(
88+
try {
89+
await session.run(
9090
'MATCH (n:Node) SET n.prop = $newValue',
9191
{ newValue: 2 },
9292
{ timeout: 1 }
9393
)
94-
).toBeRejectedWith(
95-
jasmine.objectContaining({
96-
message: jasmine.stringMatching(/transaction has been terminated/)
97-
})
98-
)
99-
94+
} catch (e) {
95+
// ClientError on 4.1 and later
96+
if (
97+
e.code != 'Neo.ClientError.Transaction.TransactionTimedOut' &&
98+
e.code != 'Neo.TransientError.Transaction.LockClientStopped'
99+
) {
100+
fail('Expected transaction timeout error but got: ' + e.code)
101+
}
102+
}
100103
await tx.rollback()
101104
await otherSession.close()
102105
})
@@ -175,13 +178,21 @@ describe('#integration Bolt V3 API', () => {
175178

176179
// run a query in an explicit transaction with timeout and try to update the locked dummy node
177180
const tx = session.beginTransaction({ timeout: 1 })
178-
await expectAsync(
179-
tx.run('MATCH (n:Node) SET n.prop = $newValue', { newValue: 2 })
180-
).toBeRejectedWith(
181-
jasmine.objectContaining({
182-
message: jasmine.stringMatching(/transaction has been terminated/)
183-
})
184-
)
181+
try {
182+
await tx.run(
183+
'MATCH (n:Node) SET n.prop = $newValue',
184+
{ newValue: 2 },
185+
{ timeout: 1 }
186+
)
187+
} catch (e) {
188+
// ClientError on 4.1 and later
189+
if (
190+
e.code != 'Neo.ClientError.Transaction.TransactionTimedOut' &&
191+
e.code != 'Neo.TransientError.Transaction.LockClientStopped'
192+
) {
193+
fail('Expected transaction timeout error but got: ' + e.code)
194+
}
195+
}
185196

186197
await otherTx.rollback()
187198
await otherSession.close()

test/rx/summary.test.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ describe('#integration-rx summary', () => {
627627
}
628628

629629
const summary = await runnable
630-
.run('EXPLAIN MATCH (n:ThisLabelDoesNotExist) RETURN n')
630+
.run('EXPLAIN MATCH (n:ThisLabelDoesNotExistRx) RETURN n')
631631
.consume()
632632
.toPromise()
633633
expect(summary).toBeDefined()
@@ -636,14 +636,8 @@ describe('#integration-rx summary', () => {
636636
expect(summary.notifications[0].code).toBe(
637637
'Neo.ClientNotification.Statement.UnknownLabelWarning'
638638
)
639-
expect(summary.notifications[0].title).toBe(
640-
'The provided label is not in the database.'
641-
)
642-
expect(summary.notifications[0].description).toBe(
643-
"One of the labels in your query is not available in the database, make sure you didn't misspell it or that" +
644-
' the label is available when you run this statement in your application (the missing label name is:' +
645-
' ThisLabelDoesNotExist)'
646-
)
639+
expect(summary.notifications[0].title).toContain('label')
640+
expect(summary.notifications[0].description).toContain('label')
647641
expect(summary.notifications[0].severity).toBe('WARNING')
648642
}
649643

test/session.test.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,7 @@ describe('#integration session', () => {
312312
expect(sum.notifications[0].code).toBe(
313313
'Neo.ClientNotification.Statement.UnknownLabelWarning'
314314
)
315-
expect(sum.notifications[0].title).toBe(
316-
'The provided label is not in the database.'
317-
)
315+
expect(sum.notifications[0].title).toContain('label')
318316
expect(sum.notifications[0].position.column).toBeGreaterThan(0)
319317
done()
320318
})

0 commit comments

Comments
 (0)