test(open-api): lock in requestBody for /phone-number/verify (#11208)

Co-authored-by: Taesu <bytaesu@gmail.com>
This commit is contained in:
Dev M
2026-09-09 08:14:11 +00:00
committed by GitHub
co-authored by Taesu
parent 163e9f9740
commit 874752f4fd
@@ -4,6 +4,7 @@ import * as z from "zod";
import { createAuthEndpoint } from "../../api";
import { getTestInstance } from "../../test-utils/test-instance";
import { emailOTP } from "../email-otp";
import { phoneNumber } from "../phone-number";
import { username } from "../username";
import { openAPI } from ".";
import type { OpenAPISchema, Path } from "./generator";
@@ -307,6 +308,17 @@ describe("open-api", async () => {
}),
],
});
const { auth: authWithPhoneNumber } = await getTestInstance({
plugins: [
phoneNumber({
sendOTP: async () => {},
signUpOnVerification: {
getTempEmail: (phone) => `${phone}@phone.example.com`,
},
}),
openAPI(),
],
});
const { auth: authWithNullableIntersection } = await getTestInstance({
plugins: [openAPI(), nullableIntersectionPlugin],
});
@@ -881,6 +893,47 @@ describe("open-api", async () => {
expect(signInEmailOTPSchema.additionalProperties).toEqual({});
});
it.for([
"/sign-in/phone-number",
"/phone-number/send-otp",
"/phone-number/request-password-reset",
"/phone-number/reset-password",
])("emits a request body for %s", async (path) => {
const schema = await authWithPhoneNumber.api.generateOpenAPISchema();
const paths = schema.paths as Record<string, Path>;
expect(paths[path]?.post?.requestBody).toBeDefined();
});
/**
* @see https://github.com/better-auth/better-auth/issues/8122
*/
it("emits the phone-number verification request body", async () => {
const schema = await authWithPhoneNumber.api.generateOpenAPISchema();
const paths = schema.paths as Record<string, Path>;
const requestBody = getPostRequestBody(paths, "/phone-number/verify");
const requestBodySchema = requestBody.content["application/json"].schema;
expect(requestBody).toMatchObject({
required: true,
content: {
"application/json": {
schema: {
type: "object",
properties: {
phoneNumber: { type: "string" },
code: { type: "string" },
disableSession: { type: "boolean" },
updatePhoneNumber: { type: "boolean" },
},
required: ["phoneNumber", "code"],
},
},
},
});
expect(requestBodySchema.additionalProperties).toEqual({});
});
it("should keep plain email OTP request bodies as object schemas", async () => {
const schema = await authWithEmailOTP.api.generateOpenAPISchema();
const paths = schema.paths as Record<string, any>;