Files
NODEDC_DESIGN_GUIDELINE/packages/map-cesium-react/test/providerEndpoint.test.mjs
T

70 lines
1.8 KiB
JavaScript

import assert from "node:assert/strict";
import test from "node:test";
import { parseProviderEndpoint } from "../dist/providerEndpoint.js";
const attributions = [{ html: "provider", collapsible: true }];
test("provider endpoint accepts the canonical string asset identifiers", () => {
const imagery = parseProviderEndpoint({
assetId: "2",
type: "IMAGERY",
externalType: "BING",
credentialMode: "gateway",
options: {
url: "https://dev.virtualearth.net/REST/v1/Imagery/Metadata/Aerial",
mapStyle: "Aerial",
},
attributions,
}, 2, "imagery");
const terrain = parseProviderEndpoint({
assetId: "1",
type: "TERRAIN",
credentialMode: "gateway",
url: "https://assets.ion.cesium.com/terrain/",
attributions,
}, 1, "terrain");
const buildings = parseProviderEndpoint({
assetId: "96188",
type: "3DTILES",
credentialMode: "gateway",
url: "https://assets.ion.cesium.com/buildings/tileset.json",
attributions,
}, 96188, "buildings");
assert.equal(imagery.assetId, "2");
assert.equal(terrain.assetId, "1");
assert.equal(buildings.assetId, "96188");
});
test("provider endpoint rejects numeric, mismatched and credential-bearing shapes", () => {
for (const document of [
{
assetId: 1,
type: "TERRAIN",
credentialMode: "gateway",
url: "https://assets.ion.cesium.com/terrain/",
attributions,
},
{
assetId: "2",
type: "TERRAIN",
credentialMode: "gateway",
url: "https://assets.ion.cesium.com/terrain/",
attributions,
},
{
assetId: "1",
type: "TERRAIN",
credentialMode: "browser",
url: "https://assets.ion.cesium.com/terrain/",
attributions,
},
]) {
assert.throws(
() => parseProviderEndpoint(document, 1, "terrain"),
/map_provider_contract_mismatch/,
);
}
});