feat(identity): confirm registration email atomically
This commit is contained in:
1 parent
8e7ce8d71c
commit
fade4e76e4
75 files changed
+4188
-403
No files matched your search
@@ -0,0 +1,49 @@
|
||||
import { describe, expect, expectTypeOf, it } from "vitest";
|
||||
import { confirmEmail, getConfirmEmailUrl } from "./endpoints/identity/identity";
|
||||
import { ConfirmEmailHeaders, EmailVerificationRequest, EmailVerificationResult } from "./schemas";
|
||||
|
||||
const token = "A".repeat(64);
|
||||
const request = { token, password: "password chosen during registration" };
|
||||
|
||||
describe("generated email confirmation request", () => {
|
||||
it("requires the token and the registration password", () => {
|
||||
expect(EmailVerificationRequest.parse(request)).toEqual(request);
|
||||
expect(EmailVerificationRequest.safeParse({ token }).success).toBe(false);
|
||||
expect(EmailVerificationRequest.safeParse({ ...request, token: "short" }).success).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("generated email confirmation response", () => {
|
||||
it("returns the saved onboarding destination without a session field", () => {
|
||||
const result = {
|
||||
email_verified: true,
|
||||
scenario: "candidate",
|
||||
onboarding_step: "candidate_profile",
|
||||
} as const;
|
||||
|
||||
const parsed = EmailVerificationResult.parse(result);
|
||||
|
||||
expect(parsed).toEqual(result);
|
||||
expect(EmailVerificationResult.parse({ ...result, session: "unexpected" })).not.toHaveProperty(
|
||||
"session",
|
||||
);
|
||||
expectTypeOf<keyof EmailVerificationResult>().toEqualTypeOf<
|
||||
"email_verified" | "scenario" | "onboarding_step"
|
||||
>();
|
||||
});
|
||||
});
|
||||
|
||||
describe("generated ConfirmEmail client", () => {
|
||||
it("uses the confirmation URL and exposes Origin separately from the request body", () => {
|
||||
expect(getConfirmEmailUrl()).toBe("/api/v1/identity/email-verifications");
|
||||
expect(ConfirmEmailHeaders.parse({ Origin: "https://app.example" })).toEqual({
|
||||
Origin: "https://app.example",
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps the request, optional origin header, and response types aligned", () => {
|
||||
expectTypeOf(confirmEmail).parameter(0).toEqualTypeOf<EmailVerificationRequest>();
|
||||
expectTypeOf(confirmEmail).parameter(1).toEqualTypeOf<ConfirmEmailHeaders | undefined>();
|
||||
expectTypeOf(confirmEmail).returns.resolves.toEqualTypeOf<EmailVerificationResult>();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user