50 lines
2.0 KiB
TypeScript
50 lines
2.0 KiB
TypeScript
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>();
|
|
});
|
|
});
|