Files
MikrotikManager/backend/scripts/writer-profile/fixed58-build-definition.test.mts
T

26 lines
1.7 KiB
TypeScript

import assert from "node:assert/strict"
import { test } from "node:test"
import { sorted } from "./catalogue-projection.js"
import { FIXED57_ROLE_TEMPLATE } from "./fixed57-build-definition.js"
import { FIXED58_ROLE_TEMPLATE, normalizeFixed58RestoreRows } from "./fixed58-build-definition.js"
test("source58 accepts only the reviewed dump layouts and leaves raw catalogue data intact", () => {
const relation = "server_probe_executions"
const reviewed = FIXED57_ROLE_TEMPLATE.columns.filter(row => row.relname === relation)
const compact = reviewed.map(row => typeof row.attnum === "number" && row.attnum > 18 ? { ...row, attnum: row.attnum - 1 } : row)
assert.deepEqual(normalizeFixed58RestoreRows(relation, "columns", compact), sorted(reviewed))
assert(compact.some(row => row.attnum === 18))
const moved = compact.map(row => row.attnum === 18 ? { ...row, attnum: 16 } : row)
assert.notDeepEqual(normalizeFixed58RestoreRows(relation, "columns", moved), sorted(reviewed))
const checks = FIXED58_ROLE_TEMPLATE.restorePortable.filter(row => typeof row.conname === "string")
assert.equal(checks.length, 3)
for (const check of checks) {
const original = FIXED57_ROLE_TEMPLATE.constraints.find(row => row.relname === check.relname && row.conname === check.conname)!
const restored = { ...original, definition: check.definition }
assert.deepEqual(normalizeFixed58RestoreRows(String(check.relname), "constraints", [restored]), [original])
assert.equal(restored.definition, check.definition)
const weakened = { ...restored, definition: "CHECK (true)" }
assert.deepEqual(normalizeFixed58RestoreRows(String(check.relname), "constraints", [weakened]), [weakened])
}
})