Initial reliable release of consent engine
This commit is contained in:
@@ -0,0 +1,136 @@
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
import {
|
||||
resolveConsentContext,
|
||||
createIntegratedConsentEngine
|
||||
} from "../../integration/index.js";
|
||||
|
||||
function test(name, fn) {
|
||||
try {
|
||||
fn();
|
||||
console.log(`PASS ${name}`);
|
||||
} catch (error) {
|
||||
console.error(`FAIL ${name}`);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
test("fixed us-ma resolves into Core context", () => {
|
||||
const context = resolveConsentContext({
|
||||
mode: "fixed",
|
||||
jurisdiction: "us-ma"
|
||||
});
|
||||
|
||||
assert.equal(context.resolution.jurisdiction.id, "us-ma");
|
||||
assert.equal(context.resolution.policy.id, "us-state-privacy");
|
||||
});
|
||||
|
||||
test("fixed eu resolves into Core context", () => {
|
||||
const context = resolveConsentContext({
|
||||
mode: "fixed",
|
||||
jurisdiction: "eu"
|
||||
});
|
||||
|
||||
assert.equal(context.resolution.jurisdiction.id, "eu");
|
||||
assert.equal(context.resolution.policy.id, "eu-privacy");
|
||||
});
|
||||
|
||||
test("global resolves into global baseline", () => {
|
||||
const context = resolveConsentContext({ mode: "global" });
|
||||
|
||||
assert.equal(context.resolution.jurisdiction.id, "global");
|
||||
assert.equal(context.resolution.policy.id, "global-baseline");
|
||||
});
|
||||
|
||||
test("integration configures Core jurisdiction", () => {
|
||||
const consent = createIntegratedConsentEngine({
|
||||
jurisdiction: { mode: "fixed", jurisdiction: "us-ma" }
|
||||
});
|
||||
|
||||
const state = consent.initialize();
|
||||
|
||||
assert.equal(state.jurisdiction, "us-ma");
|
||||
assert.equal(state.hasDecision, false);
|
||||
});
|
||||
|
||||
test("jurisdiction does not grant consent", () => {
|
||||
const consent = createIntegratedConsentEngine({
|
||||
jurisdiction: { mode: "fixed", jurisdiction: "us-ma" }
|
||||
});
|
||||
|
||||
const state = consent.initialize();
|
||||
|
||||
assert.equal(state.categories.necessary, "granted");
|
||||
assert.equal(state.categories.preferences, "unknown");
|
||||
assert.equal(state.categories.analytics, "unknown");
|
||||
assert.equal(state.categories.marketing, "unknown");
|
||||
assert.equal(state.hasDecision, false);
|
||||
});
|
||||
|
||||
test("resolved context is exposed without mutable internals", () => {
|
||||
const consent = createIntegratedConsentEngine({
|
||||
jurisdiction: { mode: "fixed", jurisdiction: "eu" }
|
||||
});
|
||||
|
||||
const context = consent.getJurisdictionContext();
|
||||
|
||||
assert.equal(context.resolution.jurisdiction.id, "eu");
|
||||
assert.equal(Object.isFrozen(context), true);
|
||||
assert.equal(Object.isFrozen(context.resolution), true);
|
||||
});
|
||||
|
||||
test("Core configuration preserves resolved jurisdiction", () => {
|
||||
const consent = createIntegratedConsentEngine({
|
||||
jurisdiction: { mode: "fixed", jurisdiction: "us-ma" }
|
||||
});
|
||||
|
||||
const config = consent.getConfig();
|
||||
|
||||
assert.equal(config.jurisdiction, "us-ma");
|
||||
});
|
||||
|
||||
test("Node environment does not fake successful persistence", () => {
|
||||
const consent = createIntegratedConsentEngine({
|
||||
jurisdiction: { mode: "fixed", jurisdiction: "us-ma" }
|
||||
});
|
||||
|
||||
consent.initialize();
|
||||
const state = consent.acceptAll();
|
||||
|
||||
assert.equal(state.jurisdiction, "us-ma");
|
||||
assert.equal(state.hasDecision, false);
|
||||
assert.equal(state.categories.preferences, "unknown");
|
||||
assert.equal(state.categories.analytics, "unknown");
|
||||
assert.equal(state.categories.marketing, "unknown");
|
||||
});
|
||||
|
||||
test("integration remains deterministic", () => {
|
||||
const input = {
|
||||
mode: "auto",
|
||||
request: {
|
||||
jurisdiction: "us-ma",
|
||||
source: "server"
|
||||
},
|
||||
visitor: {
|
||||
jurisdiction: "eu",
|
||||
source: "browser"
|
||||
}
|
||||
};
|
||||
|
||||
const first = resolveConsentContext(input);
|
||||
const second = resolveConsentContext(input);
|
||||
|
||||
assert.deepEqual(first, second);
|
||||
});
|
||||
|
||||
test("invalid jurisdiction remains an Engine error", () => {
|
||||
assert.throws(
|
||||
() => resolveConsentContext({
|
||||
mode: "fixed",
|
||||
jurisdiction: "not-a-jurisdiction"
|
||||
}),
|
||||
/Unknown jurisdiction/
|
||||
);
|
||||
});
|
||||
|
||||
console.log("10 integration tests passed.");
|
||||
Reference in New Issue
Block a user