refactor: 收敛公开工作区运行时契约
This commit is contained in:
1 parent
d5e63be074
commit
9b61047ec6
13 files changed
+93
-64
No files matched your search
@@ -46,12 +46,7 @@ export class PublicWorkspaceController {
|
||||
offerings: [],
|
||||
inquiryForms: [],
|
||||
capabilities: [],
|
||||
runtimeCapabilities: [],
|
||||
runtimeModules: [],
|
||||
fields: [],
|
||||
trustContent: [],
|
||||
trustPresentation: {},
|
||||
inquiryForm: null,
|
||||
navigation: { tabs: [] },
|
||||
plugins: [],
|
||||
theme: { colors: {} },
|
||||
@@ -61,9 +56,6 @@ export class PublicWorkspaceController {
|
||||
const modulesData = this.jsonArray(releaseSnapshot.modules).filter(
|
||||
(item) => this.jsonObject(item).isEnabled === true,
|
||||
) as Array<Record<string, unknown>>;
|
||||
const fieldsData = this.jsonArray(releaseSnapshot.fields).filter(
|
||||
(item) => this.jsonObject(item).isVisible === true,
|
||||
);
|
||||
const offeringsData = this.jsonArray(releaseSnapshot.offerings).filter(
|
||||
(item) => this.jsonObject(item).isEnabled === true,
|
||||
) as Array<Record<string, unknown>>;
|
||||
@@ -265,7 +257,6 @@ export class PublicWorkspaceController {
|
||||
},
|
||||
];
|
||||
});
|
||||
const inquiryForm = formsData[0] ?? null;
|
||||
const trustPresentation = trustData.reduce<Record<string, unknown>>((result, raw) => {
|
||||
const item = this.jsonObject(raw);
|
||||
const config = this.jsonObject(item.config);
|
||||
@@ -350,13 +341,6 @@ export class PublicWorkspaceController {
|
||||
}
|
||||
: null,
|
||||
visualTemplateManifest,
|
||||
capabilities: runtimeCapabilities,
|
||||
runtimeCapabilities,
|
||||
runtimeModules,
|
||||
fields: fieldsData,
|
||||
trustContent: trustData,
|
||||
trustPresentation,
|
||||
inquiryForm,
|
||||
};
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import { WechatAuthService } from "../dist/wechat-auth.js";
|
||||
let app;
|
||||
const prisma = new PrismaClient();
|
||||
const brandId = process.env.DEFAULT_BRAND_ID;
|
||||
|
||||
const openid = `integration-${Date.now()}`;
|
||||
let customerToken;
|
||||
const createdBookingIds = [];
|
||||
@@ -327,7 +328,7 @@ test("health and public content are available without authentication", async ()
|
||||
assert.ok(Array.isArray(runtime.plugins));
|
||||
assert.equal(runtime.brand.founder, "阿成");
|
||||
assert.ok(runtime.offerings.every((item) => item.coverUrl));
|
||||
assert.ok(runtime.trustContent.length > 0);
|
||||
assert.ok(runtime.trustPresentation);
|
||||
const bySlug = await request("/public/workspace?brandSlug=default-brand");
|
||||
assert.equal(bySlug.statusCode, 200);
|
||||
assert.equal(JSON.parse(bySlug.body).brand.id, brandId);
|
||||
@@ -403,10 +404,8 @@ test("seeded public workspaces keep personal, food, and doors brands isolated",
|
||||
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);
|
||||
assert.ok(workspace.inquiryForm);
|
||||
assert.equal(workspace.inquiryForm.isEnabled, true);
|
||||
assert.ok(workspace.inquiryForms.length > 0);
|
||||
assert.ok(workspace.offerings.length > 0);
|
||||
assert.ok(workspace.offerings.every((offering) => offering.brandId === undefined));
|
||||
assert.ok(
|
||||
@@ -443,7 +442,7 @@ test("public workspace uses brand-scoped capability installations and preserves
|
||||
const response = await request("/public/workspace");
|
||||
assert.equal(response.statusCode, 200);
|
||||
const body = JSON.parse(response.body);
|
||||
assert.deepEqual(body.runtimeCapabilities, [
|
||||
assert.deepEqual(body.capabilities, [
|
||||
{
|
||||
key: "inquiry",
|
||||
version: "1.0.0",
|
||||
@@ -451,7 +450,7 @@ test("public workspace uses brand-scoped capability installations and preserves
|
||||
config: { source: "integration-test" },
|
||||
},
|
||||
]);
|
||||
assert.notEqual(body.runtimeCapabilities[0].status, "enabled");
|
||||
assert.notEqual(body.capabilities[0].status, "enabled");
|
||||
} finally {
|
||||
await prisma.capabilityInstallation.delete({ where: { id: installation.id } });
|
||||
}
|
||||
@@ -831,10 +830,14 @@ test("admin can install a template and public workspace exposes enabled configur
|
||||
assert.equal(workspaceBody.contractVersion, "1.0");
|
||||
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);
|
||||
assert.equal("runtimeModules" in workspaceBody, false);
|
||||
assert.equal("runtimeCapabilities" in workspaceBody, false);
|
||||
assert.equal("fields" in workspaceBody, false);
|
||||
assert.equal("trustContent" in workspaceBody, false);
|
||||
assert.equal("inquiryForm" in workspaceBody, false);
|
||||
assert.equal(workspaceBody.modules[0].schemaVersion, "1.0");
|
||||
assert.ok(workspaceBody.inquiryForms.length > 0);
|
||||
const conflict = await request("/admin/workspace/install", {
|
||||
method: "POST",
|
||||
headers: { authorization: `Bearer ${token}` },
|
||||
@@ -1087,7 +1090,7 @@ test("admin can create and version an inquiry form", async () => {
|
||||
assert.equal(JSON.parse(publicOffering.body).inquiryForms[0].id, id);
|
||||
const publicWorkspace = await request("/public/workspace");
|
||||
assert.equal(publicWorkspace.statusCode, 200);
|
||||
assert.equal(JSON.parse(publicWorkspace.body).inquiryForm.id, id);
|
||||
assert.ok(JSON.parse(publicWorkspace.body).inquiryForms.some((form) => form.key === id));
|
||||
assert.ok(
|
||||
JSON.parse(publicWorkspace.body).inquiryForms.some(
|
||||
(form) => form.key === id && form.targetId === offering.id,
|
||||
|
||||
@@ -15,7 +15,7 @@ Page({
|
||||
.then((workspace) =>
|
||||
this.setData({
|
||||
brand: workspace.brand || {},
|
||||
trustContent: workspace.trustContent || [],
|
||||
trustContent: workspace.trustPresentation || {},
|
||||
pageRenderer: workspace.pageRenderers?.profile || "",
|
||||
records: [],
|
||||
templateKey: workspace.visualTemplate?.key || "",
|
||||
|
||||
@@ -44,7 +44,7 @@ Page({
|
||||
: {};
|
||||
this.setData({
|
||||
brand: activeBrand,
|
||||
trustContent: workspace.trustContent || [],
|
||||
trustContent: workspace.trustPresentation || {},
|
||||
offerings: activeOfferings,
|
||||
modules: workspace.modules || [],
|
||||
moduleVariants: workspace.moduleVariants || {},
|
||||
|
||||
@@ -32,7 +32,7 @@ Page({
|
||||
const presentation = workspace.brand?.visualPresentation?.inquiry || {};
|
||||
this.setData({
|
||||
offering,
|
||||
fields: form?.fields || workspace.fields || [],
|
||||
fields: form?.fields || [],
|
||||
formId: form?.key || form?.id || "",
|
||||
title: isQuote ? "获取报价方案" : presentation.title || "需求咨询",
|
||||
eyebrow: isQuote ? "QUOTE REQUEST" : presentation.eyebrow || "CONSULTATION",
|
||||
|
||||
@@ -44,6 +44,19 @@ test("已发布 workspace 正常返回", async () => {
|
||||
assert.equal(workspace.brand.name, "测试品牌");
|
||||
});
|
||||
|
||||
test("运行时只消费 canonical workspace 字段", async () => {
|
||||
const workspace = await loadWithResponse({
|
||||
publication: { status: "published" },
|
||||
brand: { name: "测试品牌" },
|
||||
offerings: [],
|
||||
trustPresentation: { bio: "品牌介绍" },
|
||||
inquiryForms: [],
|
||||
});
|
||||
assert.deepEqual(workspace.trustContent, { bio: "品牌介绍" });
|
||||
assert.equal(workspace.fields, undefined);
|
||||
assert.equal(workspace.inquiryForm, undefined);
|
||||
});
|
||||
|
||||
test("模板声明的业务提供项展示字段会保留在小程序 view model", async () => {
|
||||
const workspace = await loadWithResponse({
|
||||
publication: { status: "published" },
|
||||
|
||||
Reference in new issue
Block a user