Unify and validate bid totals across screen and exports

This commit is contained in:
2026-09-06 13:16:49 +03:00
parent 6fd6ac04f4
commit 3096ca45cd
6 changed files with 72 additions and 8 deletions
+31
View File
@@ -34,3 +34,34 @@ test('Turkish decimal price is identical in row total and printable sheet',()=>{
for(const value of ['', '125,,50','1e3','125 TL','1.2.3','-20','125,']) assert.equal(parseBidPrice(value),null);
assert.equal(bidRowTotal({quantity:'1000000000 adet',birimFiyat:'999999999999999'}),null);
});
test('aggregate overflow is rejected across printable and workbook output',async()=>{
const {bidTotal,bidAmount}=await import('../src/services/bidValidation.js');
const {createBidWorkbook}=await import('../src/services/bidWorkbook.js');
const {teklifMektubuHtml}=await import('../src/services/bidDocs.js');
const rows=Array.from({length:3},()=>({name:'Cihaz',quantity:'1 adet',birimFiyat:40000000000000}));
assert.deepEqual(validateBidRows(rows),[]);
assert.equal(bidTotal(rows),null);
assert.throws(()=>teklifCetveliHtml({},rows,120000000000000),/sınır/);
await assert.rejects(createBidWorkbook({},rows),/sınır/);
for(const amount of ['999999999999999', '0.001', '', '-1', Infinity]) {
assert.equal(bidAmount(amount),null);
assert.throws(()=>teklifMektubuHtml({},amount),/geçersiz/);
}
assert.equal(bidAmount('125,505'),125.51);
});
test('print total must equal the common rounded row sum',async()=>{
const {bidTotal}=await import('../src/services/bidValidation.js');
const rows=Array.from({length:100},()=>({name:'Kit',quantity:'3 adet',birimFiyat:'0.335'}));
assert.equal(bidTotal(rows),101);
const {createBidWorkbook}=await import('../src/services/bidWorkbook.js');
const {default:ExcelJS}=await import('exceljs');
const workbook=new ExcelJS.Workbook();
await workbook.xlsx.load(await createBidWorkbook({},rows));
assert.equal(workbook.worksheets[0].getCell('F107').result,101);
for(let i=7;i<=106;i++) assert.equal(workbook.worksheets[0].getCell(`F${i}`).result,1.01);
assert.throws(()=>teklifCetveliHtml({},rows,100.5),/uyuşmuyor/);
assert.ok(teklifCetveliHtml({},rows,101).includes('101,00'));
assert.equal(bidTotal([{name:'Kit',quantity:'2 adet',birimFiyat:''}]),null);
});