Files
MikrotikManager/backend/src/utils/server-id.test.ts
T

6 lines
600 B
TypeScript

import assert from "node:assert/strict"
import { parseDbServerId } from "./server-id.js"
for (const id of [1, "1", "001", " 1 ", 2147483648, "2147483648", Number.MAX_SAFE_INTEGER, String(Number.MAX_SAFE_INTEGER)]) assert.equal(parseDbServerId(id), Number(id))
for (const id of [undefined, null, false, {}, "", "srv1", "1abc", "1.5", "1e3", "-1", "0", NaN, Infinity, "9007199254740992", "9007199254740993", 9007199254740992, "9223372036854775807"]) assert.equal(parseDbServerId(id), null)
console.log("server-id: bigint/safe integer IDs preserved; malformed and unsafe IDs rejected without rounding")