فینورا پرو - سامانه جامع حسابداری و صدور فاکتور

test(A02): protect control claims, overflow, privacy and non-posting

davoodmehraban89 committed Oct 17, 2026 at 07:26 UTC 69fb7648c609711fd4515825346735e80250899c
1 file changed +92
tests/a02-holoo-delimited-export.test.mjs
+92
@@ -108,3 +108,95 @@ test('A02: reject large cells and unsupported separator without emitting source
108 assert.throws(()=>parseStrictDelimitedRows('id,name\n1,'+'z'.repeat(270000)),/CSV_CELL_TOO_LARGE/);
109 assert.throws(()=>parseStrictDelimitedRows('id|name\n1|x',{delimiter:'|'}),/CSV_UNSUPPORTED_DELIMITER/);
110 });
111 +
112 +
113 +test('A02: declared Holoo report control counts and rial totals match explicit mapped data', () => {
114 + const sample = fixture();
115 + sample.declaredControlTotals = {
116 + contacts: { count: 1, receivable: 0, payable: 0 },
117 + products: { count: 1 },
118 + invoices: { count: 1, grandTotal: 300, paidAmount: 100 },
119 + invoiceLines: { count: 1 }, cheques: { count: 1, amount: 50 }
120 + };
121 + const before = structuredClone(sample);
122 + const result = previewHolooDelimitedExport(sample);
123 + assert.equal(result.issueCount, 0, JSON.stringify(result.issues));
124 + assert.equal(result.declaredControlChecks, 10);
125 + assert.equal(result.sourceControlClaimsPresent, true);
126 + assert.equal(result.independentlyVerified, false);
127 + assert.equal(result.canCommit, false);
128 + assert.deepEqual(sample, before);
129 +});
130 +
131 +test('A02: source-report amount and row-count differences fail without leaking actual financial numbers', () => {
132 + const sample = fixture();
133 + sample.declaredControlTotals = { invoices: { count: 2, grandTotal: 97531, paidAmount: 99999 } };
134 + const result = previewHolooDelimitedExport(sample);
135 + const codes = result.issues.map(x => x.code);
136 + for (const code of ['CONTROL_COUNT_MISMATCH','CONTROL_AMOUNT_MISMATCH'])
137 + assert.ok(codes.includes(code));
138 + for (const secret of ['97531','99999','مشتری'])
139 + assert.ok(!JSON.stringify(result).includes(secret));
140 + assert.equal(result.canCommit, false);
141 + assert.equal(result.status, 'blocked');
142 +});
143 +
144 +test('A02: explicit toman source amounts are reconciled only against correctly converted rial controls', () => {
145 + const sample = fixture();
146 + sample.moneyUnit = 'toman';
147 + sample.declaredControlTotals = { invoices: { grandTotal: 3000, paidAmount: 1000 } };
148 + assert.equal(previewHolooDelimitedExport(sample).issueCount, 0);
149 + sample.declaredControlTotals.invoices.grandTotal = 300;
150 + const report = previewHolooDelimitedExport(sample);
151 + assert.ok(report.issues.some(x => x.code === 'CONTROL_AMOUNT_MISMATCH'));
152 +});
153 +
154 +test('A02: controls never claim success when their table is missing or the source amount is invalid', () => {
155 + const sample = fixture();
156 + sample.declaredControlTotals = { cheques: { count: 1 } };
157 + delete sample.tables.cheques;
158 + const missing = previewHolooDelimitedExport(sample);
159 + assert.ok(missing.issues.some(x => x.code === 'CONTROL_SOURCE_DATASET_MISSING'));
160 + sample.tables.cheques = {text:'id,amount\nQ1,N/A\n'};
161 + sample.declaredControlTotals = { cheques: { amount: 50 } };
162 + const invalid = previewHolooDelimitedExport(sample);
163 + assert.ok(invalid.issues.some(x => x.code === 'CONTROL_SOURCE_AMOUNT_INVALID'));
164 +});
165 +
166 +test('A02: large per-row safe amounts detect aggregate overflow and never silently round', () => {
167 + const sample = fixture();
168 + sample.tables.invoices.text =
169 + 'id,contact,gross,paid\nI1,C1,9007199254740990,0\nI2,C1,9007199254740990,0\n';
170 + sample.declaredControlTotals = { invoices: { grandTotal: 9007199254740990 } };
171 + const result = previewHolooDelimitedExport(sample);
172 + assert.ok(result.issues.some(x => x.code === 'CONTROL_SOURCE_SUM_OVERFLOW'));
173 +});
174 +
175 +test('A02: reject unauthorized control schema, unsafe numbers and prototype-name tables', () => {
176 + const sample = fixture();
177 + sample.declaredControlTotals = { invoices: { amount: 10 } };
178 + assert.throws(() => previewHolooDelimitedExport(sample), /CONTROL_TOTALS_SCHEMA_INVALID/);
179 + sample.declaredControlTotals = { invoices: { grandTotal: Number.MAX_SAFE_INTEGER + 1 } };
180 + assert.throws(() => previewHolooDelimitedExport(sample), /CONTROL_TOTAL_NOT_SAFE_RIAL/);
181 + sample.declaredControlTotals = { constructor: { count: 1 } };
182 + assert.throws(() => previewHolooDelimitedExport(sample), /CONTROL_TOTALS_SCHEMA_INVALID/);
183 + delete sample.declaredControlTotals;
184 + sample.tables.constructor = { text: 'id\nx\n' };
185 + assert.throws(() => previewHolooDelimitedExport(sample), /SOURCE_UNSUPPORTED_TABLE/);
186 +});
187 +
188 +test('A02: bounded combined diagnostics preserve total count without leaking raw data', () => {
189 + const sample = fixture();
190 + sample.tables.cheques.text = 'id,amount\nX,-45\n';
191 + sample.declaredControlTotals = {
192 + cheques: { count: 2, amount: 123456 },
193 + invoices: { count: 0, grandTotal: 999999 }
194 + };
195 + const result = previewHolooDelimitedExport(sample, { maxIssues: 2 });
196 + assert.equal(result.issues.length, 2);
197 + assert.equal(result.truncated, true);
198 + assert.ok(result.issueCount > 2);
199 + assert.equal(result.independentlyVerified, false);
200 + assert.ok(!JSON.stringify(result).includes('123456'));
201 + assert.ok(!JSON.stringify(result).includes('999999'));
202 +});