134 lines
4.2 KiB
JavaScript
134 lines
4.2 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import { test } from "node:test";
|
|
import { buildTemplateContractMigrationReport } from "../scripts/template-contract-migration-audit.mjs";
|
|
|
|
function brandRow(overrides = {}) {
|
|
return {
|
|
brandId: "brand-1",
|
|
slug: "sample-brand",
|
|
industry: "food",
|
|
brandVisualTemplateKey: "acheng-campus-food",
|
|
installationId: "installation-1",
|
|
installationVisualTemplateKey: null,
|
|
installationPackageVersionId: null,
|
|
snapshotVisualTemplateKey: null,
|
|
snapshotPackageKey: null,
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
function packageVersion(overrides = {}) {
|
|
const manifestSnapshot = {
|
|
packageKey: "acheng-campus-food",
|
|
version: "1.0.2",
|
|
visualTemplateKey: "acheng-campus-food",
|
|
runtimeContract: "1.0",
|
|
supportedIndustryTemplates: ["food"],
|
|
previewFixture: { food: { schemaVersion: "1" } },
|
|
};
|
|
return {
|
|
id: "version-1",
|
|
packageKey: "acheng-campus-food",
|
|
version: "1.0.2",
|
|
status: "published",
|
|
visualTemplateKey: "acheng-campus-food",
|
|
manifestSnapshot,
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
test("migration audit accepts a unique published version named by explicit legacy config", () => {
|
|
const report = buildTemplateContractMigrationReport({
|
|
brands: [brandRow()],
|
|
versions: [packageVersion()],
|
|
});
|
|
|
|
assert.equal(report.ready, true);
|
|
assert.equal(report.brands[0].packageKey, "acheng-campus-food");
|
|
assert.deepEqual(report.brands[0].blockers, []);
|
|
});
|
|
|
|
test("migration audit uses manifest metadata instead of the redundant database renderer column", () => {
|
|
const report = buildTemplateContractMigrationReport({
|
|
brands: [brandRow()],
|
|
versions: [packageVersion({ visualTemplateKey: null, status: "imported" })],
|
|
});
|
|
|
|
assert.deepEqual(report.brands[0].blockers, ["matching_package_version_not_published"]);
|
|
assert.equal(report.brands[0].candidates[0].version, "1.0.2");
|
|
});
|
|
|
|
test("migration audit does not infer a package from the brand industry", () => {
|
|
const report = buildTemplateContractMigrationReport({
|
|
brands: [brandRow({ brandVisualTemplateKey: null })],
|
|
versions: [packageVersion()],
|
|
});
|
|
|
|
assert.equal(report.ready, false);
|
|
assert.deepEqual(report.brands[0].blockers, ["explicit_package_declaration_missing"]);
|
|
});
|
|
|
|
test("migration audit requires the explicitly named package version to be published", () => {
|
|
const report = buildTemplateContractMigrationReport({
|
|
brands: [brandRow()],
|
|
versions: [packageVersion({ status: "imported" })],
|
|
});
|
|
|
|
assert.deepEqual(report.brands[0].blockers, ["matching_package_version_not_published"]);
|
|
assert.equal(report.brands[0].candidates[0].version, "1.0.2");
|
|
});
|
|
|
|
test("migration audit blocks multiple valid published versions instead of picking the latest", () => {
|
|
const report = buildTemplateContractMigrationReport({
|
|
brands: [brandRow()],
|
|
versions: [
|
|
packageVersion(),
|
|
packageVersion({
|
|
id: "version-2",
|
|
version: "1.0.3",
|
|
manifestSnapshot: {
|
|
...packageVersion().manifestSnapshot,
|
|
version: "1.0.3",
|
|
},
|
|
}),
|
|
],
|
|
});
|
|
|
|
assert.deepEqual(report.brands[0].blockers, ["published_package_version_ambiguous"]);
|
|
});
|
|
|
|
test("uninstalled historical snapshots are reported without blocking mapped brands", () => {
|
|
const report = buildTemplateContractMigrationReport({
|
|
brands: [brandRow()],
|
|
versions: [
|
|
packageVersion(),
|
|
packageVersion({
|
|
id: "old-version",
|
|
version: "1.0.1",
|
|
status: "retired",
|
|
visualTemplateKey: null,
|
|
manifestSnapshot: { packageKey: "acheng-campus-food", version: "1.0.1" },
|
|
}),
|
|
],
|
|
});
|
|
|
|
assert.equal(report.ready, true);
|
|
assert.equal(report.summary.historicalInvalidVersionCount, 1);
|
|
assert.deepEqual(report.invalidHistoricalVersions[0], {
|
|
packageKey: "acheng-campus-food",
|
|
version: "1.0.1",
|
|
status: "retired",
|
|
storedVisualTemplateKey: null,
|
|
hasPreviewFixture: false,
|
|
});
|
|
});
|
|
|
|
test("migration audit blocks conflicting explicit package declarations", () => {
|
|
const report = buildTemplateContractMigrationReport({
|
|
brands: [brandRow({ installationVisualTemplateKey: "linjing-editorial" })],
|
|
versions: [packageVersion()],
|
|
});
|
|
|
|
assert.deepEqual(report.brands[0].blockers, ["legacy_package_declarations_conflict"]);
|
|
});
|