@@ -33,11 +33,67 @@ describe('deleteConversation util', () => {
3333 expect ( removeSpy ) . toBeCalled ( )
3434 } )
3535
36- it . skip ( 'throws an error if Twilio client throws' , async ( ) => {
36+ it ( 'throws an error if Twilio client throws' , async ( ) => {
37+ let mockedClient = jest . mocked ( client , true )
3738
39+ let removeSpy = jest . fn ( ( ) => {
40+ throw new Error ( 'Twilio Problem' )
41+ } )
42+
43+ let conversationsSpy = jest . fn ( ( options ) => {
44+ return {
45+ remove : removeSpy
46+ }
47+ } )
48+
49+ mockedClient [ 'conversations' ] = {
50+ conversations : conversationsSpy
51+ } as any
52+
53+ const consoleSpy = jest . spyOn ( console , 'log' ) ;
54+
55+ try {
56+ await deleteConversation ( "myConversationSid" ) ;
57+ } catch ( e ) {
58+ expect ( consoleSpy ) . toHaveBeenCalledWith ( 'Quit without retry' ) ;
59+ }
3860 } )
3961
40- it . skip ( 'retrys if error is 429' , ( ) => {
62+ it ( 'retrys if error is 429' , async ( ) => {
63+ interface TwilioError extends Error {
64+ status : number
65+ }
66+
67+ class TwilioError extends Error {
68+ constructor ( message ) {
69+ super ( message ) ;
70+ this . name = "ConcurrencyLimit" ;
71+ this . status = 429
72+ }
73+ }
74+
75+ let mockedClient = jest . mocked ( client , true )
76+
77+ let removeSpy = jest . fn ( ( ) => {
78+ throw new TwilioError ( 'Too many connections' )
79+ } )
80+
81+ let conversationsSpy = jest . fn ( ( options ) => {
82+ return {
83+ remove : removeSpy
84+ }
85+ } )
86+
87+ mockedClient [ 'conversations' ] = {
88+ conversations : conversationsSpy
89+ } as any
90+
91+ const consoleSpy = jest . spyOn ( console , 'log' ) ;
4192
93+ try {
94+ await deleteConversation ( "myConversationSid" , { retries : 0 , factor : 1 , maxTimeout : 0 , minTimeout : 0 } ) ;
95+ } catch ( e ) {
96+ expect ( consoleSpy ) . toHaveBeenCalledWith ( 'Re-trying on 429 error' ) ;
97+ }
4298 } )
4399} )
0 commit comments