Files
ihaleist/tests/list-dates.test.mjs

34 lines
2.2 KiB
JavaScript
Raw Permalink 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 { acikIhale, compareTenderDeadlines, ihaleGunu, compareTenderPublications, publicationInfo, bugunEklendi } from '../src/services/ihaleTarih.js';
test('publication sorting ignores arbitrary ids and handles Istanbul day boundaries',()=>{
const rows=[{id:'zzz',ilanTarihi:'05.09.2026'}, {id:1,yayinZamani:'2026-09-05T22:00:00Z'},
{id:'aaa',yayinZamani:'2026-09-06T09:00:00'}, {id:'unknown'}];
assert.deepEqual([...rows].sort(compareTenderPublications).map(t=>t.id),['aaa',1,'zzz','unknown']);
assert.deepEqual(publicationInfo(rows[1]),{dateKey:'2026-09-06',timestamp:Date.parse('2026-09-05T22:00:00Z')});
assert.equal(publicationInfo(rows[2]).timestamp,Date.parse('2026-09-06T06:00:00Z'));
assert.equal(publicationInfo({ilanTarihi:'2026-02-31'}).dateKey,null);
assert.equal(publicationInfo({yayinZamani:'2026-09-06T25:00:00',ilanTarihi:'05.09.2026'}).dateKey,'2026-09-05');
assert.equal(bugunEklendi({ilanTarihi:'05.09.2026',isYeni:true},new Date('2026-09-06T09:00:00Z')),false);
});
test('list date sorting crosses month/year boundaries and leaves unknown dates last',()=>{
const rows=[
{id:'oct',tarih:'01.10.2026',saat:'09:00'},
{id:'sep-late',tarih:'30.09.2026',saat:'14:00'},
{id:'sep-early',tarih:'30.09.2026',saat:'09:00'},
{id:'year',tarih:'01.01.2027',saat:'09:00'},
{id:'unknown',tarih:''},
];
assert.deepEqual([...rows].sort(compareTenderDeadlines).map(t=>t.id),['sep-early','sep-late','oct','year','unknown']);
assert.deepEqual([...rows].sort((a,b)=>compareTenderDeadlines(a,b,-1)).map(t=>t.id),['year','oct','sep-late','sep-early','unknown']);
assert.equal(ihaleGunu('31.09.2026'),null);
});
test('open list closes at exact deadline but never invents an unknown time',()=>{
const t={tarih:'06.09.2026',saat:'10:00'};
assert.equal(acikIhale(t,new Date('2026-09-06T06:59:59Z')),true);
assert.equal(acikIhale(t,new Date('2026-09-06T07:00:00Z')),false);
assert.equal(acikIhale({...t,saat:''},new Date('2026-09-06T20:59:59Z')),true);
assert.equal(acikIhale({...t,saat:''},new Date('2026-09-06T21:00:00Z')),false);
for(const durum of ['İptal','Sonuçlandı','Sözleşme İmzalandı']) assert.equal(acikIhale({...t,durum},new Date('2026-09-05')),false);
});