Files
clean-architecture-frontend…/tests/platform/release/release-coherence.test.ts

88 lines
2.5 KiB
TypeScript

import { describe, expect, it } from "vitest";
import {
assertReleaseCoherent,
checkReleaseCoherence,
ReleaseMismatchError,
} from "../../../src/platform/release/release-coherence.ts";
function identity(release: string) {
return Object.freeze({
buildId: `build-${release}`,
releaseId: `release-${release}`,
configSchemaVersion: "2.0",
assetManifestHash: `assets-${release}`,
});
}
describe("assertReleaseCoherent", () => {
it.each([
["R10", "R10", "R10", true],
["R10", "R11", "R10", false],
["R10", "R10", "R11", false],
["R11", "R11", "R11", true],
["R11", "R10", "R10", false],
["R10", "R11", "R11", false],
])(
"HTML %s config %s manifest %s => coherent=%s",
(html, config, manifest, coherent) => {
const run = () =>
assertReleaseCoherent(
identity(html),
identity(config),
identity(manifest),
);
if (coherent) expect(run).not.toThrow();
else expect(run).toThrow(/release.*mismatch/i);
},
);
it("reports the first incoherent field in the boot precedence order", () => {
const result = checkReleaseCoherence({
html: { buildId: "b1", assetManifestHash: "a1" },
config: { buildId: "b1", configSchemaVersion: "2.0", releaseId: "r2" },
manifest: {
buildId: "b1",
configSchemaVersion: "2.1",
releaseId: "r1",
assetManifestHash: "a2",
},
});
expect(result).toEqual({
coherent: false,
field: "configSchemaVersion",
sources: ["config", "manifest"],
});
});
it("compares only fields that two sources both carry", () => {
expect(
checkReleaseCoherence({
html: { buildId: "b1" },
config: { buildId: "b1" },
manifest: { buildId: "b1", releaseId: "r1", assetManifestHash: "a" },
}),
).toEqual({ coherent: true });
});
it("fails closed when HTML or manifest cannot name its build", () => {
expect(() =>
assertReleaseCoherent({}, identity("R10"), identity("R10")),
).toThrow(ReleaseMismatchError);
expect(() =>
assertReleaseCoherent(identity("R10"), identity("R10"), { releaseId: "release-R10" }),
).toThrow(ReleaseMismatchError);
});
it("exposes which field and sources disagreed", () => {
try {
assertReleaseCoherent(identity("R10"), identity("R11"), identity("R10"));
expect.unreachable();
} catch (error) {
expect(error).toBeInstanceOf(ReleaseMismatchError);
expect(error).toMatchObject({ field: "buildId", sources: ["html", "config"] });
}
});
});