Files
ihaleist/tests/shared-items.test.mjs
T

26 lines
1.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import {test} from 'node:test';
import assert from 'node:assert/strict';
import {kalemleriGetir} from '../src/services/kalem.js';
test('empty shared inventory is distinct from HTTP errors and malformed responses',async()=>{
const original=globalThis.fetch;
try {
globalThis.fetch=async()=>Response.json({success:true,kalemler:[]});
assert.deepEqual((await kalemleriGetir('2026/123')).kalemler,[]);
for(const response of [Response.json({success:true,kalemler:[]},{status:503}),Response.json({success:true}),new Response('Bad gateway')]) {
globalThis.fetch=async()=>response;await assert.rejects(kalemleriGetir('2026/123'),/alınamadı/);
}
} finally {globalThis.fetch=original;}
});
test('shared inventory waits are bounded and can be cancelled on tender change',async()=>{
const original=globalThis.fetch;
try {
globalThis.fetch=async(url,{signal})=>new Promise((resolve,reject)=>{
const cancel=()=>reject(new DOMException('Aborted','AbortError'));
if(signal.aborted)cancel();else signal.addEventListener('abort',cancel,{once:true});
});
await assert.rejects(kalemleriGetir('2026/123',{timeoutMs:5}),/zaman aşımı/);
const c=new AbortController();const pending=kalemleriGetir('2026/123',{signal:c.signal});c.abort();
await assert.rejects(pending,{name:'AbortError'});
} finally {globalThis.fetch=original;}
});