100 lines
3.1 KiB
JavaScript
100 lines
3.1 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import { buildTemplateContractPlan } from "./prepare-template-contract.mjs";
|
|
|
|
function manifest(packageKey, industry, version = "1.0.0") {
|
|
return {
|
|
packageKey,
|
|
version,
|
|
visualTemplateKey: packageKey,
|
|
runtimeContract: "1.0",
|
|
supportedIndustryTemplates: [industry],
|
|
previewFixture: { [industry]: { schemaVersion: "1" } },
|
|
};
|
|
}
|
|
|
|
function catalogEntry(packageKey, industry, version = "1.0.0") {
|
|
return {
|
|
packageKey,
|
|
version,
|
|
displayName: packageKey,
|
|
contentChecksum: "a".repeat(64),
|
|
validationReport: { errors: [] },
|
|
manifest: manifest(packageKey, industry, version),
|
|
archiveChecksum: "b".repeat(64),
|
|
archivePath: `template-artifacts/${packageKey}/${version}/${"b".repeat(64)}.tar.gz`,
|
|
};
|
|
}
|
|
|
|
test("template contract plan resolves legacy installations and imports missing packages", () => {
|
|
const existing = catalogEntry("atelier-solopreneur", "personal", "1.3.2");
|
|
const defaultBrand = catalogEntry("acheng-campus-food", "food", "1.0.3");
|
|
const plan = buildTemplateContractPlan({
|
|
catalog: { formatVersion: "1", packages: [existing, defaultBrand] },
|
|
versions: [],
|
|
brands: [
|
|
{
|
|
brandId: "brand-1",
|
|
slug: "atelier-studio",
|
|
templateKey: "personal",
|
|
brandVisualTemplateKey: "atelier-solopreneur",
|
|
installations: [
|
|
{
|
|
id: "installation-1",
|
|
templatePackageVersionId: null,
|
|
visualTemplateKey: null,
|
|
snapshotVisualTemplateKey: null,
|
|
snapshotPackageKey: null,
|
|
},
|
|
],
|
|
},
|
|
{
|
|
brandId: "brand-2",
|
|
slug: "default-brand",
|
|
templateKey: "food",
|
|
brandVisualTemplateKey: "acheng-campus-food",
|
|
installations: [],
|
|
},
|
|
],
|
|
});
|
|
|
|
assert.deepEqual(
|
|
plan.catalogImports.map((entry) => `${entry.packageKey}@${entry.version}`),
|
|
["atelier-solopreneur@1.3.2", "acheng-campus-food@1.0.3"],
|
|
);
|
|
assert.equal(plan.installations.length, 2);
|
|
assert.equal(plan.installations[0].installationId, "installation-1");
|
|
assert.equal(plan.installations[0].packageVersionId, null);
|
|
assert.equal(plan.installations[0].catalogImport, true);
|
|
assert.equal(plan.installations[1].installationId, null);
|
|
assert.equal(plan.installations[1].slug, "default-brand");
|
|
});
|
|
|
|
test("template contract plan rejects conflicting legacy package declarations", () => {
|
|
assert.throws(
|
|
() =>
|
|
buildTemplateContractPlan({
|
|
catalog: { formatVersion: "1", packages: [] },
|
|
versions: [],
|
|
brands: [
|
|
{
|
|
brandId: "brand-1",
|
|
slug: "conflicting-brand",
|
|
templateKey: "food",
|
|
brandVisualTemplateKey: "acheng-campus-food",
|
|
installations: [
|
|
{
|
|
id: "installation-1",
|
|
templatePackageVersionId: null,
|
|
visualTemplateKey: "linjing-editorial",
|
|
snapshotVisualTemplateKey: null,
|
|
snapshotPackageKey: null,
|
|
},
|
|
],
|
|
},
|
|
],
|
|
}),
|
|
/模板包声明冲突/,
|
|
);
|
|
});
|