mirror of
https://github.com/outline/outline.git
synced 2026-11-21 13:34:02 +03:00
* 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
57 lines
1.6 KiB
TypeScript
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();
|
|
});
|
|
});
|