Files
auto-virtual-tryon-frontend/tests/app/api/libraries.route.test.ts

51 lines
1.6 KiB
TypeScript

import { expect, test } from "vitest";
import { GET } from "../../../app/api/libraries/[libraryType]/route";
test("returns honest placeholder library data for unsupported backend modules", async () => {
const response = await GET(new Request("http://localhost/api/libraries/models"), {
params: Promise.resolve({ libraryType: "models" }),
});
const payload = await response.json();
expect(response.status).toBe(200);
expect(payload).toMatchObject({
mode: "placeholder",
data: {
items: expect.arrayContaining([
expect.objectContaining({
libraryType: "models",
isMock: true,
}),
]),
},
message: "资源库当前使用占位数据,真实后端接口尚未提供。",
});
});
test("rejects unsupported placeholder library types with a normalized error", async () => {
const response = await GET(new Request("http://localhost/api/libraries/unknown"), {
params: Promise.resolve({ libraryType: "unknown" }),
});
const payload = await response.json();
expect(response.status).toBe(404);
expect(payload).toEqual({
error: "NOT_FOUND",
message: "不支持的资源库类型。",
});
});
test("rejects inherited object keys instead of treating them as valid library types", async () => {
const response = await GET(new Request("http://localhost/api/libraries/toString"), {
params: Promise.resolve({ libraryType: "toString" }),
});
const payload = await response.json();
expect(response.status).toBe(404);
expect(payload).toEqual({
error: "NOT_FOUND",
message: "不支持的资源库类型。",
});
});