fix: test

This commit is contained in:
Alex Yang
2025-12-15 20:44:32 +09:00
parent 93874e40a9
commit 4da13f98eb
2 changed files with 4789 additions and 7 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -23,6 +23,7 @@ describe("open-api", async (it) => {
it("should generate OpenAPI schema", async () => {
const schema = await auth.api.generateOpenAPISchema();
expect(schema).toBeDefined();
expect(schema).toMatchSnapshot("openAPISchema");
});
it("should have an id field in the User schema", async () => {
@@ -68,21 +69,117 @@ describe("open-api", async (it) => {
const schema_properties =
requestBody.content["application/json"].schema.properties;
expect(schema_properties.idToken).toBeDefined();
expect(schema_properties.idToken.type).toBe("object");
const idTokenType = schema_properties.idToken.type;
expect(idTokenType).toContain("object");
expect(idTokenType).toContain("null");
expect(schema_properties.idToken.properties).toBeDefined();
expect(schema_properties.idToken.properties.token).toBeDefined();
expect(schema_properties.idToken.properties.token.type).toBe("string");
expect(schema_properties.idToken.properties.accessToken).toBeDefined();
expect(schema_properties.idToken.properties.accessToken.type).toBe(
"string",
);
const accessTokenType =
schema_properties.idToken.properties.accessToken.type;
expect(accessTokenType).toContain("string");
expect(accessTokenType).toContain("null");
expect(schema_properties.idToken.properties.refreshToken).toBeDefined();
expect(schema_properties.idToken.properties.refreshToken.type).toBe(
"string",
);
const refreshTokenType =
schema_properties.idToken.properties.refreshToken.type;
expect(refreshTokenType).toContain("string");
expect(refreshTokenType).toContain("null");
expect(schema_properties.idToken.required).toContain("token");
expect(schema_properties.idToken.required).not.toContain("accessToken");
expect(schema_properties.idToken.required).not.toContain("refreshToken");
});
it("should use OpenAPI 3.1 nullable format for optional primitive types", async () => {
const schema = await auth.api.generateOpenAPISchema();
const paths = schema.paths as Record<string, any>;
const signInSocialPath = paths["/sign-in/social"];
const schema_properties =
signInSocialPath.post.requestBody.content["application/json"].schema
.properties;
const accessTokenType =
schema_properties.idToken.properties.accessToken.type;
const refreshTokenType =
schema_properties.idToken.properties.refreshToken.type;
expect(Array.isArray(accessTokenType)).toBe(true);
expect(accessTokenType).toContain("string");
expect(accessTokenType).toContain("null");
expect(Array.isArray(refreshTokenType)).toBe(true);
expect(refreshTokenType).toContain("string");
expect(refreshTokenType).toContain("null");
expect(schema_properties.idToken.properties.accessToken.nullable).toBe(
undefined,
);
expect(schema_properties.idToken.properties.refreshToken.nullable).toBe(
undefined,
);
});
it("should use anyOf format for optional object types in OpenAPI 3.1", async () => {
const schema = await auth.api.generateOpenAPISchema();
const paths = schema.paths as Record<string, any>;
const signInSocialPath = paths["/sign-in/social"];
const schema_properties =
signInSocialPath.post.requestBody.content["application/json"].schema
.properties;
const parentRequired =
signInSocialPath.post.requestBody.content["application/json"].schema
.required;
const isIdTokenOptional = !parentRequired?.includes("idToken");
expect(isIdTokenOptional).toBe(true);
const idTokenSchema = schema_properties.idToken;
const _hasAnyOf = idTokenSchema.anyOf !== undefined;
const hasTypeArrayWithNull =
Array.isArray(idTokenSchema.type) && idTokenSchema.type.includes("null");
expect(hasTypeArrayWithNull).toBe(true);
expect(idTokenSchema.nullable).toBe(undefined);
});
it("should generate OpenAPI 3.1 compliant schemas from Zod types", async () => {
const schema = await auth.api.generateOpenAPISchema();
expect(schema.openapi).toMatch(/^3\.1\./);
const paths = schema.paths as Record<string, any>;
const signInSocialPath = paths["/sign-in/social"];
const requestBodySchema =
signInSocialPath.post.requestBody.content["application/json"].schema;
const checkNoNullable = (obj: any, path = ""): void => {
if (obj === null || obj === undefined) return;
if (typeof obj === "object") {
for (const key in obj) {
if (key === "nullable") {
throw new Error(
`Found deprecated 'nullable' property at ${path}.${key}`,
);
}
if (typeof obj[key] === "object") {
checkNoNullable(obj[key], `${path}.${key}`);
}
}
}
};
expect(() =>
checkNoNullable(requestBodySchema, "signInSocialRequestBody"),
).not.toThrow();
});
});