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