fix: 校验必需信任内容完整性
This commit is contained in:
1 parent
5ed06b1abe
commit
0c5ff79b42
4 files changed
+71
-10
No files matched your search
@@ -80,9 +80,12 @@ export class BrandReleaseApiService {
|
||||
}),
|
||||
database.trustContent.findMany({
|
||||
where: { brandId, isPublished: true },
|
||||
select: { type: true },
|
||||
select: { type: true, title: true, content: true },
|
||||
}),
|
||||
]);
|
||||
const validTrustItems = trustItems.filter(
|
||||
(item) => item.title.trim().length > 0 && item.content.trim().length > 0,
|
||||
);
|
||||
const offeringIds = new Set(offerings.map((item) => item.id));
|
||||
const usableForms = forms.filter(
|
||||
(form) =>
|
||||
@@ -132,18 +135,18 @@ export class BrandReleaseApiService {
|
||||
{
|
||||
key: "trust",
|
||||
label: "至少需要一条已发布的信任内容",
|
||||
passed: trustItems.length > 0,
|
||||
passed: validTrustItems.length > 0,
|
||||
destination: "/admin/trust",
|
||||
},
|
||||
];
|
||||
const publishedTrustTypes = new Set(trustItems.map((item) => item.type));
|
||||
const publishedTrustTypes = new Set(validTrustItems.map((item) => item.type));
|
||||
for (const type of packageManifest?.trustContentTypes ?? []) {
|
||||
if (type.required !== true) continue;
|
||||
checks.push({
|
||||
key: `trust:${type.type}`,
|
||||
label: `请补充${type.label}`,
|
||||
label: `请完善${type.label}`,
|
||||
passed: publishedTrustTypes.has(type.type),
|
||||
...(type.help ? { help: type.help } : {}),
|
||||
help: ["标题和详细内容都填写后才能发布。", type.help].filter(Boolean).join(" "),
|
||||
destination: "/admin/trust",
|
||||
});
|
||||
}
|
||||
|
||||
@@ -98,11 +98,16 @@ test("admin release lifecycle is authorized, brand-scoped, and versioned", async
|
||||
where: { brandId, type: "schedule", isPublished: true },
|
||||
});
|
||||
assert.ok(scheduleTrust);
|
||||
await prisma.trustContent.update({
|
||||
where: { id: scheduleTrust.id },
|
||||
data: { isPublished: false },
|
||||
});
|
||||
const originalScheduleTrust = {
|
||||
isPublished: scheduleTrust.isPublished,
|
||||
title: scheduleTrust.title,
|
||||
content: scheduleTrust.content,
|
||||
};
|
||||
try {
|
||||
await prisma.trustContent.update({
|
||||
where: { id: scheduleTrust.id },
|
||||
data: { isPublished: false },
|
||||
});
|
||||
const missingTrust = await request("/admin/releases/readiness", {
|
||||
headers: { authorization: `Bearer ${adminToken}` },
|
||||
});
|
||||
@@ -112,10 +117,54 @@ test("admin release lifecycle is authorized, brand-scoped, and versioned", async
|
||||
missingTrustBody.checks.find((check) => check.key === "trust:schedule")?.passed,
|
||||
false,
|
||||
);
|
||||
await prisma.trustContent.update({
|
||||
where: { id: scheduleTrust.id },
|
||||
data: { isPublished: true, title: " " },
|
||||
});
|
||||
const missingTitle = JSON.parse(
|
||||
(
|
||||
await request("/admin/releases/readiness", {
|
||||
headers: { authorization: `Bearer ${adminToken}` },
|
||||
})
|
||||
).body,
|
||||
);
|
||||
assert.equal(missingTitle.ready, false);
|
||||
assert.equal(
|
||||
missingTitle.checks.find((check) => check.key === "trust:schedule")?.passed,
|
||||
false,
|
||||
);
|
||||
await prisma.trustContent.update({
|
||||
where: { id: scheduleTrust.id },
|
||||
data: { title: originalScheduleTrust.title, content: " \n " },
|
||||
});
|
||||
const missingContent = JSON.parse(
|
||||
(
|
||||
await request("/admin/releases/readiness", {
|
||||
headers: { authorization: `Bearer ${adminToken}` },
|
||||
})
|
||||
).body,
|
||||
);
|
||||
assert.equal(missingContent.ready, false);
|
||||
assert.equal(
|
||||
missingContent.checks.find((check) => check.key === "trust:schedule")?.passed,
|
||||
false,
|
||||
);
|
||||
await prisma.trustContent.update({
|
||||
where: { id: scheduleTrust.id },
|
||||
data: originalScheduleTrust,
|
||||
});
|
||||
const validTrust = JSON.parse(
|
||||
(
|
||||
await request("/admin/releases/readiness", {
|
||||
headers: { authorization: `Bearer ${adminToken}` },
|
||||
})
|
||||
).body,
|
||||
);
|
||||
assert.equal(validTrust.checks.find((check) => check.key === "trust:schedule")?.passed, true);
|
||||
} finally {
|
||||
await prisma.trustContent.update({
|
||||
where: { id: scheduleTrust.id },
|
||||
data: { isPublished: true },
|
||||
data: originalScheduleTrust,
|
||||
});
|
||||
}
|
||||
const originalBrand = await prisma.brandProfile.findUniqueOrThrow({ where: { id: brandId } });
|
||||
|
||||
Reference in new issue
Block a user