This commit is contained in:
Luke Crouch 2019-05-06 15:48:42 -05:00
Родитель a63203decd
Коммит 2ec804d05b
2 изменённых файлов: 26 добавлений и 2 удалений

Просмотреть файл

@ -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);
});