From 56ad66a95db9495c6ef50a477179574bdcf3e29e Mon Sep 17 00:00:00 2001 From: Julian Poyourow Date: Fri, 12 May 2023 10:39:36 -0700 Subject: [PATCH] feat(auth): change exclude behavior for mover script Because: * The product requirements changed regarding excluding customers. * We no longer want to cancel-only for excluded customers, but now want to exclude completely. This commit: * Excludes customers in the excluded list completely, rather than just excluding them from the cancellation behavior. Closes FXA-7448 --- .../fxa-auth-server/scripts/move-customers-to-new-plan.ts | 2 +- .../move-customers-to-new-plan.ts | 4 ++-- .../test/scripts/move-customers-to-new-plan.ts | 7 +++++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/fxa-auth-server/scripts/move-customers-to-new-plan.ts b/packages/fxa-auth-server/scripts/move-customers-to-new-plan.ts index cec68904690..6069b0add6e 100644 --- a/packages/fxa-auth-server/scripts/move-customers-to-new-plan.ts +++ b/packages/fxa-auth-server/scripts/move-customers-to-new-plan.ts @@ -48,7 +48,7 @@ async function init() { ) .option( '-e, --exclude [string]', - 'Do not sign customers up for the destination plan if they have a subscription to a price in this list', + 'Do not touch customers if they have a subscription to a price in this list', '' ) .option( diff --git a/packages/fxa-auth-server/scripts/move-customers-to-new-plan/move-customers-to-new-plan.ts b/packages/fxa-auth-server/scripts/move-customers-to-new-plan/move-customers-to-new-plan.ts index eacee14e25d..a73757539eb 100644 --- a/packages/fxa-auth-server/scripts/move-customers-to-new-plan/move-customers-to-new-plan.ts +++ b/packages/fxa-auth-server/scripts/move-customers-to-new-plan/move-customers-to-new-plan.ts @@ -140,10 +140,10 @@ export class CustomerPlanMover { const isExcluded = this.isCustomerExcluded(customer.subscriptions.data); - if (!this.dryRun) { + if (!this.dryRun && !isExcluded) { await this.cancelSubscription(firestoreSubscription); - if (!isExcluded) await this.createSubscription(customer.id); + await this.createSubscription(customer.id); } const report = this.buildReport(customer, account, isExcluded); diff --git a/packages/fxa-auth-server/test/scripts/move-customers-to-new-plan.ts b/packages/fxa-auth-server/test/scripts/move-customers-to-new-plan.ts index 9dcfc794508..951f1f3a981 100644 --- a/packages/fxa-auth-server/test/scripts/move-customers-to-new-plan.ts +++ b/packages/fxa-auth-server/test/scripts/move-customers-to-new-plan.ts @@ -277,6 +277,13 @@ describe('CustomerPlanMover', () => { expect(createSubscriptionStub.notCalled).true; }); + it('does not cancel subscription if customer is excluded', async () => { + customerPlanMover.isCustomerExcluded = sinon.stub().resolves(true); + await customerPlanMover.convertSubscription(mockFirestoreSub); + + expect(cancelSubscriptionStub.notCalled).true; + }); + it('does not move subscription if subscription is not in active state', async () => { await customerPlanMover.convertSubscription({ ...mockFirestoreSub,