@@ -162,7 +162,13 @@ describe("BillingService", () => {
162162
163163 const stripe = ( await import ( "@calcom/features/ee/payments/server/stripe" ) ) . default ;
164164 expect ( stripe . subscriptions . cancel ) . toHaveBeenCalledWith ( "sub_123" ) ;
165- expect ( mocks . mockPhoneNumberRepository . updateSubscriptionStatus ) . toHaveBeenCalledWith ( {
165+ expect ( mocks . mockPhoneNumberRepository . updateSubscriptionStatus ) . toHaveBeenCalledTimes ( 2 ) ;
166+ expect ( mocks . mockPhoneNumberRepository . updateSubscriptionStatus ) . toHaveBeenNthCalledWith ( 1 , {
167+ id : 1 ,
168+ subscriptionStatus : PhoneNumberSubscriptionStatus . CANCELLED ,
169+ disconnectOutboundAgent : false ,
170+ } ) ;
171+ expect ( mocks . mockPhoneNumberRepository . updateSubscriptionStatus ) . toHaveBeenNthCalledWith ( 2 , {
166172 id : 1 ,
167173 subscriptionStatus : PhoneNumberSubscriptionStatus . CANCELLED ,
168174 disconnectOutboundAgent : true ,
@@ -268,11 +274,15 @@ describe("BillingService", () => {
268274
269275 const stripe = ( await import ( "@calcom/features/ee/payments/server/stripe" ) ) . default ;
270276 stripe . subscriptions . cancel . mockRejectedValue ( {
271- type : "invalid_request_error" ,
277+ type : "StripeInvalidRequestError" ,
278+ raw : {
279+ code : "resource_missing" ,
280+ doc_url : "https://stripe.com/docs/error-codes/resource-missing" ,
281+ message : "No such subscription: 'sub_123'" ,
282+ param : "id" ,
283+ type : "invalid_request_error" ,
284+ } ,
272285 code : "resource_missing" ,
273- message : "No such subscription: 'sub_123'" ,
274- param : "id" ,
275- doc_url : "https://stripe.com/docs/error-codes/resource-missing" ,
276286 } ) ;
277287
278288 const result = await service . cancelPhoneNumberSubscription ( validCancelData ) ;
@@ -284,8 +294,14 @@ describe("BillingService", () => {
284294
285295 // Should attempt to cancel
286296 expect ( stripe . subscriptions . cancel ) . toHaveBeenCalledWith ( "sub_123" ) ;
287- // Should still update database even after 404
288- expect ( mocks . mockPhoneNumberRepository . updateSubscriptionStatus ) . toHaveBeenCalledWith ( {
297+ // Should update database twice: first CANCELLED (disconnectOutboundAgent: false), then final CANCELLED (disconnectOutboundAgent: true)
298+ expect ( mocks . mockPhoneNumberRepository . updateSubscriptionStatus ) . toHaveBeenCalledTimes ( 2 ) ;
299+ expect ( mocks . mockPhoneNumberRepository . updateSubscriptionStatus ) . toHaveBeenNthCalledWith ( 1 , {
300+ id : 1 ,
301+ subscriptionStatus : PhoneNumberSubscriptionStatus . CANCELLED ,
302+ disconnectOutboundAgent : false ,
303+ } ) ;
304+ expect ( mocks . mockPhoneNumberRepository . updateSubscriptionStatus ) . toHaveBeenNthCalledWith ( 2 , {
289305 id : 1 ,
290306 subscriptionStatus : PhoneNumberSubscriptionStatus . CANCELLED ,
291307 disconnectOutboundAgent : true ,
@@ -310,8 +326,16 @@ describe("BillingService", () => {
310326
311327 // Should attempt to cancel
312328 expect ( stripe . subscriptions . cancel ) . toHaveBeenCalledWith ( "sub_123" ) ;
313- // Should NOT update database due to error
314- expect ( mocks . mockPhoneNumberRepository . updateSubscriptionStatus ) . not . toHaveBeenCalled ( ) ;
329+ expect ( mocks . mockPhoneNumberRepository . updateSubscriptionStatus ) . toHaveBeenCalledTimes ( 2 ) ;
330+ expect ( mocks . mockPhoneNumberRepository . updateSubscriptionStatus ) . toHaveBeenNthCalledWith ( 1 , {
331+ id : 1 ,
332+ subscriptionStatus : PhoneNumberSubscriptionStatus . CANCELLED ,
333+ disconnectOutboundAgent : false ,
334+ } ) ;
335+ expect ( mocks . mockPhoneNumberRepository . updateSubscriptionStatus ) . toHaveBeenNthCalledWith ( 2 , {
336+ id : 1 ,
337+ subscriptionStatus : PhoneNumberSubscriptionStatus . ACTIVE ,
338+ } ) ;
315339 } ) ;
316340 } ) ;
317341} ) ;
0 commit comments