feat: prepare bids by official lot selection

This commit is contained in:
2026-09-06 08:52:07 +03:00
parent 311344306b
commit 0d332afdb1
6 changed files with 162 additions and 13 deletions
+21
View File
@@ -0,0 +1,21 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import {selectBidLots} from '../src/services/bidLots.js';
import {bidRowTotal} from '../src/services/bidValidation.js';
import {teklifCetveliHtml} from '../src/services/bidDocs.js';
const rows=[{priceKey:'a',name:'Kit A',kisim:'1',quantity:'2 adet',birimFiyat:10},{priceKey:'b',name:'Kit B',kisim:'1',quantity:'3 adet',birimFiyat:20},{priceKey:'c',name:'Cihaz C',kisim:'2',quantity:'1 adet',birimFiyat:1000}];
test('partial bid includes all selected-lot rows and excludes others from price and output',()=>{
const selected=selectBidLots(rows,{enabled:true,source:'İdari 19',selected:['1']});
assert.deepEqual(selected.errors,[]);assert.equal(selected.rows.length,2);
const total=selected.rows.reduce((sum,r)=>sum+bidRowTotal(r),0);assert.equal(total,80);
const html=teklifCetveliHtml({kisim:'1'},selected.rows,total);
assert.ok(html.includes('Kit A'));assert.ok(html.includes('Kit B'));assert.ok(!html.includes('Cihaz C'));
assert.equal(selectBidLots(rows,{enabled:false}).rows.length,3);
});
test('unknown grouping, source permission and obsolete selected lots prevent readiness',()=>{
assert.ok(selectBidLots(rows,{enabled:true,selected:['1']}).errors.length);
assert.ok(selectBidLots([{...rows[0],kisim:null}],{enabled:true,source:'19',selected:['1']}).errors.length);
assert.ok(selectBidLots(rows,{enabled:true,source:'19',selected:['3']}).errors.length);
const result=selectBidLots([{...rows[0],kisim:null}],{enabled:true,source:'19',selected:['1'],assignments:{a:'1'}});
assert.deepEqual(result.errors,[]);assert.equal(result.rows.length,1);
});