54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
vi.mock("~/utils/db/appConfiguration.db.server", () => ({
|
|
getAppConfiguration: vi.fn(),
|
|
}));
|
|
|
|
vi.mock("./MailjetEmailService", () => ({
|
|
sendEmailMailjet: vi.fn(async () => ({ provider: "queue", status: "queued", messageId: "job_1" })),
|
|
}));
|
|
|
|
import { getAppConfiguration } from "~/utils/db/appConfiguration.db.server";
|
|
import { sendEmailMailjet } from "./MailjetEmailService";
|
|
import { sendEmail } from "./EmailService";
|
|
|
|
const getAppConfigurationMock = vi.mocked(getAppConfiguration);
|
|
const sendEmailMailjetMock = vi.mocked(sendEmailMailjet);
|
|
|
|
describe("EmailService queued delivery", () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
delete process.env.MAILJET_API_KEY;
|
|
delete process.env.MAILJET_FROM_EMAIL;
|
|
getAppConfigurationMock.mockResolvedValue({
|
|
email: {
|
|
provider: "mailjet",
|
|
fromEmail: "",
|
|
fromName: "",
|
|
supportEmail: "",
|
|
},
|
|
} as Awaited<ReturnType<typeof getAppConfiguration>>);
|
|
});
|
|
|
|
it("queues mail without requiring Mailjet credentials in the web runtime", async () => {
|
|
await sendEmail({
|
|
request: new Request("https://admin.example.com/settings/transactional-emails"),
|
|
to: "ada@example.com",
|
|
subject: "Welcome",
|
|
body: "<p>Hello</p>",
|
|
alias: "registration-welcome",
|
|
data: { firstName: "Ada" },
|
|
});
|
|
|
|
expect(sendEmailMailjetMock).toHaveBeenCalledWith({
|
|
data: {
|
|
to: "ada@example.com",
|
|
subject: "Welcome",
|
|
body: "<p>Hello</p>",
|
|
alias: "registration-welcome",
|
|
data: { firstName: "Ada" },
|
|
},
|
|
});
|
|
});
|
|
});
|