fix: 强化工作空间字段运行时校验

This commit is contained in:
que01 committed 2026-09-20 10:19:44 +08:00
1 parent 1503f042e0
commit 1a4e806ca8
2 files changed
+33 -10

No files matched your search

+13 -1
View File
@@ -47,6 +47,9 @@ test("health and public content are available without authentication", async ()
});
test("admin can install a template and public workspace exposes enabled configuration", async () => {
await prisma.brandFieldDefinition.deleteMany({ where: { brandId } });
await prisma.brandModule.deleteMany({ where: { brandId } });
await prisma.brandTemplateInstallation.deleteMany({ where: { brandId } });
const login = await request("/admin/session/login", {
method: "POST",
payload: { username: "admin", password: process.env.SEED_ADMIN_PASSWORD },
@@ -85,6 +88,9 @@ test("admin can install a template and public workspace exposes enabled configur
});
test("admin can customize workspace modules and fields with brand isolation", async () => {
await prisma.brandFieldDefinition.deleteMany({ where: { brandId } });
await prisma.brandModule.deleteMany({ where: { brandId } });
await prisma.brandTemplateInstallation.deleteMany({ where: { brandId } });
const login = await request("/admin/session/login", {
method: "POST",
payload: { username: "admin", password: process.env.SEED_ADMIN_PASSWORD },
@@ -100,6 +106,12 @@ test("admin can customize workspace modules and fields with brand isolation", as
headers: { authorization: `Bearer ${token}` },
});
const moduleId = JSON.parse(workspace.body).modules[0].id;
const invalidField = await request("/admin/workspace/fields", {
method: "POST",
headers: { authorization: `Bearer ${token}` },
payload: { scope: "unknown", key: "Bad-Key", label: "非法字段", type: "text" },
});
assert.equal(invalidField.statusCode, 400);
const updatedModule = await request(`/admin/workspace/modules/${moduleId}`, {
method: "PATCH",
headers: { authorization: `Bearer ${token}` },
@@ -111,7 +123,7 @@ test("admin can customize workspace modules and fields with brand isolation", as
headers: { authorization: `Bearer ${token}` },
payload: {
scope: "profile",
key: `region-${Date.now()}`,
key: `region_${Date.now()}`,
label: "服务区域",
type: "text",
required: false,