Files
NODEDC_DEVICE_CORE/services/device-control-core/test/ontology-migration.test.mjs
T

57 lines
1.9 KiB
JavaScript

import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import test from "node:test";
const migrationUrl = new URL(
"../migrations/016_device_asset_infrastructure_ontology.sql",
import.meta.url,
);
const repositoryUrl = new URL("../src/postgres-repository.mjs", import.meta.url);
test("ontology migration is additive and encodes the official entity identifiers", async () => {
const sql = await readFile(migrationUrl, "utf8");
for (const table of [
"device_assets",
"device_asset_bindings",
"device_infrastructure_hosts",
"device_infrastructure_deployments",
"device_infrastructure_service_instances",
"device_health_observations",
]) {
assert.match(sql, new RegExp(`create table if not exists ${table}`, "i"));
}
for (const entityId of [
"asset.asset",
"device.asset_binding",
"infrastructure.host",
"infrastructure.deployment",
"infrastructure.service_instance",
"observation.health_observation",
]) {
assert.equal(sql.includes(`'${entityId}'`), true);
}
assert.equal(sql.includes("229c61c02a790906"), true);
for (const commandKind of [
"asset.ensure",
"asset_binding.ensure",
"asset_binding.close",
"infrastructure_host.ensure",
"infrastructure_endpoint.ensure",
"infrastructure_deployment.ensure",
"infrastructure_service_instance.ensure",
"health_observation.record",
]) {
assert.equal(sql.includes(`'${commandKind}'`), true);
}
assert.doesNotMatch(sql, /insert\s+into\s+device_(?:assets|infrastructure_hosts)/i);
assert.doesNotMatch(sql, /gelios|arusnavi|beget|hetzner|aws/i);
});
test("ontology migration follows integration identity", async () => {
const source = await readFile(repositoryUrl, "utf8");
assert.ok(
source.indexOf("015_device_integration_identity.sql")
< source.indexOf("016_device_asset_infrastructure_ontology.sql"),
);
});