fix: 保证品牌模板身份不被台账漂移

This commit is contained in:
que01 committed 2026-10-14 16:27:23 +08:00
1 parent 6073e72940
commit aaeec14733
6 files changed
+53 -13

No files matched your search

+48 -2
View File
@@ -1697,6 +1697,53 @@ test("installing another industry template is rejected without drifting brand id
}
});
test("cross template requests are rejected even when a drifted ledger already exists", async () => {
const originalBrand = await prisma.brandProfile.findUniqueOrThrow({ where: { id: brandId } });
await prisma.inquirySubmission.deleteMany({ where: { brandId } });
await prisma.inquiryForm.deleteMany({ where: { brandId } });
await prisma.brandFieldDefinition.deleteMany({ where: { brandId } });
await prisma.brandTemplateInstallation.deleteMany({ where: { brandId } });
await prisma.brandTemplateInstallation.create({
data: {
brandId,
templateKey: "doors",
templateVersion: "1.0.0",
configSnapshot: { schemaVersion: "1.0" },
},
});
const login = await request("/admin/session/login", {
method: "POST",
payload: { username: "admin", password: process.env.SEED_ADMIN_PASSWORD },
});
const headers = {
authorization: `Bearer ${JSON.parse(login.body).data?.token ?? JSON.parse(login.body).token}`,
};
try {
const rejected = await request("/admin/workspace/install", {
method: "POST",
headers,
payload: { templateKey: "doors" },
});
assert.equal(rejected.statusCode, 400, rejected.body);
assert.match(errorMessage(rejected.body), /更换行业模板不在本版本范围内/);
const brandAfter = await prisma.brandProfile.findUniqueOrThrow({ where: { id: brandId } });
assert.equal(brandAfter.templateKey, originalBrand.templateKey);
assert.equal(await prisma.brandTemplateInstallation.count({ where: { brandId } }), 1);
const workspace = await request("/public/workspace");
assert.equal(workspace.statusCode, 200);
assert.equal(JSON.parse(workspace.body).template.key, originalBrand.templateKey);
} finally {
await prisma.brandFieldDefinition.deleteMany({ where: { brandId } });
await prisma.brandTemplateInstallation.deleteMany({ where: { brandId } });
await prisma.brandProfile.update({
where: { id: brandId },
data: { templateKey: originalBrand.templateKey, config: originalBrand.config },
});
}
});
test("admin can preview and import sample content idempotently", async () => {
const originalBrand = await prisma.brandProfile.findUnique({ where: { id: brandId } });
const originalForms = await prisma.inquiryForm.findMany({ where: { brandId } });
@@ -2959,12 +3006,11 @@ test("admin can read and update brand and service configuration", async () => {
payload: {
description: "集成测试品牌简介",
contactPhone: "13800000000",
templateKey: "personal",
},
});
assert.equal(updatedBrand.statusCode, 200);
assert.equal(JSON.parse(updatedBrand.body).description, "集成测试品牌简介");
assert.equal(JSON.parse(updatedBrand.body).templateKey, "personal");
assert.equal(JSON.parse(updatedBrand.body).templateKey, brandBefore.templateKey);
const updatedConfig = JSON.parse(updatedBrand.body).config;
assert.equal(updatedConfig.slogan, "集成测试品牌简介");