Files
MikrotikManager/lib/evobgp-catalog.test.ts
T

18 lines
1.4 KiB
TypeScript

import assert from "node:assert/strict"
import { test } from "node:test"
import { parseEvoBgpCatalog } from "./evobgp-catalog"
const empty = { fetchedAt: "2026-10-01T00:00:00Z", modules: [], domains: [], ipRanges: [], asns: [], communities: [] }
const domain = { id: "domain-1", domain: "example.test", resolvedIp: "—", asn: "—", purpose: "", filter: "", updated: "—", enabled: false }
test("known empty and false stay explicit without invented rows", () => {
assert.deepEqual(parseEvoBgpCatalog(empty), empty)
assert.equal(parseEvoBgpCatalog({ ...empty, domains: [domain] }).domains[0].enabled, false)
})
test("malformed or partial catalogue never reaches consumers as a snapshot", () => {
for (const raw of [{}, null, { ...empty, domains: undefined }, { ...empty, asns: {} }, { ...empty, fetchedAt: "bad" }, { ...empty, domains: [null] }, { ...empty, domains: [{ ...domain, enabled: undefined }] }, { ...empty, domains: [domain, domain] }]) assert.throws(() => parseEvoBgpCatalog(raw), /Каталог Evolution не подтверждён/)
})
test("ASN and community zero counts are preserved, invalid counts rejected", () => {
const asn = { id: "asn-1", asn: "AS1", org: "", country: "", prefixes: 0, filter: "", updated: "—", enabled: false }
assert.equal(parseEvoBgpCatalog({ ...empty, asns: [asn] }).asns[0].prefixes, 0)
assert.throws(() => parseEvoBgpCatalog({ ...empty, asns: [{ ...asn, prefixes: -1 }] }))
})