From 04899de98c56747c83ddc9eaccfcfc441ff2ceb7 Mon Sep 17 00:00:00 2001 From: Danijel Martinek Date: Fri, 8 May 2026 16:37:37 +0200 Subject: [PATCH] =?UTF-8?q?test(web-next):=20e2e=20cross-feature=20sign-up?= =?UTF-8?q?=E2=86=92welcome-email=20flow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit End-to-end proof-of-life. bindAllDevSeed wires InMemoryEventBus + InMemoryJobQueue across all features. signUpController publishes auth.user.signed-up; marketing-pages' handler enqueues marketing-pages.send-welcome-email; the in-memory queue dispatches the wrapped job which records on RecordingMailerService. Adds ./di/container, ./di/symbols, ./services/mailer, and ./services/recording-mailer to auth + marketing-pages exports so the e2e test can resolve from the per-feature containers without deep-importing. --- .../__tests__/sign-up-welcome-email.test.ts | 44 +++++++++++++++++++ packages/auth/package.json | 4 +- packages/marketing-pages/package.json | 6 ++- 3 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 apps/web-next/src/__tests__/sign-up-welcome-email.test.ts diff --git a/apps/web-next/src/__tests__/sign-up-welcome-email.test.ts b/apps/web-next/src/__tests__/sign-up-welcome-email.test.ts new file mode 100644 index 0000000..530d51d --- /dev/null +++ b/apps/web-next/src/__tests__/sign-up-welcome-email.test.ts @@ -0,0 +1,44 @@ +// Cross-feature proof-of-life: signing up in @repo/auth publishes +// userSignedUpEvent on the shared bus, marketing-pages' subscriber enqueues +// a send-welcome-email job on the shared queue, and dev-seed's +// InMemoryJobQueue.register() dispatches it to the wrapped job — which +// records the call on the bound RecordingMailerService. + +import "reflect-metadata"; +import { describe, it, expect, beforeEach } from "vitest"; +import { bindAllDevSeed, __resetBindStateForTests } from "@/server/bind-production"; +import { authContainer } from "@repo/auth/di/container"; +import { AUTH_SYMBOLS } from "@repo/auth/di/symbols"; +import type { ISignUpController } from "@repo/auth"; +import { marketingPagesContainer } from "@repo/marketing-pages/di/container"; +import { MARKETING_PAGES_SYMBOLS } from "@repo/marketing-pages/di/symbols"; +import { RecordingMailerService } from "@repo/marketing-pages/services/recording-mailer"; + +describe("e2e: sign-up triggers welcome email via cross-feature event", () => { + beforeEach(() => { + __resetBindStateForTests(); + }); + + it("delivers a welcome email after a successful sign-up", async () => { + await bindAllDevSeed(); + + const mailer = marketingPagesContainer.get( + MARKETING_PAGES_SYMBOLS.IMailerService, + ); + const signUp = authContainer.get(AUTH_SYMBOLS.ISignUpController); + + await signUp({ + username: "testuser", + password: "secret_password", + confirmPassword: "secret_password", + }); + + // The InMemoryJobQueue dispatches the registered handler on setImmediate; + // wait for microtasks + one setImmediate tick to settle. + await new Promise((r) => setImmediate(r)); + + expect(mailer.sent).toEqual([ + { userId: expect.any(String), email: "testuser@example.local" }, + ]); + }); +}); diff --git a/packages/auth/package.json b/packages/auth/package.json index e29e395..668dd65 100644 --- a/packages/auth/package.json +++ b/packages/auth/package.json @@ -9,7 +9,9 @@ "./cms": "./src/integrations/cms/index.ts", "./api": "./src/integrations/api/router.ts", "./di/bind-production": "./src/di/bind-production.ts", - "./di/bind-dev-seed": "./src/di/bind-dev-seed.ts" + "./di/bind-dev-seed": "./src/di/bind-dev-seed.ts", + "./di/container": "./src/di/container.ts", + "./di/symbols": "./src/di/symbols.ts" }, "scripts": { "build": "tsc --noEmit", diff --git a/packages/marketing-pages/package.json b/packages/marketing-pages/package.json index ce7c7da..5afb693 100644 --- a/packages/marketing-pages/package.json +++ b/packages/marketing-pages/package.json @@ -9,7 +9,11 @@ "./cms": "./src/integrations/cms/index.ts", "./api": "./src/integrations/api/router.ts", "./di/bind-production": "./src/di/bind-production.ts", - "./di/bind-dev-seed": "./src/di/bind-dev-seed.ts" + "./di/bind-dev-seed": "./src/di/bind-dev-seed.ts", + "./di/container": "./src/di/container.ts", + "./di/symbols": "./src/di/symbols.ts", + "./services/mailer": "./src/application/services/mailer.service.interface.ts", + "./services/recording-mailer": "./src/infrastructure/services/recording-mailer.service.ts" }, "scripts": { "build": "tsc --noEmit",