76 lines
2.4 KiB
JavaScript
76 lines
2.4 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
import {
|
|
MapRuntimeError,
|
|
applyCacheIntent,
|
|
initialMapRuntimeState,
|
|
withProviderState,
|
|
} from "../dist/index.js";
|
|
|
|
test("cache intent keeps all provider traffic behind the gateway contract", () => {
|
|
const cached = new URL(
|
|
applyCacheIntent("https://assets.ion.cesium.com/tileset.json?v=1", {
|
|
enabled: true,
|
|
no_overwrite: true,
|
|
}, false),
|
|
);
|
|
assert.equal(cached.searchParams.get("nodedc_cache_profile"), "live");
|
|
assert.equal(cached.searchParams.has("nodedc_cache_refresh"), false);
|
|
|
|
const passthrough = new URL(
|
|
applyCacheIntent("https://assets.ion.cesium.com/tileset.json", {
|
|
enabled: false,
|
|
no_overwrite: true,
|
|
}, false),
|
|
);
|
|
assert.equal(passthrough.searchParams.get("nodedc_cache_mode"), "passthrough");
|
|
|
|
const refresh = new URL(
|
|
applyCacheIntent("https://assets.ion.cesium.com/tileset.json", {
|
|
enabled: true,
|
|
no_overwrite: true,
|
|
}, true),
|
|
);
|
|
assert.equal(refresh.searchParams.get("nodedc_cache_refresh"), "1");
|
|
});
|
|
|
|
test("provider URLs reject direct credentials and non-HTTPS transport", () => {
|
|
for (const value of [
|
|
"http://assets.ion.cesium.com/tile.bin",
|
|
"https://user:pass@assets.ion.cesium.com/tile.bin",
|
|
"https://assets.ion.cesium.com/tile.bin?access_token=forbidden",
|
|
"https://assets.ion.cesium.com/tile.bin#token",
|
|
]) {
|
|
assert.throws(
|
|
() => applyCacheIntent(value, { enabled: true, no_overwrite: true }, false),
|
|
MapRuntimeError,
|
|
);
|
|
}
|
|
});
|
|
|
|
test("independent provider states produce ready, degraded and unavailable phases", () => {
|
|
let state = initialMapRuntimeState();
|
|
state = withProviderState(state, "imagery", { phase: "ready" });
|
|
state = withProviderState(state, "terrain", { phase: "ready" });
|
|
state = withProviderState(state, "buildings", { phase: "ready" });
|
|
assert.equal(state.phase, "ready");
|
|
|
|
state = withProviderState(state, "buildings", {
|
|
phase: "error",
|
|
code: "cesium_ion_endpoint_unavailable",
|
|
});
|
|
assert.equal(state.phase, "degraded");
|
|
assert.equal(state.code, "cesium_ion_endpoint_unavailable");
|
|
|
|
state = withProviderState(state, "imagery", {
|
|
phase: "error",
|
|
code: "map_upstream_timeout",
|
|
});
|
|
state = withProviderState(state, "terrain", {
|
|
phase: "error",
|
|
code: "map_upstream_timeout",
|
|
});
|
|
assert.equal(state.phase, "gateway-unavailable");
|
|
});
|