Files
outline/server/queues/processors/UserUpdatedProcessor.test.ts
Tom Moor 9c6a940f42 Send security notice to previous address when account email changes (#13979)
* feat: Send security notice to previous address when account email changes

* refactor: Send email change notice from a users.update processor

* fix: Notify previous email address even if the user was deleted
2026-10-10 08:27:47 -04:00

57 lines
1.6 KiB
TypeScript

import { faker } from "@faker-js/faker";
import EmailUpdatedEmail from "@server/emails/templates/EmailUpdatedEmail";
import { buildUser } from "@server/test/factories";
import UserUpdatedProcessor from "./UserUpdatedProcessor";
const ip = "127.0.0.1";
afterEach(() => {
vi.restoreAllMocks();
});
describe("UserUpdatedProcessor", () => {
it("should send a security notice to the previous email", async () => {
const user = await buildUser();
const email = faker.internet.email().toLowerCase();
const spy = vi.spyOn(EmailUpdatedEmail.prototype, "schedule");
const processor = new UserUpdatedProcessor();
await processor.perform({
name: "users.update",
userId: user.id,
teamId: user.teamId,
actorId: user.id,
ip,
changes: {
attributes: { email },
previous: { email: user.email },
},
});
expect(spy).toHaveBeenCalledTimes(1);
expect(spy.mock.contexts[0]).toMatchObject({
props: expect.objectContaining({ to: user.email, email }),
});
});
it("should not send a security notice when the email did not change", async () => {
const user = await buildUser();
const spy = vi.spyOn(EmailUpdatedEmail.prototype, "schedule");
const processor = new UserUpdatedProcessor();
await processor.perform({
name: "users.update",
userId: user.id,
teamId: user.teamId,
actorId: user.id,
ip,
changes: {
attributes: { name: "New name" },
previous: { name: user.name },
},
});
expect(spy).not.toHaveBeenCalled();
});
});