Skip to content

Commit

Permalink
fix(auth): pass Product/Plan Metadata to Email Sender
Browse files Browse the repository at this point in the history
Because:

* The email sender defaults to the VPN's privacy and ToS links in the email footer, we need to pass the product/plan specific metadata

This commit:

* passes the metadata from the formattedSubscription object to the message received by the email sender

Closes #12655
  • Loading branch information
IvoJP committed May 11, 2022
1 parent 626c834 commit 2cae023
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export class SubscriptionReminders {
// Using invoice prefix instead of plan to accomodate `yarn write-emails`.
invoiceTotalInCents: amount,
invoiceTotalCurrency: currency,
productMetadata: formattedSubscription.productMetadata,
}
);
await this.updateSentEmail(uid, emailParams);
Expand Down
3 changes: 2 additions & 1 deletion packages/fxa-auth-server/lib/senders/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -2789,7 +2789,8 @@ module.exports = function (log, config, bounces) {
privacyNoticeDownloadURL = this.privacyUrl,
} = productDetailsFromPlan(
{
product_metadata: message.productMetadata,
product_metadata:
message.productMetadata || message.subscription?.productMetadata,
},
determineLocale(message.acceptLanguage)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,11 @@ describe('SubscriptionReminders', () => {
},
};
reminder.alreadySentEmail = sandbox.fake.resolves(false);
const account = { emails: [], email: 'testo@test.test', locale: 'NZ' };
const account = {
emails: [],
email: 'testo@test.test',
locale: 'NZ',
};
reminder.db.account = sandbox.fake.resolves(account);
mockLog.info = sandbox.fake.returns({});
mockStripeHelper.formatSubscriptionForEmail = sandbox.fake.resolves({});
Expand All @@ -264,8 +268,15 @@ describe('SubscriptionReminders', () => {
interval_count: longPlan1.interval_count,
interval: longPlan1.interval,
});
const formattedSubscription = {
id: 'subscriptionId',
productMetadata: {
privacyUrl: 'http://privacy',
termsOfServiceUrl: 'http://tos',
},
};
reminder.mailer.sendSubscriptionRenewalReminderEmail =
sandbox.fake.resolves({});
sandbox.fake.resolves(formattedSubscription);
reminder.updateSentEmail = sandbox.fake.resolves({});
const realDateNow = Date.now.bind(global.Date);
Date.now = sinon.fake(() => MOCK_DATETIME_MS);
Expand Down Expand Up @@ -305,12 +316,13 @@ describe('SubscriptionReminders', () => {
acceptLanguage: account.locale,
uid: 'uid',
email: 'testo@test.test',
subscription: {},
subscription: formattedSubscription,
reminderLength: 14,
planIntervalCount: 1,
planInterval: 'month',
invoiceTotalInCents: 499,
invoiceTotalCurrency: 'usd',
productMetadata: formattedSubscription.productMetadata,
}
);
sinon.assert.calledOnceWithExactly(
Expand Down

0 comments on commit 2cae023

Please sign in to comment.