fix getUnsubscribeUrl
This commit is contained in:
Родитель
a63203decd
Коммит
2ec804d05b
|
@ -107,8 +107,10 @@ const EmailUtils = {
|
|||
|
||||
getUnsubscribeUrl(subscriber, emailType) {
|
||||
let url = new URL(`${AppConstants.SERVER_URL}/user/unsubscribe`);
|
||||
url.searchParams.append("token", encodeURIComponent(subscriber.verification_token));
|
||||
url.searchParams.append("hash", encodeURIComponent(subscriber.sha1));
|
||||
const token = (subscriber.hasOwnProperty("verification_token")) ? subscriber.verification_token : subscriber.primary_verification_token;
|
||||
const hash = (subscriber.hasOwnProperty("sha1")) ? subscriber.sha1 : subscriber.primary_sha1;
|
||||
url.searchParams.append("token", encodeURIComponent(token))
|
||||
url.searchParams.append("hash", encodeURIComponent(hash));
|
||||
url = this.appendUtmParams(url, "unsubscribe", emailType);
|
||||
return url;
|
||||
},
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
const nodemailer = require("nodemailer");
|
||||
|
||||
const EmailUtils = require("../email-utils");
|
||||
const { TEST_SUBSCRIBERS, TEST_EMAIL_ADDRESSES } = require("../db/seeds/test_subscribers");
|
||||
|
||||
|
||||
jest.mock("nodemailer");
|
||||
|
@ -41,3 +42,24 @@ test("EmailUtils.sendEmail with recipient, subject, template, context calls gTra
|
|||
|
||||
// TODO: find a way to expect gTransporter.sendMail
|
||||
});
|
||||
|
||||
|
||||
test("EmailUtils.getUnsubscribeUrl works with subscriber record", () => {
|
||||
const subscriberRecord = TEST_SUBSCRIBERS.firefox_account;
|
||||
|
||||
const unsubUrl = EmailUtils.getUnsubscribeUrl(subscriberRecord).toString();
|
||||
|
||||
expect(unsubUrl).toMatch(subscriberRecord.primary_sha1);
|
||||
expect(unsubUrl).toMatch(subscriberRecord.primary_verification_token);
|
||||
|
||||
});
|
||||
|
||||
|
||||
test("EmailUtils.getUnsubscribeUrl works with email_address record", () => {
|
||||
const emailAddressRecord = TEST_EMAIL_ADDRESSES.firefox_account;
|
||||
|
||||
const unsubUrl = EmailUtils.getUnsubscribeUrl(emailAddressRecord).toString();
|
||||
|
||||
expect(unsubUrl).toMatch(emailAddressRecord.sha1);
|
||||
expect(unsubUrl).toMatch(emailAddressRecord.verification_token);
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче