@@ -28,6 +28,7 @@ const invoiceFixture = require('../../payments/fixtures/stripe/invoice_paid.json
2828const subscriptionCreated = require ( '../../payments/fixtures/stripe/subscription_created.json' ) ;
2929const subscriptionCreatedIncomplete = require ( '../../payments/fixtures/stripe/subscription_created_incomplete.json' ) ;
3030const subscriptionDeleted = require ( '../../payments/fixtures/stripe/subscription_deleted.json' ) ;
31+ const subscriptionReplaced = require ( '../../payments/fixtures/stripe/subscription_replaced.json' ) ;
3132const subscriptionUpdated = require ( '../../payments/fixtures/stripe/subscription_updated.json' ) ;
3233const subscriptionUpdatedFromIncomplete = require ( '../../payments/fixtures/stripe/subscription_updated_from_incomplete.json' ) ;
3334const eventInvoiceCreated = require ( '../../payments/fixtures/stripe/event_invoice_created.json' ) ;
@@ -1120,6 +1121,54 @@ describe('StripeWebhookHandler', () => {
11201121 ) ;
11211122 } ) ;
11221123
1124+ it ( 'sends subscriptionReplaced email if metadata includes redundantCancellation' , async ( ) => {
1125+ const mockCustomer = deepCopy ( customerFixture ) ;
1126+ StripeWebhookHandlerInstance . stripeHelper . expandResource . resolves (
1127+ mockCustomer
1128+ ) ;
1129+ const deletedEvent = deepCopy ( subscriptionReplaced ) ;
1130+ const account = {
1131+ email : customerFixture . email ,
1132+ emails : customerFixture . email ,
1133+ locale : 'en' ,
1134+ } ;
1135+ sandbox . stub ( authDbModule . Account , 'findByUid' ) . resolves ( account ) ;
1136+ const mockInvoice = deepCopy ( invoiceFixture ) ;
1137+ StripeWebhookHandlerInstance . stripeHelper . extractSubscriptionDeletedEventDetailsForEmail . resolves (
1138+ mockInvoice
1139+ ) ;
1140+ StripeWebhookHandlerInstance . mailer . sendSubscriptionReplacedEmail =
1141+ sandbox . stub ( ) ;
1142+ await StripeWebhookHandlerInstance . handleSubscriptionDeletedEvent (
1143+ { } ,
1144+ deletedEvent
1145+ ) ;
1146+ assert . calledWith ( mockCapabilityService . stripeUpdate , {
1147+ sub : deletedEvent . data . object ,
1148+ uid : customerFixture . metadata . userid ,
1149+ } ) ;
1150+ assert . notCalled ( authDbModule . getUidAndEmailByStripeCustomerId ) ;
1151+ assert . calledOnceWithExactly (
1152+ StripeWebhookHandlerInstance . paypalHelper
1153+ . conditionallyRemoveBillingAgreement ,
1154+ customerFixture
1155+ ) ;
1156+ assert . calledOnceWithExactly (
1157+ StripeWebhookHandlerInstance . stripeHelper
1158+ . extractSubscriptionDeletedEventDetailsForEmail ,
1159+ deletedEvent . data . object
1160+ ) ;
1161+ assert . calledWith (
1162+ StripeWebhookHandlerInstance . mailer . sendSubscriptionReplacedEmail ,
1163+ account . emails ,
1164+ account ,
1165+ {
1166+ acceptLanguage : account . locale ,
1167+ ...mockInvoice ,
1168+ }
1169+ ) ;
1170+ } ) ;
1171+
11231172 it ( 'does not conditionally delete without customer record' , async ( ) => {
11241173 const deletedEvent = deepCopy ( subscriptionDeleted ) ;
11251174 StripeWebhookHandlerInstance . stripeHelper . expandResource . resolves ( ) ;
0 commit comments