Skip to content

Commit

Permalink
fixup! fixup! Port breach alert email to new email template
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinnl committed Aug 1, 2024
1 parent 26e4301 commit 2659b15
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/scripts/cronjobs/emailBreachAlerts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,51 @@ test("processes valid messages", async () => {
);
});

test("rendering the new template if the `RedesignedEmails` flag is enabled", async () => {
const mockedFeatureFlagModule: any = jest.requireMock(
"../../db/tables/featureFlags",
);
mockedFeatureFlagModule.getEnabledFeatureFlags.mockResolvedValue([
"RedesignedEmails",
]);
const consoleLog = jest
.spyOn(console, "log")
.mockImplementation(() => undefined);
// It's not clear if the calls to console.info are important enough to remain,
// but since they were already there when adding the "no logs" rule in tests,
// I'm respecting Chesterton's Fence and leaving them in place for now:
jest.spyOn(console, "info").mockImplementation(() => undefined);
const emailMod = await import("../../utils/email.js");
const sendEmail = emailMod.sendEmail as jest.Mock<
(typeof emailMod)["sendEmail"]
>;

const mockedUtilsHibp: any = jest.requireMock("../../utils/hibp");
mockedUtilsHibp.getBreachByName.mockReturnValue({
IsVerified: true,
Domain: "test1",
IsFabricated: false,
IsSpamList: false,
});

const receivedMessages = buildReceivedMessages({
breachName: "test1",
hashPrefix: "test-prefix1",
hashSuffixes: ["test-suffix1"],
});

const { poll } = await import("./emailBreachAlerts");

await poll(subClient, receivedMessages);
expect(subClient.acknowledge).toHaveBeenCalledTimes(1);
expect(sendEmail).toHaveBeenCalledTimes(1);
const emailBody = sendEmail.mock.calls[0][2];
expect(emailBody).toContain("Questions about ⁨Mozilla Monitor⁩?");
expect(consoleLog).toHaveBeenCalledWith(
'Received message: {"breachName":"test1","hashPrefix":"test-prefix1","hashSuffixes":["test-suffix1"]}',
);
});

test("skipping email when subscriber id exists in email_notifications table", async () => {
const consoleLog = jest
.spyOn(console, "log")
Expand Down

0 comments on commit 2659b15

Please sign in to comment.