Files
MikrotikManager/shared/api/backend-health.test.ts
T

6 lines
1.1 KiB
TypeScript

import assert from "node:assert/strict"
import {test} from "node:test"
import {confirmBackendHealth,getBackendHealth} from "./backend-health"
test("health confirms actual status ok and legacy literal ok true only",()=>{for(const value of [{status:"ok",timestamp:"2026-10-03"},{ok:true}])assert.doesNotThrow(()=>confirmBackendHealth(value));for(const value of [null,{},[],{ok:false},{ok:"true"},{status:"error"},"ok"])assert.throws(()=>confirmBackendHealth(value),/не подтверждена/)})
test("HTTP success alone cannot confirm backend, signals and no retries are preserved",async()=>{const original=globalThis.fetch;let calls=0;try{const controller=new AbortController();globalThis.fetch=async(_url,init)=>{calls++;assert.equal(init?.signal instanceof AbortSignal,true);return new Response("<html>proxy</html>",{status:200})};await assert.rejects(()=>getBackendHealth("https://backend.test",controller.signal));assert.equal(calls,1);globalThis.fetch=async()=>{calls++;return Response.json({status:"ok"})};await getBackendHealth("https://backend.test");assert.equal(calls,2)}finally{globalThis.fetch=original}})