feat: 完成模板管理阶段4闭环
This commit is contained in:
1 parent
b1e8012ded
commit
d1958a7d7f
26 files changed
+1179
-310
No files matched your search
@@ -2283,6 +2283,7 @@ test("admin can preview and import sample content idempotently", async () => {
|
||||
where: { brandId, content: "示例内容,待品牌主理人完善。" },
|
||||
});
|
||||
await prisma.brandProfile.update({ where: { id: brandId }, data: { templateKey: "doors" } });
|
||||
await prisma.brandTemplateInstallation.deleteMany({ where: { brandId } });
|
||||
await prisma.offering.deleteMany({
|
||||
where: {
|
||||
brandId,
|
||||
@@ -2307,44 +2308,77 @@ test("admin can preview and import sample content idempotently", async () => {
|
||||
payload: { username: "admin", password: process.env.SEED_ADMIN_PASSWORD },
|
||||
});
|
||||
const token = JSON.parse(login.body).data?.token ?? JSON.parse(login.body).token;
|
||||
const headers = { authorization: `Bearer ${token}` };
|
||||
const archive = createTemplateArchive("acheng-campus-food");
|
||||
const uploaded = multipartArchive(archive);
|
||||
const importedPackage = await request("/admin/templates/import", {
|
||||
method: "POST",
|
||||
headers: { ...headers, ...uploaded.headers },
|
||||
rawPayload: uploaded.payload,
|
||||
});
|
||||
assert.equal(importedPackage.statusCode, 201, importedPackage.body);
|
||||
const packageVersionId = JSON.parse(importedPackage.body).version.id;
|
||||
const publishedPackage = await request(`/admin/templates/${packageVersionId}/publish`, {
|
||||
method: "POST",
|
||||
headers,
|
||||
});
|
||||
assert.equal(publishedPackage.statusCode, 201, publishedPackage.body);
|
||||
await prisma.brandProfile.update({
|
||||
where: { id: brandId },
|
||||
data: { templateKey: "food", config: { visualTemplateKey: "acheng-campus-food" } },
|
||||
});
|
||||
await prisma.brandTemplateInstallation.create({
|
||||
data: {
|
||||
brandId,
|
||||
templateKey: "food",
|
||||
visualTemplateKey: "acheng-campus-food",
|
||||
templatePackageVersionId: packageVersionId,
|
||||
contentChecksum: JSON.parse(importedPackage.body).version.contentChecksum,
|
||||
templateVersion: JSON.parse(importedPackage.body).version.version,
|
||||
configSnapshot: { schemaVersion: "1.0" },
|
||||
},
|
||||
});
|
||||
const preview = await request("/admin/workspace/sample-content/preview", {
|
||||
headers: { authorization: `Bearer ${token}` },
|
||||
headers,
|
||||
});
|
||||
assert.equal(preview.statusCode, 200);
|
||||
assert.equal(JSON.parse(preview.body).source.templatePackageVersionId, packageVersionId);
|
||||
assert.equal(JSON.parse(preview.body).source.kind, "package_version");
|
||||
assert.equal(JSON.parse(preview.body).willCreateInquiryForm, false);
|
||||
assert.equal(await prisma.templateBootstrapImport.count({ where: { brandId } }), 0);
|
||||
const missingConfirmation = await request("/admin/workspace/sample-content/import", {
|
||||
method: "POST",
|
||||
headers,
|
||||
payload: { strategy: "missing_only", confirm: false },
|
||||
});
|
||||
assert.equal(missingConfirmation.statusCode, 400);
|
||||
const imported = await request("/admin/workspace/sample-content/import", {
|
||||
method: "POST",
|
||||
headers: { authorization: `Bearer ${token}` },
|
||||
headers,
|
||||
payload: {
|
||||
templatePackageVersionId: packageVersionId,
|
||||
strategy: "missing_only",
|
||||
confirm: true,
|
||||
},
|
||||
});
|
||||
assert.equal(imported.statusCode, 201);
|
||||
assert.equal(JSON.parse(imported.body).counts.inquiryForms, 0);
|
||||
assert.ok(await prisma.inquiryForm.findFirst({ where: { brandId, name: "现有客户表单" } }));
|
||||
await prisma.offering.deleteMany({
|
||||
where: {
|
||||
brandId,
|
||||
name: { in: ["序章·入户门", "庭院·边界门", "室内·静谧门", "一对一门系统设计咨询"] },
|
||||
},
|
||||
});
|
||||
await prisma.trustContent.deleteMany({
|
||||
where: { brandId, content: "示例内容,待品牌主理人完善。" },
|
||||
});
|
||||
await prisma.brandFieldDefinition.deleteMany({ where: { brandId, source: "sample" } });
|
||||
await prisma.inquiryForm.deleteMany({ where: { brandId } });
|
||||
const importedWithoutForm = await request("/admin/workspace/sample-content/import", {
|
||||
method: "POST",
|
||||
headers: { authorization: `Bearer ${token}` },
|
||||
});
|
||||
assert.equal(importedWithoutForm.statusCode, 201);
|
||||
assert.equal(JSON.parse(importedWithoutForm.body).counts.inquiryForms, 1);
|
||||
const importedForm = await prisma.inquiryForm.findFirstOrThrow({
|
||||
where: { brandId, name: "门系统咨询表单" },
|
||||
});
|
||||
assert.ok(Array.isArray(importedForm.fieldsSnapshot) && importedForm.fieldsSnapshot.length > 0);
|
||||
assert.equal(
|
||||
await prisma.templateBootstrapImport.count({ where: { brandId, status: "imported" } }),
|
||||
1,
|
||||
);
|
||||
const duplicate = await request("/admin/workspace/sample-content/import", {
|
||||
method: "POST",
|
||||
headers: { authorization: `Bearer ${token}` },
|
||||
headers,
|
||||
payload: {
|
||||
templatePackageVersionId: packageVersionId,
|
||||
strategy: "missing_only",
|
||||
confirm: true,
|
||||
},
|
||||
});
|
||||
assert.equal(duplicate.statusCode, 400);
|
||||
assert.equal(duplicate.statusCode, 201);
|
||||
assert.equal(JSON.parse(duplicate.body).alreadyImported, true);
|
||||
await prisma.offering.deleteMany({
|
||||
where: {
|
||||
brandId,
|
||||
@@ -2371,9 +2405,16 @@ test("admin can preview and import sample content idempotently", async () => {
|
||||
});
|
||||
}
|
||||
await prisma.capabilityAuditLog.deleteMany({ where: { brandId, capabilityKey: "doors" } });
|
||||
await prisma.templateBootstrapImport.deleteMany({ where: { brandId } });
|
||||
await prisma.brandTemplateInstallation.deleteMany({ where: { brandId } });
|
||||
await prisma.templatePackageAuditLog.deleteMany({
|
||||
where: { templatePackageVersionId: packageVersionId },
|
||||
});
|
||||
await prisma.templatePackageVersion.delete({ where: { id: packageVersionId } });
|
||||
await prisma.templatePackage.deleteMany({ where: { packageKey: "acheng-campus-food" } });
|
||||
await prisma.brandProfile.update({
|
||||
where: { id: brandId },
|
||||
data: { templateKey: originalBrand?.templateKey ?? "food" },
|
||||
data: { templateKey: originalBrand?.templateKey ?? "food", config: originalBrand?.config },
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4006,16 +4047,37 @@ test("atelier template imports selected package and preserves draft publication
|
||||
headers,
|
||||
payload: { config: { visualTemplateKey: "atelier-solopreneur" } },
|
||||
});
|
||||
const packageArchive = multipartArchive(createTemplateArchive("atelier-solopreneur"));
|
||||
const importedPackage = await request("/admin/templates/import", {
|
||||
method: "POST",
|
||||
headers: { ...headers, ...packageArchive.headers },
|
||||
rawPayload: packageArchive.payload,
|
||||
});
|
||||
assert.equal(importedPackage.statusCode, 201, importedPackage.body);
|
||||
const selectedPackage = JSON.parse(importedPackage.body).version;
|
||||
const publishedPackage = await request(`/admin/templates/${selectedPackage.id}/publish`, {
|
||||
method: "POST",
|
||||
headers,
|
||||
});
|
||||
assert.equal(publishedPackage.statusCode, 201, publishedPackage.body);
|
||||
const installation = await json("/admin/workspace/install", {
|
||||
method: "POST",
|
||||
headers,
|
||||
payload: { templateKey: "personal" },
|
||||
payload: { templateKey: "personal", templatePackageVersionId: selectedPackage.id },
|
||||
});
|
||||
assert.equal(installation.visualTemplate.key, "atelier-solopreneur");
|
||||
assert.equal(installation.visualTemplate.tokens.colors.accent, "#1f3a5f");
|
||||
const preview = await json("/admin/workspace/sample-content/preview", { headers });
|
||||
assert.equal(preview.counts.fields, 5);
|
||||
await json("/admin/workspace/sample-content/import", { method: "POST", headers });
|
||||
await json("/admin/workspace/sample-content/import", {
|
||||
method: "POST",
|
||||
headers,
|
||||
payload: {
|
||||
templatePackageVersionId: selectedPackage.id,
|
||||
strategy: "missing_only",
|
||||
confirm: true,
|
||||
},
|
||||
});
|
||||
const imported = await json("/admin/config/brand", { headers });
|
||||
assert.equal(imported.config.visualPresentation.home.subtitle, "保留已有品牌说明");
|
||||
assert.equal(imported.config.atelier.deliverables.length, 7);
|
||||
@@ -4025,11 +4087,17 @@ test("atelier template imports selected package and preserves draft publication
|
||||
form.fieldsSnapshot.map((field) => field.key),
|
||||
["name", "industry", "needs", "timeline", "contact"],
|
||||
);
|
||||
assert.equal(
|
||||
(await request("/admin/workspace/sample-content/import", { method: "POST", headers }))
|
||||
.statusCode,
|
||||
400,
|
||||
);
|
||||
const duplicateImport = await request("/admin/workspace/sample-content/import", {
|
||||
method: "POST",
|
||||
headers,
|
||||
payload: {
|
||||
templatePackageVersionId: selectedPackage.id,
|
||||
strategy: "missing_only",
|
||||
confirm: true,
|
||||
},
|
||||
});
|
||||
assert.equal(duplicateImport.statusCode, 201);
|
||||
assert.equal(JSON.parse(duplicateImport.body).alreadyImported, true);
|
||||
const manifest = (await json("/admin/workspace", { headers })).templateContent;
|
||||
const exampleOffering = await prisma.offering.findFirstOrThrow({
|
||||
where: { brandId: brand.id },
|
||||
@@ -4171,11 +4239,22 @@ test("atelier template imports selected package and preserves draft publication
|
||||
where: { brandId: brand.id },
|
||||
data: { isPublished: true },
|
||||
});
|
||||
const readiness = await json("/admin/releases/readiness", { headers });
|
||||
assert.equal(
|
||||
readiness.checks.find((check) => check.key === "template-package-version")?.passed,
|
||||
true,
|
||||
);
|
||||
await json("/admin/releases/publish", {
|
||||
method: "POST",
|
||||
headers,
|
||||
payload: { note: "宣传模板独立品牌验收" },
|
||||
});
|
||||
const release = await prisma.brandRelease.findFirstOrThrow({
|
||||
where: { brandId: brand.id, status: "published" },
|
||||
orderBy: { version: "desc" },
|
||||
});
|
||||
assert.equal(release.snapshot.installation.templatePackageVersionId, selectedPackage.id);
|
||||
assert.equal(release.snapshot.templatePackageManifest.packageKey, selectedPackage.packageKey);
|
||||
const published = await json("/public/workspace?brandSlug=" + slug);
|
||||
assert.equal(published.brand.visualPresentation.home.subtitle, "保留已有品牌说明");
|
||||
const next = structuredClone(defaults);
|
||||
|
||||
Reference in new issue
Block a user