sendWelcomeEmailJob takes IMailerService, validates the typed input (userId + email), and delegates to mailer.sendWelcome. The onAuthUserSignedUpHandler now takes IJobQueue and enqueues "marketing-pages.send-welcome-email" with the event payload. Both binders bind a RecordingMailerService at the IMailerService symbol (production placeholder until a real adapter ships) and pass mailer / queue into the wrapped factories. Dev-seed additionally queue.register()s the slug so the in-memory queue dispatches via the wrapped job; production relies on the generated Payload event-task to resolve the wrapped handler from the container.
26 lines
923 B
TypeScript
26 lines
923 B
TypeScript
// packages/marketing-pages/src/events/handlers/on-auth-user-signed-up.handler.test.ts
|
|
import { describe, it, expect } from "vitest";
|
|
import { RecordingJobQueue } from "@repo/core-testing/instrumentation";
|
|
import { onAuthUserSignedUpHandler } from "@/events/handlers/on-auth-user-signed-up.handler";
|
|
|
|
describe("onAuthUserSignedUpHandler", () => {
|
|
it("enqueues marketing-pages.send-welcome-email with userId + email", async () => {
|
|
const queue = new RecordingJobQueue();
|
|
const handler = onAuthUserSignedUpHandler(queue);
|
|
|
|
await handler({
|
|
userId: "u-42",
|
|
email: "alice@example.com",
|
|
signedUpAt: "2026-05-08T12:00:00.000Z",
|
|
});
|
|
|
|
expect(queue.enqueued).toHaveLength(1);
|
|
expect(queue.enqueued[0]).toEqual(
|
|
expect.objectContaining({
|
|
taskSlug: "marketing-pages.send-welcome-email",
|
|
input: { userId: "u-42", email: "alice@example.com" },
|
|
}),
|
|
);
|
|
});
|
|
});
|