feat(platform): complete the Gelios external data loop
This commit is contained in:
@@ -24,6 +24,8 @@ assert.deepEqual(input.semanticTypes, ["vehicle.trike", "map.moving_object"]);
|
||||
assert.deepEqual(input.fields, ["status", "source_id", "observed_at", "geometry"]);
|
||||
assert.equal(Object.isFrozen(definition.semanticTypes), true);
|
||||
assert.equal(Object.isFrozen(definition.fields), true);
|
||||
assert.deepEqual(definition.fieldContracts, {});
|
||||
assert.equal(Object.isFrozen(definition.fieldContracts), true);
|
||||
|
||||
const reordered = normalizeDataProductDefinition({
|
||||
...input,
|
||||
@@ -78,4 +80,49 @@ assert.throws(
|
||||
/data_product_definition_fields_duplicate/,
|
||||
);
|
||||
|
||||
const strict = normalizeDataProductDefinition({
|
||||
...input,
|
||||
fields: ["geometry", "movement_state", "signal_state", "speed_kph"],
|
||||
fieldContracts: {
|
||||
geometry: { type: "point", required: false },
|
||||
movement_state: { type: "string", required: true, enum: ["stopped", "moving"] },
|
||||
signal_state: { type: "string", required: true, enum: ["inactive", "active"] },
|
||||
speed_kph: { type: "number", required: false, minimum: 0 },
|
||||
},
|
||||
});
|
||||
assert.deepEqual(strict.fieldContracts.movement_state.enum, ["moving", "stopped"]);
|
||||
assert.equal(Object.isFrozen(strict.fieldContracts), true);
|
||||
assert.equal(Object.isFrozen(strict.fieldContracts.signal_state), true);
|
||||
assert.equal(Object.isFrozen(strict.fieldContracts.signal_state.enum), true);
|
||||
|
||||
assert.throws(
|
||||
() => normalizeDataProductDefinition({
|
||||
...input,
|
||||
fieldContracts: { status: { type: "string", required: true } },
|
||||
}),
|
||||
/data_product_field_contracts_must_match_fields/,
|
||||
);
|
||||
assert.throws(
|
||||
() => normalizeDataProductDefinition({
|
||||
...input,
|
||||
fieldContracts: Object.fromEntries(input.fields.map((field) => [
|
||||
field,
|
||||
field === "status"
|
||||
? { type: "string", required: true, enum: ["active", 1] }
|
||||
: { type: field === "geometry" ? "point" : "string", required: false },
|
||||
])),
|
||||
}),
|
||||
/data_product_field_contract_enum_invalid/,
|
||||
);
|
||||
assert.throws(
|
||||
() => normalizeDataProductDefinition({
|
||||
...strict,
|
||||
fieldContracts: {
|
||||
...strict.fieldContracts,
|
||||
speed_kph: { type: "number", required: false, minimum: 10, maximum: 1 },
|
||||
},
|
||||
}),
|
||||
/data_product_field_contract_range_invalid/,
|
||||
);
|
||||
|
||||
console.log("external-data-plane data product policy: ok");
|
||||
|
||||
Reference in New Issue
Block a user