feat(platform): add replaceable geozone data layer
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
import {
|
||||
ZONE_SOURCE_GENERATION_SCHEMA_VERSION,
|
||||
normalizeZoneSourceGeneration,
|
||||
validateDataProductPublish,
|
||||
} from "../src/index.mjs";
|
||||
|
||||
const generatedAt = "2026-07-20T18:00:00.000Z";
|
||||
const live = normalizeZoneSourceGeneration({
|
||||
schemaVersion: ZONE_SOURCE_GENERATION_SCHEMA_VERSION,
|
||||
adapterId: "gelios-rest-v1",
|
||||
sourceRevision: "gelios-rest-v1",
|
||||
generatedAt,
|
||||
complete: true,
|
||||
zones: [{
|
||||
id: 42,
|
||||
name: "Polygon zone",
|
||||
type: "polygon",
|
||||
points: [
|
||||
{ latitude: 55.74, longitude: 37.60 },
|
||||
{ latitude: 55.74, longitude: 37.62 },
|
||||
{ latitude: 55.76, longitude: 37.62 },
|
||||
],
|
||||
color: "#ff00ff",
|
||||
}, {
|
||||
id: 43,
|
||||
name: "Circle zone",
|
||||
type: "circle",
|
||||
points: [{ latitude: 55.75, longitude: 37.61 }],
|
||||
radius: 150,
|
||||
}],
|
||||
});
|
||||
assert.equal(live.complete, true);
|
||||
assert.equal(live.sourceKind, "live_api");
|
||||
assert.equal(live.facts.length, 2);
|
||||
assert.deepEqual(live.facts.map((fact) => fact.sourceId), ["gelios-zone-42", "gelios-zone-43"]);
|
||||
assert.equal(live.facts.every((fact) => fact.observedAt === generatedAt), true);
|
||||
assert.equal(live.facts.every((fact) => fact.geometry.type === "Polygon"), true);
|
||||
assert.equal(validateDataProductPublish({
|
||||
schemaVersion: "nodedc.data-product.publish/v1",
|
||||
batch: { runId: "zones-live-1", sequence: 0, idempotencyKey: "zones-live-1.batch-0", mode: "replace", generationAt: generatedAt },
|
||||
facts: live.facts,
|
||||
}).ok, true);
|
||||
|
||||
const snapshotDigest = "a".repeat(64);
|
||||
const snapshot = normalizeZoneSourceGeneration({
|
||||
schemaVersion: ZONE_SOURCE_GENERATION_SCHEMA_VERSION,
|
||||
adapterId: "mmap-snapshot-v1",
|
||||
snapshotDigest,
|
||||
generatedAt,
|
||||
complete: true,
|
||||
zones: [{
|
||||
snapshotKey: "legacy-zone-a",
|
||||
name: "Snapshot zone",
|
||||
type: "polygon",
|
||||
points: "55.74,37.60;55.74,37.62;55.76,37.62",
|
||||
}],
|
||||
}, { identityCrosswalk: { "legacy-zone-a": 42 } });
|
||||
assert.equal(snapshot.sourceKind, "versioned_snapshot");
|
||||
assert.equal(snapshot.facts[0].sourceId, live.facts[0].sourceId);
|
||||
assert.match(snapshot.sourceRevision, new RegExp(`@sha256:${snapshotDigest}$`));
|
||||
|
||||
assert.throws(() => normalizeZoneSourceGeneration({
|
||||
schemaVersion: ZONE_SOURCE_GENERATION_SCHEMA_VERSION,
|
||||
adapterId: "mmap-snapshot-v1",
|
||||
snapshotDigest,
|
||||
generatedAt,
|
||||
complete: true,
|
||||
zones: [{ snapshotKey: "unknown", name: "Unknown", type: "polygon", points: "55.74,37.60;55.74,37.62;55.76,37.62" }],
|
||||
}), /zone_source_identity_crosswalk_required/);
|
||||
assert.throws(() => normalizeZoneSourceGeneration({
|
||||
schemaVersion: ZONE_SOURCE_GENERATION_SCHEMA_VERSION,
|
||||
adapterId: "mmap-snapshot-v1",
|
||||
snapshotDigest,
|
||||
generatedAt,
|
||||
complete: true,
|
||||
zones: [{ id: 42, name: "Uncrossed", type: "polygon", points: "55.74,37.60;55.74,37.62;55.76,37.62" }],
|
||||
}), /zone_source_identity_crosswalk_required/);
|
||||
assert.throws(() => normalizeZoneSourceGeneration({
|
||||
schemaVersion: ZONE_SOURCE_GENERATION_SCHEMA_VERSION,
|
||||
adapterId: "gelios-rest-v1",
|
||||
generatedAt,
|
||||
complete: true,
|
||||
zones: [{ name: "No native id", type: "polygon", points: "55.74,37.60;55.74,37.62;55.76,37.62" }],
|
||||
}), /zone_source_native_identity_required/);
|
||||
assert.throws(() => normalizeZoneSourceGeneration({
|
||||
schemaVersion: ZONE_SOURCE_GENERATION_SCHEMA_VERSION,
|
||||
adapterId: "gelios-rest-v1",
|
||||
generatedAt,
|
||||
complete: false,
|
||||
zones: [],
|
||||
}), /zone_source_generation_incomplete/);
|
||||
|
||||
console.log("external-provider zone source: ok");
|
||||
Reference in New Issue
Block a user