fix: 强化工作空间字段运行时校验
This commit is contained in:
1 parent
1503f042e0
commit
1a4e806ca8
2 files changed
+33
-10
No files matched your search
@@ -1,4 +1,15 @@
|
||||
import { IsArray, IsBoolean, IsIn, IsInt, IsOptional, IsString, Max, Min } from "class-validator";
|
||||
import {
|
||||
IsArray,
|
||||
IsBoolean,
|
||||
IsIn,
|
||||
IsInt,
|
||||
IsObject,
|
||||
IsOptional,
|
||||
IsString,
|
||||
Matches,
|
||||
Max,
|
||||
Min,
|
||||
} from "class-validator";
|
||||
|
||||
export class UpdateBrandDto {
|
||||
@IsOptional() @IsString() name?: string;
|
||||
@@ -137,21 +148,21 @@ export class UpdateModuleDto {
|
||||
}
|
||||
|
||||
export class CreateFieldDefinitionDto {
|
||||
@IsString() scope!: string;
|
||||
@IsString() key!: string;
|
||||
@IsIn(["profile", "service", "inquiry"]) scope!: string;
|
||||
@IsString() @Matches(/^[a-z][a-z0-9_]*$/) key!: string;
|
||||
@IsString() label!: string;
|
||||
@IsIn(["text", "textarea", "number", "date", "select", "multi-select", "image", "url", "phone"])
|
||||
type!: string;
|
||||
@IsOptional() @IsBoolean() required?: boolean;
|
||||
@IsOptional() @IsBoolean() isVisible?: boolean;
|
||||
@IsOptional() @IsInt() @Min(0) @Max(9999) sortOrder?: number;
|
||||
@IsOptional() options?: unknown;
|
||||
@IsOptional() visibleWhen?: unknown;
|
||||
@IsOptional() @IsArray() options?: unknown[];
|
||||
@IsOptional() @IsObject() visibleWhen?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export class UpdateFieldDefinitionDto {
|
||||
@IsOptional() @IsString() scope?: string;
|
||||
@IsOptional() @IsString() key?: string;
|
||||
@IsOptional() @IsIn(["profile", "service", "inquiry"]) scope?: string;
|
||||
@IsOptional() @IsString() @Matches(/^[a-z][a-z0-9_]*$/) key?: string;
|
||||
@IsOptional() @IsString() label?: string;
|
||||
@IsOptional()
|
||||
@IsIn(["text", "textarea", "number", "date", "select", "multi-select", "image", "url", "phone"])
|
||||
@@ -159,8 +170,8 @@ export class UpdateFieldDefinitionDto {
|
||||
@IsOptional() @IsBoolean() required?: boolean;
|
||||
@IsOptional() @IsBoolean() isVisible?: boolean;
|
||||
@IsOptional() @IsInt() @Min(0) @Max(9999) sortOrder?: number;
|
||||
@IsOptional() options?: unknown;
|
||||
@IsOptional() visibleWhen?: unknown;
|
||||
@IsOptional() @IsArray() options?: unknown[];
|
||||
@IsOptional() @IsObject() visibleWhen?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export class CreateInquiryFormDto {
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user