fix: exclude closed tenders from upcoming feeds
This commit is contained in:
@@ -3,6 +3,7 @@ import assert from 'node:assert/strict';
|
||||
import { mkdtempSync, rmSync } from 'node:fs';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
import { tenderSnapshot } from '../src/services/tenderState.js';
|
||||
|
||||
const dir = mkdtempSync(join(tmpdir(), 'ihaleist-feed-'));
|
||||
process.env.IHALEIST_USER_DATA_DIR = dir;
|
||||
@@ -63,3 +64,28 @@ test('weekly notification schedule starts at Monday 08:00 Istanbul', () => {
|
||||
assert.equal(briefScheduleKey(new Date('2026-09-07T20:59:59Z')), '2026-8-7');
|
||||
assert.equal(briefScheduleKey(new Date('2026-09-07T21:00:00Z')), null);
|
||||
});
|
||||
|
||||
|
||||
test('closed tenders stay out of open feeds and weekly upcoming items, including saved snapshots', () => {
|
||||
const owner = 'closed-feed@example.test';
|
||||
const base = { tarih:'07.09.2026', saat:'10:00' };
|
||||
const closed = ['İptal', 'Sonuçlandı', 'Sözleşme İmzalandı'].map((durum, i) =>
|
||||
({ ...base, id:`closed-${i}`, ikn:`2026/closed-${i}`, durum }));
|
||||
closed.push({ ...base, id:'winner', ikn:'2026/winner', kazananFirma:'Test kazananı' });
|
||||
const open = { ...base, id:'open', ikn:'2026/open', durum:'Açık' };
|
||||
const unknownTime = { ...open, id:'unknown-time', ikn:'2026/unknown-time', saat:'' };
|
||||
const all = [...closed, open, unknownTime];
|
||||
for (const tender of all) store.saveTenderState(owner, tender.ikn, { takipte:true }, tenderSnapshot(tender), 0);
|
||||
assert.deepEqual(ihaleFiltrele(all, {}, now).map(t => t.id), ['open', 'unknown-time']);
|
||||
assert.equal(ihaleFiltrele(all, { sadeceAcik:false }, now).length, all.length);
|
||||
// Status updates in the current source must override a previously open saved snapshot.
|
||||
const updated = { ...open, durum:'İptal' };
|
||||
const upcoming = yaklasanIhaleler(owner, [updated, unknownTime], 14, now);
|
||||
assert.deepEqual(upcoming.map(t => t.ikn), ['2026/unknown-time']);
|
||||
assert.equal(upcoming[0].saat_dogrulanmali, true);
|
||||
for (const output of [briefMetni, briefHtml]) {
|
||||
const body = output({ hafta:'Test haftası', yaklasan:upcoming, sonuclar:[] });
|
||||
for (const tender of [...closed, open]) assert.ok(!body.includes(tender.ikn));
|
||||
assert.match(body, /saat doğrulanmalı/);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user