22
33const expect = require ( 'chai' ) . expect ;
44const MongoNetworkError = require ( '../../lib/core/error' ) . MongoNetworkError ;
5+ const isRetryableEndTransactionError = require ( '../../lib/core/error' )
6+ . isRetryableEndTransactionError ;
57
68describe ( 'MongoErrors' , function ( ) {
79 describe ( 'MongoNetworkError' , function ( ) {
@@ -19,4 +21,32 @@ describe('MongoErrors', function() {
1921 expect ( Object . getOwnPropertySymbols ( errorWithoutOption ) . length ) . to . equal ( 0 ) ;
2022 } ) ;
2123 } ) ;
24+
25+ describe ( '#isRetryableEndTransactionError' , function ( ) {
26+ context ( 'when the error has a RetryableWriteError label' , function ( ) {
27+ const error = new MongoNetworkError ( '' ) ;
28+ error . addErrorLabel ( 'RetryableWriteError' ) ;
29+
30+ it ( 'returns true' , function ( ) {
31+ expect ( isRetryableEndTransactionError ( error ) ) . to . be . true ;
32+ } ) ;
33+ } ) ;
34+
35+ context ( 'when the error does not have a RetryableWriteError label' , function ( ) {
36+ const error = new MongoNetworkError ( '' ) ;
37+ error . addErrorLabel ( 'InvalidLabel' ) ;
38+
39+ it ( 'returns false' , function ( ) {
40+ expect ( isRetryableEndTransactionError ( error ) ) . to . be . false ;
41+ } ) ;
42+ } ) ;
43+
44+ context ( 'when the error does not have any label' , function ( ) {
45+ const error = new MongoNetworkError ( '' ) ;
46+
47+ it ( 'returns false' , function ( ) {
48+ expect ( isRetryableEndTransactionError ( error ) ) . to . be . false ;
49+ } ) ;
50+ } ) ;
51+ } ) ;
2252} ) ;
0 commit comments