// Cross-feature event bus proof-of-life (DISABLED — @repo/core-events removed).
//
// @repo/core-events is now optional. When absent, ctx.bus is undefined, and
// bus?.subscribe(...) / bus?.publish(...) calls are no-ops. Cross-feature event
// fanout does not occur until core-events is scaffolded via:
//
//   pnpm turbo gen core-package events
//
// After scaffolding, restore this test and re-wire the bus in bind-production.ts
// (see the comment in bindAll()). Until then, signing up does NOT trigger a
// welcome email — the mailer queue stays empty.
//
// Replaced with a reduced test that asserts the no-bus behavior.

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 with no event bus (core-events not scaffolded)", () => {
  beforeEach(() => {
    __resetBindStateForTests();
  });

  it("sign-up succeeds and mailer stays empty (no cross-feature fanout without bus)", async () => {
    await bindAllDevSeed();

    const mailer = marketingPagesContainer.get<RecordingMailerService>(
      MARKETING_PAGES_SYMBOLS.IMailerService,
    );
    const signUp = authContainer.get<ISignUpController>(AUTH_SYMBOLS.ISignUpController);

    await signUp({
      username: "testuser",
      password: "secret_password",
      confirmPassword: "secret_password",
    });

    // Without a bus, bus?.subscribe() is a no-op so the event handler never
    // fires and the mailer receives nothing.
    await new Promise((r) => setImmediate(r));

    expect(mailer.sent).toEqual([]);
  });
});
