14 lines
1.3 KiB
TypeScript
14 lines
1.3 KiB
TypeScript
import assert from "node:assert/strict"
|
|
import {test} from "node:test"
|
|
import {parseDashboardServers,parseDashboardProbes} from "./dashboard-readers"
|
|
const server={id:1,name:"Узел",host:"192.0.2.1",site:"TEST",country:"RU",asn:"64512",type:"exit-node",enabled:true,status:null,latency:null,os:null,model:null,sessions:0}
|
|
const probe={id:"p1",srcServerId:"1",name:"Проверка",target:"192.0.2.2",filter:"main",rtt:null,loss:100,status:"down",series:[],enabled:true,showOnDashboard:true}
|
|
test("dashboard server catalog validates identities and keeps unknown status",()=>{
|
|
assert.equal(parseDashboardServers([server])[0].status,null);assert.deepEqual(parseDashboardServers([]),[])
|
|
for(const raw of [{},[server,server],[{...server,status:"invalid"}],[{...server,latency:-1}],[{...server,id:0}],[{id:1}]])assert.throws(()=>parseDashboardServers(raw))
|
|
})
|
|
test("dashboard probes validate real shape, uniqueness and numeric ranges before publication",()=>{
|
|
assert.equal(parseDashboardProbes({probes:[probe]}).probes[0].rtt,null);assert.deepEqual(parseDashboardProbes({probes:[]}),{probes:[],sampledAt:null})
|
|
for(const raw of [{},{probes:[probe,probe]},{probes:[{...probe,loss:101}]},{probes:[{...probe,status:"invalid"}]},{probes:[{...probe,series:[null]}]},{probes:[{}]}])assert.throws(()=>parseDashboardProbes(raw))
|
|
})
|