feat(auth): userSignedUpEvent contract

This commit is contained in:
2026-05-08 16:24:12 +02:00
parent 1c13b757ed
commit 7f63adf740
3 changed files with 72 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
// 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();
});
});

View File

@@ -0,0 +1,18 @@
// packages/auth/src/events/user-signed-up.event.ts
import { z } from "zod";
import { defineEvent } from "@repo/core-events";
export const userSignedUpEventSchema = z
.object({
userId: z.string(),
email: z.string().email(),
signedUpAt: z.string().datetime(),
})
.strict();
export type UserSignedUpEvent = z.infer<typeof userSignedUpEventSchema>;
export const userSignedUpEvent = defineEvent(
"auth.user.signed-up",
userSignedUpEventSchema,
);