Files
MikrotikManager/lib/probe-schedule-response.test.ts
T

7 lines
1010 B
TypeScript

import assert from "node:assert/strict"
import {test} from "node:test"
import {readProbeSchedule} from "./probe-schedule-response"
export const probe={id:"probe-fixture",srcServerId:"1",dstServerId:"2",srcInterface:"",dstInterface:"",protocol:"tcp",direction:"both",durationSec:"10",enabled:true,lastRunAt:null,lastTxAvgMbps:0,lastRxAvgMbps:null,lastStatus:"done",lastError:null}
test("probe schedule keeps confirmed empty and nullable metrics distinct",()=>{assert.deepEqual(readProbeSchedule({probes:[]}),[]);assert.equal(readProbeSchedule({probes:[probe]})[0].lastRxAvgMbps,null);assert.equal(readProbeSchedule({probes:[probe]})[0].lastTxAvgMbps,0)})
test("probe schedule rejects incomplete/duplicate/malformed rows",()=>{for(const raw of [{},{probes:null},{probes:[{}]},{probes:[probe,probe]},{probes:[{...probe,enabled:"yes"}]},{probes:[{...probe,lastRxAvgMbps:-1}]},{probes:[{...probe,lastStatus:"unknown-status"}]},{probes:[{...probe,lastRunAt:"bad-date"}]}])assert.throws(()=>readProbeSchedule(raw))})