feat(auth): userSignedUpEvent contract
This commit is contained in:
49
packages/auth/src/events/user-signed-up.event.test.ts
Normal file
49
packages/auth/src/events/user-signed-up.event.test.ts
Normal 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();
|
||||
});
|
||||
});
|
||||
18
packages/auth/src/events/user-signed-up.event.ts
Normal file
18
packages/auth/src/events/user-signed-up.event.ts
Normal 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,
|
||||
);
|
||||
Reference in New Issue
Block a user