Files
MikrotikManager/backend/src/services/gre-catalog-poll.test.ts
T

18 lines
1.2 KiB
TypeScript

import assert from "node:assert/strict"
import { pollGreCatalog } from "./gre-catalog-poll.js"
const devices = [{ id: 1, name: "Первый" }, { id: 2, name: "Второй" }]
const mixed = await pollGreCatalog(devices, async device => {
if (device.id === 2) throw new Error("Таймаут тест")
return { tunnels: [{ id: "*1", serverId: "1" }] }
})
assert.deepEqual(mixed, { tunnels: [{ id: "*1", serverId: "1" }], failures: [{ serverId: "2", serverName: "Второй", error: "Таймаут тест" }] })
assert.deepEqual(await pollGreCatalog(devices, async () => ({ tunnels: [] })), { tunnels: [], failures: [] })
const failed = await pollGreCatalog(devices, async () => { throw new Error("Недоступно") })
assert.equal(failed.tunnels.length, 0)
assert.deepEqual(failed.failures.map(f => f.serverId), ["1", "2"])
const foreign = await pollGreCatalog([devices[0]], async () => ({ tunnels: [{ serverId: "2" }] }))
assert.equal(foreign.tunnels.length, 0)
assert.equal(foreign.failures[0].serverId, "1")
assert.deepEqual(await pollGreCatalog([], async () => { throw new Error("Не должен вызываться") }), { tunnels: [], failures: [] })
console.log("gre catalog: partial/empty/failed/foreign contexts passed")