// packages/auth/src/events/user-signed-up.event.test.ts
import { describe, it, expect } from "vitest";
import { userSignedUpEventSchema, userSignedUpEvent } from "@/events/user-signed-up.event";

describe("userSignedUpEvent", () => {
  it("has the correct wire name", () => {
    expect(userSignedUpEvent.name).toBe("auth.user.signed-up");
  });

  it("accepts a valid payload", () => {
    const payload = {
      userId: "user_123",
      email: "alice@example.com",
      signedUpAt: "2026-05-08T12:00:00.000Z",
    };
    expect(() => userSignedUpEventSchema.parse(payload)).not.toThrow();
  });

  it("rejects invalid email", () => {
    expect(() =>
      userSignedUpEventSchema.parse({
        userId: "u1",
        email: "not-an-email",
        signedUpAt: "2026-05-08T12:00:00.000Z",
      }),
    ).toThrow();
  });

  it("rejects invalid datetime", () => {
    expect(() =>
      userSignedUpEventSchema.parse({
        userId: "u1",
        email: "alice@example.com",
        signedUpAt: "yesterday",
      }),
    ).toThrow();
  });

  it("rejects unknown fields (strict)", () => {
    expect(() =>
      userSignedUpEventSchema.parse({
        userId: "u1",
        email: "alice@example.com",
        signedUpAt: "2026-05-08T12:00:00.000Z",
        extraField: "no",
      }),
    ).toThrow();
  });
});
