feat: 完善模板驱动的品牌内容工作台
This commit is contained in:
1 parent
77224ea51f
commit
dd55af8d73
46 files changed
+2204
-295
No files matched your search
@@ -77,6 +77,70 @@ test("admin release lifecycle is authorized, brand-scoped, and versioned", async
|
||||
});
|
||||
}
|
||||
const originalBrand = await prisma.brandProfile.findUniqueOrThrow({ where: { id: brandId } });
|
||||
const originalConfig = originalBrand.config;
|
||||
const originalOffering = await prisma.offering.findFirstOrThrow({ where: { brandId } });
|
||||
await prisma.brandProfile.update({
|
||||
where: { id: brandId },
|
||||
data: {
|
||||
config: {
|
||||
...(originalConfig && typeof originalConfig === "object" ? originalConfig : {}),
|
||||
heroImage: "",
|
||||
founder: "",
|
||||
},
|
||||
},
|
||||
});
|
||||
const missingBrandContent = JSON.parse(
|
||||
(
|
||||
await request("/admin/releases/readiness", {
|
||||
headers: { authorization: `Bearer ${adminToken}` },
|
||||
})
|
||||
).body,
|
||||
);
|
||||
assert.equal(missingBrandContent.ready, false);
|
||||
assert.equal(
|
||||
missingBrandContent.checks.find((check) => check.key === "asset:brand.stallHero")?.passed,
|
||||
false,
|
||||
);
|
||||
assert.equal(
|
||||
missingBrandContent.checks.find((check) => check.key === "content:identity:founder")
|
||||
?.destination,
|
||||
"/admin/brand",
|
||||
);
|
||||
assert.match(
|
||||
missingBrandContent.checks.find((check) => check.key === "asset:brand.stallHero")?.help,
|
||||
/真实摊位/,
|
||||
);
|
||||
assert.equal(
|
||||
(
|
||||
await request("/admin/releases/publish", {
|
||||
method: "POST",
|
||||
headers: { authorization: `Bearer ${adminToken}` },
|
||||
payload: {},
|
||||
})
|
||||
).statusCode,
|
||||
400,
|
||||
);
|
||||
await prisma.brandProfile.update({
|
||||
where: { id: brandId },
|
||||
data: { config: originalConfig },
|
||||
});
|
||||
await prisma.offering.update({ where: { id: originalOffering.id }, data: { coverUrl: null } });
|
||||
const missingOfferingImage = JSON.parse(
|
||||
(
|
||||
await request("/admin/releases/readiness", {
|
||||
headers: { authorization: `Bearer ${adminToken}` },
|
||||
})
|
||||
).body,
|
||||
);
|
||||
assert.equal(missingOfferingImage.ready, false);
|
||||
assert.equal(
|
||||
missingOfferingImage.checks.find((check) => check.key === "asset:offering.cover")?.passed,
|
||||
false,
|
||||
);
|
||||
await prisma.offering.update({
|
||||
where: { id: originalOffering.id },
|
||||
data: { coverUrl: originalOffering.coverUrl },
|
||||
});
|
||||
await prisma.brandProfile.update({ where: { id: brandId }, data: { tagline: "" } });
|
||||
const incomplete = await request("/admin/releases/readiness", {
|
||||
headers: { authorization: `Bearer ${adminToken}` },
|
||||
@@ -319,6 +383,8 @@ test("seeded public workspaces keep personal, food, and doors brands isolated",
|
||||
assert.equal(workspace.template.key, item.templateKey);
|
||||
assert.ok(workspace.visualTemplate?.key);
|
||||
assert.ok(workspace.visualTemplateManifest?.pages?.length > 0);
|
||||
assert.equal(workspace.navigation.tabs.length, item.templateKey === "food" ? 5 : 3);
|
||||
assert.equal("templatePackageManifest" in workspace, false);
|
||||
assert.equal(workspace.brand.founder, item.founder);
|
||||
assert.ok(workspace.trustContent.length > 0);
|
||||
assert.ok(workspace.trustPresentation);
|
||||
@@ -333,6 +399,10 @@ test("seeded public workspaces keep personal, food, and doors brands isolated",
|
||||
offering.presentation?.categoryLabel === item.categoryLabel,
|
||||
),
|
||||
);
|
||||
if (item.templateKey === "doors") {
|
||||
assert.ok(workspace.offerings.some((offering) => offering.presentation.series));
|
||||
assert.ok(workspace.offerings.some((offering) => offering.presentation.hardware));
|
||||
}
|
||||
return workspace;
|
||||
}),
|
||||
);
|
||||
@@ -683,6 +753,10 @@ test("admin can install a template and public workspace exposes enabled configur
|
||||
const token = JSON.parse(login.body).token;
|
||||
const before = await request("/admin/workspace");
|
||||
assert.equal(before.statusCode, 401);
|
||||
const customerAccess = await request("/admin/workspace", {
|
||||
headers: { authorization: `Bearer ${customerToken}` },
|
||||
});
|
||||
assert.equal(customerAccess.statusCode, 403);
|
||||
const installed = await request("/admin/workspace/install", {
|
||||
method: "POST",
|
||||
headers: { authorization: `Bearer ${token}` },
|
||||
@@ -726,6 +800,14 @@ test("admin can install a template and public workspace exposes enabled configur
|
||||
assert.equal(workspace.statusCode, 200);
|
||||
assert.equal(JSON.parse(workspace.body).installations.length, 1);
|
||||
assert.equal(JSON.parse(workspace.body).fields.length, 5);
|
||||
const templateContent = JSON.parse(workspace.body).templateContent;
|
||||
assert.equal(templateContent.displayName, "阿成校园餐");
|
||||
assert.ok(templateContent.admin.sections.some((section) => section.title === "首页出摊信息"));
|
||||
assert.ok(
|
||||
templateContent.admin.sections
|
||||
.flatMap((section) => section.fields)
|
||||
.some((field) => field.binding === "brand.config.heroImage"),
|
||||
);
|
||||
const publicWorkspace = await request("/public/workspace");
|
||||
assert.equal(publicWorkspace.statusCode, 200);
|
||||
const workspaceBody = JSON.parse(publicWorkspace.body);
|
||||
@@ -733,6 +815,7 @@ test("admin can install a template and public workspace exposes enabled configur
|
||||
assert.equal(workspaceBody.template.key, "food");
|
||||
assert.ok(workspaceBody.modules.length > 0);
|
||||
assert.equal(workspaceBody.modules.length, workspaceBody.runtimeModules.length);
|
||||
assert.equal("templateContent" in workspaceBody, false);
|
||||
assert.equal(workspaceBody.runtimeModules[0].schemaVersion, "1.0");
|
||||
assert.ok(workspaceBody.inquiryForm);
|
||||
const conflict = await request("/admin/workspace/install", {
|
||||
@@ -1276,22 +1359,35 @@ test("brand switching isolates admin configuration, offerings, and public worksp
|
||||
assert.equal(switched.statusCode, 201);
|
||||
const doorsToken = JSON.parse(switched.body).token;
|
||||
|
||||
const [defaultConfig, doorsConfig, defaultOfferings, doorsOfferings, doorsWorkspace] =
|
||||
await Promise.all([
|
||||
request("/admin/config/brand", {
|
||||
headers: { authorization: `Bearer ${defaultToken}` },
|
||||
}),
|
||||
request("/admin/config/brand", {
|
||||
headers: { authorization: `Bearer ${doorsToken}` },
|
||||
}),
|
||||
request("/admin/workspace/offerings", {
|
||||
headers: { authorization: `Bearer ${defaultToken}` },
|
||||
}),
|
||||
request("/admin/workspace/offerings", {
|
||||
headers: { authorization: `Bearer ${doorsToken}` },
|
||||
}),
|
||||
request("/public/workspace?brandSlug=linjing-doors"),
|
||||
]);
|
||||
const [
|
||||
defaultConfig,
|
||||
doorsConfig,
|
||||
defaultOfferings,
|
||||
doorsOfferings,
|
||||
defaultAdminWorkspace,
|
||||
doorsAdminWorkspace,
|
||||
doorsWorkspace,
|
||||
] = await Promise.all([
|
||||
request("/admin/config/brand", {
|
||||
headers: { authorization: `Bearer ${defaultToken}` },
|
||||
}),
|
||||
request("/admin/config/brand", {
|
||||
headers: { authorization: `Bearer ${doorsToken}` },
|
||||
}),
|
||||
request("/admin/workspace/offerings", {
|
||||
headers: { authorization: `Bearer ${defaultToken}` },
|
||||
}),
|
||||
request("/admin/workspace/offerings", {
|
||||
headers: { authorization: `Bearer ${doorsToken}` },
|
||||
}),
|
||||
request("/admin/workspace", {
|
||||
headers: { authorization: `Bearer ${defaultToken}` },
|
||||
}),
|
||||
request("/admin/workspace", {
|
||||
headers: { authorization: `Bearer ${doorsToken}` },
|
||||
}),
|
||||
request("/public/workspace?brandSlug=linjing-doors"),
|
||||
]);
|
||||
assert.equal(defaultConfig.statusCode, 200);
|
||||
assert.equal(doorsConfig.statusCode, 200);
|
||||
assert.equal(JSON.parse(defaultConfig.body).id, brandId);
|
||||
@@ -1305,6 +1401,10 @@ test("brand switching isolates admin configuration, offerings, and public worksp
|
||||
assert.equal(doorsWorkspace.statusCode, 200);
|
||||
assert.equal(JSON.parse(doorsWorkspace.body).brand.id, doorsBrand.id);
|
||||
assert.equal(JSON.parse(doorsWorkspace.body).template.key, "doors");
|
||||
assert.equal(defaultAdminWorkspace.statusCode, 200);
|
||||
assert.equal(doorsAdminWorkspace.statusCode, 200);
|
||||
assert.equal(JSON.parse(defaultAdminWorkspace.body).templateContent.displayName, "阿成校园餐");
|
||||
assert.equal(JSON.parse(doorsAdminWorkspace.body).templateContent.displayName, "林境建筑画册");
|
||||
});
|
||||
|
||||
test("disabled brand membership blocks existing admin token", async () => {
|
||||
|
||||
Reference in new issue
Block a user