Files
ihaleist/tests/bid-workbook.test.mjs

25 lines
1.7 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 ExcelJS from 'exceljs';
import {createBidWorkbook} from '../src/services/bidWorkbook.js';
import {teklifCetveliHtml} from '../src/services/bidDocs.js';
test('real XLSX roundtrip preserves 100 Turkish rows, numeric decimals and matching total',async()=>{
const rows=Array.from({length:100},(_,i)=>({name:i===0?'=1+2':`Ölçüm kiti ${i}`,quantity:'2 adet',birimFiyat:'125,50'}));
const buffer=await createBidWorkbook({ikn:'2026/QA',firmaUnvan:'İğdır Test',kisim:'1'},rows);
const read=new ExcelJS.Workbook();await read.xlsx.load(buffer);const sheet=read.getWorksheet('Teklif Cetveli');
assert.equal(sheet.rowCount,107);assert.equal(sheet.getCell('B3').value,'İğdır Test');
assert.equal(sheet.getCell('B7').type,ExcelJS.ValueType.String);assert.equal(sheet.getCell('B7').value,'=1+2');
assert.equal(sheet.getCell('E7').value,125.5);assert.equal(sheet.getCell('F7').result,251);
assert.equal(sheet.getCell('F107').result,25100);assert.equal(sheet.getCell('B106').value,'Ölçüm kiti 99');
assert.ok(teklifCetveliHtml({},rows,25100).includes('25.100,00'));
assert.equal(sheet.pageSetup.printTitlesRow,'1:6');
});
test('XLSX refuses empty and invalid prices; fractional unit precision is preserved',async()=>{
await assert.rejects(createBidWorkbook({},[]));
const row={name:'Kit',quantity:'3 adet',birimFiyat:'0,335'};
const book=new ExcelJS.Workbook();await book.xlsx.load(await createBidWorkbook({},[row]));
assert.equal(book.worksheets[0].getCell('E7').value,0.335);
assert.equal(book.worksheets[0].getCell('F7').result,1.01);
assert.ok(teklifCetveliHtml({},[row],1.01).includes('0,335'));
});