Files
MikrotikManager/backend/src/services/complete-count.test.ts
T

15 lines
1.3 KiB
TypeScript

import assert from "node:assert/strict"
import {test} from "node:test"
import {boundedCompleteCount,completeCollectionCount,completeContainerCount} from "./complete-count.js"
test("complete counts distinguish known zero, partial and missing failure metadata",()=>{
assert.equal(completeCollectionCount({rows:[],failures:[]},"rows"),0)
for(const raw of [{rows:[]},{rows:[],failures:[{}]},{rows:null,failures:[]}])assert.equal(completeCollectionCount(raw,"rows"),undefined)
assert.equal(completeContainerCount({servers:[]}),0);assert.equal(completeContainerCount({servers:[{availability:"available",containers:[{}],failures:[{resource:"envs"}]}]}),1)
for(const availability of ["unsupported","error"])assert.equal(completeContainerCount({servers:[{availability,containers:[],failures:[]}]}),undefined)
})
test("bounded reader omits thrown, malformed and timed out counts without publishing late success",async()=>{
assert.equal(await boundedCompleteCount(async()=>0,x=>x),0);assert.equal(await boundedCompleteCount(async()=>{throw Error("offline")},x=>x),undefined)
for(const value of [-1,NaN,Infinity,1.5])assert.equal(await boundedCompleteCount(async()=>value,x=>x),undefined)
let release!:(value:number)=>void;const gate=new Promise<number>(resolve=>release=resolve);assert.equal(await boundedCompleteCount(()=>gate,x=>x,5),undefined);release(9)
})