feat: 完成模板示例内容导入闭环
This commit is contained in:
1 parent
d451c93398
commit
9b1c500c5f
3 files changed
+46
-1
No files matched your search
@@ -36,6 +36,11 @@ export function CapabilitiesPage() {
|
|||||||
},
|
},
|
||||||
onError: (error) => message.error(error instanceof Error ? error.message : "更新失败"),
|
onError: (error) => message.error(error instanceof Error ? error.message : "更新失败"),
|
||||||
});
|
});
|
||||||
|
const sampleMutation = useMutation({
|
||||||
|
mutationFn: () => createApiClient().importAdminSampleContent(),
|
||||||
|
onSuccess: (result) => message.success(`已导入 ${result.counts.offerings} 项示例业务`),
|
||||||
|
onError: (error) => message.error(error instanceof Error ? error.message : "导入失败"),
|
||||||
|
});
|
||||||
if (query.isLoading) return <QueryState loading />;
|
if (query.isLoading) return <QueryState loading />;
|
||||||
if (query.isError) return <QueryState error={query.error} />;
|
if (query.isError) return <QueryState error={query.error} />;
|
||||||
const items = query.data ?? [];
|
const items = query.data ?? [];
|
||||||
@@ -48,6 +53,13 @@ export function CapabilitiesPage() {
|
|||||||
message="能力状态会影响公开 Runtime Workspace;停用不会删除历史数据。"
|
message="能力状态会影响公开 Runtime Workspace;停用不会删除历史数据。"
|
||||||
style={{ marginBottom: 16 }}
|
style={{ marginBottom: 16 }}
|
||||||
/>
|
/>
|
||||||
|
<Button
|
||||||
|
onClick={() => sampleMutation.mutate()}
|
||||||
|
loading={sampleMutation.isPending}
|
||||||
|
style={{ marginBottom: 16 }}
|
||||||
|
>
|
||||||
|
导入门窗示例内容
|
||||||
|
</Button>
|
||||||
<Table
|
<Table
|
||||||
rowKey="capabilityKey"
|
rowKey="capabilityKey"
|
||||||
dataSource={items}
|
dataSource={items}
|
||||||
|
|||||||
@@ -237,7 +237,7 @@ class AdminWorkspaceController {
|
|||||||
kind: sortOrder === 3 ? "service" : "product",
|
kind: sortOrder === 3 ? "service" : "product",
|
||||||
name: item[0]!,
|
name: item[0]!,
|
||||||
summary: item[1]!,
|
summary: item[1]!,
|
||||||
categoryKey: item[2]!,
|
config: { categoryKey: item[2]! } as Prisma.InputJsonValue,
|
||||||
sortOrder,
|
sortOrder,
|
||||||
isEnabled: true,
|
isEnabled: true,
|
||||||
})),
|
})),
|
||||||
|
|||||||
@@ -187,6 +187,39 @@ test("admin can install doors industry template through the shared runtime contr
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("admin can preview and import sample content idempotently", async () => {
|
||||||
|
const login = await request("/admin/session/login", {
|
||||||
|
method: "POST",
|
||||||
|
payload: { username: "admin", password: process.env.SEED_ADMIN_PASSWORD },
|
||||||
|
});
|
||||||
|
const token = JSON.parse(login.body).token;
|
||||||
|
const preview = await request("/admin/workspace/sample-content/preview", {
|
||||||
|
headers: { authorization: `Bearer ${token}` },
|
||||||
|
});
|
||||||
|
assert.equal(preview.statusCode, 200);
|
||||||
|
const imported = await request("/admin/workspace/sample-content/import", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { authorization: `Bearer ${token}` },
|
||||||
|
});
|
||||||
|
assert.equal(imported.statusCode, 201);
|
||||||
|
const duplicate = await request("/admin/workspace/sample-content/import", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { authorization: `Bearer ${token}` },
|
||||||
|
});
|
||||||
|
assert.equal(duplicate.statusCode, 400);
|
||||||
|
await prisma.offering.deleteMany({
|
||||||
|
where: {
|
||||||
|
brandId,
|
||||||
|
categoryKey: { in: ["entrance-door", "garden-door", "interior-door", "custom"] },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
await prisma.trustContent.deleteMany({
|
||||||
|
where: { brandId, content: "示例内容,待品牌主理人完善。" },
|
||||||
|
});
|
||||||
|
await prisma.brandFieldDefinition.deleteMany({ where: { brandId, source: "sample" } });
|
||||||
|
await prisma.capabilityAuditLog.deleteMany({ where: { brandId, capabilityKey: "doors" } });
|
||||||
|
});
|
||||||
|
|
||||||
test("admin can install a template and public workspace exposes enabled configuration", async () => {
|
test("admin can install a template and public workspace exposes enabled configuration", async () => {
|
||||||
await prisma.inquirySubmission.deleteMany({ where: { brandId } });
|
await prisma.inquirySubmission.deleteMany({ where: { brandId } });
|
||||||
await prisma.inquiryForm.deleteMany({ where: { brandId } });
|
await prisma.inquiryForm.deleteMany({ where: { brandId } });
|
||||||
|
|||||||
Reference in new issue
Block a user