mirror of
https://github.com/better-auth/better-auth.git
synced 2026-10-20 20:26:55 -05:00
test(open-api): lock in requestBody for /phone-number/verify (#11208)
Co-authored-by: Taesu <bytaesu@gmail.com>
This commit is contained in:
@@ -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>;
|
||||
|
||||
Reference in New Issue
Block a user