1- import { chance , expect , isError } from '../common'
1+ import { chance , expect , isNitroSQLiteError } from '../common'
22import { describe , it } from '../../MochaRNAdapter'
33import type { User } from '../../../model/User'
44import { testDb , testDbQueue } from '../../db'
55
6+ const DUMMY_ERROR_NAME = 'Transaction Rejection Error'
7+ const DUMMY_ERROR_MESSAGE = 'Error from callback'
8+
69export default function registerTransactionUnitTests ( ) {
710 describe ( 'transaction' , ( ) => {
811 it ( 'Transaction, auto commit' , async ( ) => {
@@ -199,17 +202,18 @@ export default function registerTransactionUnitTests() {
199202
200203 it ( 'Transaction, rejects on callback error' , async ( ) => {
201204 const promised = testDb . transaction ( ( ) => {
202- throw new Error ( 'Error from callback' )
205+ throw new Error ( DUMMY_ERROR_MESSAGE )
203206 } )
204207
205208 // ASSERT: should return a promise that eventually rejects
206209 expect ( promised ) . to . have . property ( 'then' ) . that . is . a ( 'function' )
207210 try {
208211 await promised
209- expect . fail ( 'Should not resolve' )
212+ expect . fail ( DUMMY_ERROR_NAME )
210213 } catch ( e ) {
211- if ( isError ( e ) ) expect ( e . message ) . to . equal ( 'Error from callback' )
212- else expect . fail ( 'Should have thrown a valid NitroSQLiteException' )
214+ if ( isNitroSQLiteError ( e ) )
215+ expect ( e . message ) . to . include ( DUMMY_ERROR_MESSAGE )
216+ else expect . fail ( 'Should have thrown a valid NitroSQLiteError' )
213217 }
214218 } )
215219
@@ -221,11 +225,11 @@ export default function registerTransactionUnitTests() {
221225 expect ( promised ) . to . have . property ( 'then' ) . that . is . a ( 'function' )
222226 try {
223227 await promised
224- expect . fail ( 'Should not resolve' )
228+ expect . fail ( DUMMY_ERROR_NAME )
225229 } catch ( e ) {
226- if ( isError ( e ) )
230+ if ( isNitroSQLiteError ( e ) )
227231 expect ( e . message ) . to . include ( 'no such table: tableThatDoesNotExist' )
228- else expect . fail ( 'Should have thrown a valid NitroSQLiteException ' )
232+ else expect . fail ( 'Should have thrown a valid NitroSQLiteError ' )
229233 }
230234 } )
231235
@@ -289,15 +293,15 @@ export default function registerTransactionUnitTests() {
289293 )
290294 } )
291295 } catch ( e ) {
292- if ( isError ( e ) ) {
296+ if ( isNitroSQLiteError ( e ) ) {
293297 expect ( e . message )
294298 . to . include ( 'SqlExecutionError' )
295299 . and . to . include ( 'cannot store TEXT value in REAL column User.id' )
296300
297301 const res = testDb . execute ( 'SELECT * FROM User' )
298302 expect ( res . rows ?. _array ) . to . eql ( [ ] )
299303 } else {
300- expect . fail ( 'Should have thrown a valid NitroSQLiteException ' )
304+ expect . fail ( 'Should have thrown a valid NitroSQLiteError ' )
301305 }
302306 }
303307 } )
@@ -401,17 +405,18 @@ export default function registerTransactionUnitTests() {
401405
402406 it ( 'Async transaction, rejects on callback error' , async ( ) => {
403407 const promised = testDb . transaction ( ( ) => {
404- throw new Error ( 'Error from callback' )
408+ throw new Error ( DUMMY_ERROR_MESSAGE )
405409 } )
406410
407411 // ASSERT: should return a promise that eventually rejects
408412 expect ( promised ) . to . have . property ( 'then' ) . that . is . a ( 'function' )
409413 try {
410414 await promised
411- expect . fail ( 'Should not resolve' )
415+ expect . fail ( DUMMY_ERROR_NAME )
412416 } catch ( e ) {
413- if ( isError ( e ) ) expect ( e . message ) . to . equal ( 'Error from callback' )
414- else expect . fail ( 'Should have thrown a valid NitroSQLiteException' )
417+ if ( isNitroSQLiteError ( e ) )
418+ expect ( e . message ) . to . include ( DUMMY_ERROR_MESSAGE )
419+ else expect . fail ( 'Should have thrown a valid NitroSQLiteError' )
415420 }
416421 } )
417422
@@ -424,11 +429,11 @@ export default function registerTransactionUnitTests() {
424429 expect ( promised ) . to . have . property ( 'then' ) . that . is . a ( 'function' )
425430 try {
426431 await promised
427- expect . fail ( 'Should not resolve' )
432+ expect . fail ( DUMMY_ERROR_NAME )
428433 } catch ( e ) {
429- if ( isError ( e ) )
434+ if ( isNitroSQLiteError ( e ) )
430435 expect ( e . message ) . to . include ( 'no such table: tableThatDoesNotExist' )
431- else expect . fail ( 'Should have thrown a valid NitroSQLiteException ' )
436+ else expect . fail ( 'Should have thrown a valid NitroSQLiteError ' )
432437 }
433438 } )
434439
0 commit comments