62 lines
2.5 KiB
JavaScript
62 lines
2.5 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import test from "node:test";
|
|
import { validateTemplatePackageManifest } from "../src/index.ts";
|
|
|
|
const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
|
|
|
|
for (const key of ["acheng-campus-food", "linjing-editorial"]) {
|
|
test(`${key} declares valid admin content and asset requirements`, () => {
|
|
const manifestPath = path.join(packageRoot, `template-${key}`, "template.json");
|
|
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
|
|
assert.deepEqual(validateTemplatePackageManifest(manifest), []);
|
|
});
|
|
}
|
|
|
|
test("template contract rejects technical or incomplete admin declarations", () => {
|
|
const manifestPath = path.join(packageRoot, "template-acheng-campus-food/template.json");
|
|
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
|
|
manifest.admin.sections[0].fields[0].label = "";
|
|
manifest.assetSlots[0].help = "";
|
|
assert.deepEqual(validateTemplatePackageManifest(manifest), [
|
|
"every asset slot requires key, binding, label and help",
|
|
"every admin field requires key, binding and label",
|
|
]);
|
|
});
|
|
|
|
test("template manifests declare editable material content", () => {
|
|
const linjing = JSON.parse(
|
|
fs.readFileSync(path.join(packageRoot, "template-linjing-editorial/template.json"), "utf8"),
|
|
);
|
|
const acheng = JSON.parse(
|
|
fs.readFileSync(path.join(packageRoot, "template-acheng-campus-food/template.json"), "utf8"),
|
|
);
|
|
const bindings = (manifest) =>
|
|
new Set(
|
|
manifest.admin.sections.flatMap((section) => section.fields.map((field) => field.binding)),
|
|
);
|
|
for (const binding of [
|
|
"brand.config.homeHero.title",
|
|
"brand.config.profilePresentation.coverage",
|
|
"brand.config.profilePresentation.warranty",
|
|
"offering.config.area",
|
|
"offering.config.details.designConcept",
|
|
"brand.config.visualPresentation.offerings.closingText",
|
|
])
|
|
assert.ok(bindings(linjing).has(binding), binding);
|
|
for (const binding of [
|
|
"brand.config.visualPresentation.profile.coverageContent",
|
|
"brand.config.visualPresentation.offerings.menuTip",
|
|
"brand.config.visualPresentation.inquiry.promise",
|
|
])
|
|
assert.ok(bindings(acheng).has(binding), binding);
|
|
assert.deepEqual(
|
|
linjing.trustContentTypes
|
|
.find((item) => item.type === "credential")
|
|
.configFields.map((field) => field.key),
|
|
["stats", "pillars", "serviceFlow"],
|
|
);
|
|
});
|