fix: 完善工坊模板安装预览与详情样例
This commit is contained in:
1 parent
5313fd9d32
commit
50753db79d
16 files changed
+496
-26
No files matched your search
@@ -0,0 +1,63 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { PrismaService } from "../dist/prisma.service.js";
|
||||
import { TemplateWorkspaceService } from "../dist/template-workspace.service.js";
|
||||
|
||||
// 显式创建独立品牌;不注册模板样例,不导入内容,也不发布。
|
||||
const username = process.argv[2];
|
||||
if (!username)
|
||||
throw new Error("Usage: node --env-file=.env scripts/create-atelier-brand.mjs <admin-username>");
|
||||
const prisma = new PrismaService();
|
||||
try {
|
||||
const admin = await prisma.adminUser.findUniqueOrThrow({ where: { username } });
|
||||
assert.ok(admin.isEnabled && admin.role === "admin", "An enabled administrator is required");
|
||||
const slug = "atelier-studio";
|
||||
const existingBrands = await prisma.brandProfile.findMany({
|
||||
where: { slug: { not: slug } },
|
||||
orderBy: { id: "asc" },
|
||||
});
|
||||
const brand = await prisma.$transaction(async (tx) => {
|
||||
let current = await tx.brandProfile.findUnique({ where: { slug } });
|
||||
if (current) {
|
||||
assert.equal(current.templateKey, "personal", "Existing brand has a different industry");
|
||||
assert.equal(
|
||||
current.config?.visualTemplateKey,
|
||||
"atelier-solopreneur",
|
||||
"Existing brand has a different visual template",
|
||||
);
|
||||
} else {
|
||||
current = await tx.brandProfile.create({
|
||||
data: {
|
||||
slug,
|
||||
name: "独立工坊 · 品牌小程序",
|
||||
templateKey: "personal",
|
||||
config: { visualTemplateKey: "atelier-solopreneur" },
|
||||
},
|
||||
});
|
||||
}
|
||||
await tx.brandMembership.upsert({
|
||||
where: { adminUserId_brandId: { adminUserId: admin.id, brandId: current.id } },
|
||||
create: { adminUserId: admin.id, brandId: current.id, role: "owner" },
|
||||
update: {},
|
||||
});
|
||||
return current;
|
||||
});
|
||||
if (!(await prisma.brandTemplateInstallation.findFirst({ where: { brandId: brand.id } }))) {
|
||||
await new TemplateWorkspaceService(prisma).install(brand.id, "personal");
|
||||
}
|
||||
assert.deepEqual(
|
||||
await prisma.brandProfile.findMany({ where: { slug: { not: slug } }, orderBy: { id: "asc" } }),
|
||||
existingBrands,
|
||||
);
|
||||
console.log(
|
||||
JSON.stringify({
|
||||
slug,
|
||||
name: brand.name,
|
||||
template: "atelier-solopreneur",
|
||||
administrator: username,
|
||||
sampleImported: false,
|
||||
publishedByScript: false,
|
||||
}),
|
||||
);
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
@@ -111,7 +111,8 @@ export class AdminSampleContentService {
|
||||
name: item.name,
|
||||
summary: item.summary,
|
||||
...(item.coverUrl ? { coverUrl: item.coverUrl } : {}),
|
||||
config: { categoryKey: item.categoryKey },
|
||||
...(item.priceText ? { priceText: item.priceText } : {}),
|
||||
config: { ...item.config, categoryKey: item.categoryKey } as Prisma.InputJsonValue,
|
||||
sortOrder,
|
||||
isEnabled: true,
|
||||
})),
|
||||
|
||||
@@ -2,6 +2,7 @@ import assert from "node:assert/strict";
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { after, before, test } from "node:test";
|
||||
import { PrismaClient } from "@prisma/client";
|
||||
import { getVisualTemplateManifest } from "@personal-brand/config";
|
||||
import { createApp } from "../dist/main.js";
|
||||
import { readIdentity, signIdentity } from "../dist/auth.js";
|
||||
import { WechatAuthService } from "../dist/wechat-auth.js";
|
||||
@@ -1189,6 +1190,12 @@ test("visual template compatibility is enforced by catalog, preview, and brand s
|
||||
const catalog = await request("/public/templates");
|
||||
assert.equal(catalog.statusCode, 200);
|
||||
const visuals = JSON.parse(catalog.body).visuals;
|
||||
for (const visual of visuals) {
|
||||
const manifest = getVisualTemplateManifest(visual.key);
|
||||
assert.ok(manifest, `Catalog visual must be installable: ${visual.key}`);
|
||||
assert.equal(manifest.key, visual.key);
|
||||
assert.deepEqual(manifest.supportedIndustryTemplates, visual.supportedIndustryTemplates);
|
||||
}
|
||||
assert.deepEqual(
|
||||
visuals.find((visual) => visual.key === "linjing-editorial").supportedIndustryTemplates,
|
||||
["personal", "doors"],
|
||||
@@ -3468,7 +3475,7 @@ test("atelier template imports selected package and preserves draft publication
|
||||
tagline: "独立开发者 · 品牌小程序构建",
|
||||
description: "专注个人品牌表达、内容管理与咨询承接。",
|
||||
config: {
|
||||
visualTemplateKey: "atelier-solopreneur",
|
||||
visualTemplateKey: "linjing-editorial",
|
||||
founder: "验收主理人",
|
||||
title: "产品设计 / 全栈开发",
|
||||
visualPresentation: { home: { subtitle: "保留已有品牌说明" } },
|
||||
@@ -3501,6 +3508,18 @@ test("atelier template imports selected package and preserves draft publication
|
||||
403,
|
||||
);
|
||||
}
|
||||
await json("/admin/config/brand", {
|
||||
method: "PATCH",
|
||||
headers,
|
||||
payload: { config: { visualTemplateKey: "atelier-solopreneur" } },
|
||||
});
|
||||
const installation = await json("/admin/workspace/install", {
|
||||
method: "POST",
|
||||
headers,
|
||||
payload: { templateKey: "personal" },
|
||||
});
|
||||
assert.equal(installation.visualTemplate.key, "atelier-solopreneur");
|
||||
assert.equal(installation.visualTemplate.tokens.colors.accent, "#183329");
|
||||
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 });
|
||||
@@ -3523,6 +3542,16 @@ test("atelier template imports selected package and preserves draft publication
|
||||
where: { brandId: brand.id },
|
||||
});
|
||||
assert.match(exampleOffering.coverUrl, /^\/assets\/cases\//);
|
||||
const sampleRuntime = await json("/admin/workspace/preview", { headers });
|
||||
for (const item of sampleRuntime.offerings) {
|
||||
assert.equal(item.presentation.categoryLabel, "案例展示");
|
||||
assert.equal(item.priceText, "按需求确认范围与报价");
|
||||
assert.ok(item.presentation.spaceType);
|
||||
assert.ok(item.presentation.details.background);
|
||||
assert.ok(item.presentation.details.designConcept);
|
||||
assert.ok(item.presentation.details.crafts.length);
|
||||
assert.ok(item.presentation.details.materialsList.length);
|
||||
}
|
||||
const offeringFields = [
|
||||
...new Map(
|
||||
manifest.admin.sections
|
||||
|
||||
Reference in new issue
Block a user