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

test(A01): exercise return credit conservation at max safe rial

davoodmehraban89 committed Oct 19, 2026 at 01:57 UTC ee488fdc9aead8e26fcb86e006878de793dc1459
1 file changed +22
tests/return-settlement-preview.test.mjs
+22
@@ -72,3 +72,25 @@ test('A01 preview: invariant across varied safe integer rial inputs', () => {
72 }
73 }
74 });
75 +
76 +test('A01 preview: exact safe-integer boundary retains credit conservation', () => {
77 + const max = Number.MAX_SAFE_INTEGER;
78 + const cases = [
79 + { invoiceTotal: max, paidAmount: max, priorReturns: max - 1, returnAmount: 1 },
80 + { invoiceTotal: max, paidAmount: max - 1, priorReturns: 0, returnAmount: max },
81 + { invoiceTotal: max, paidAmount: 0, priorReturns: max - 1, returnAmount: 1 },
82 + { invoiceTotal: max, paidAmount: max, priorReturns: 0, returnAmount: max }
83 + ];
84 + for (const input of cases) {
85 + const result = preview(input);
86 + for (const [key, value] of Object.entries(result)) {
87 + if (typeof value === 'number') {
88 + assert.ok(Number.isSafeInteger(value), key + ' must remain an exact rial amount');
89 + assert.ok(value >= 0, key + ' must be nonnegative');
90 + }
91 + }
92 + assert.equal(result.customerCreditAfter - result.priorCustomerCredit, result.newCustomerCredit);
93 + assert.equal(result.receivableAfter - result.customerCreditAfter, result.invoiceNetAfter - input.paidAmount);
94 + assert.equal(result.autoRefundAllowed, false);
95 + }
96 +});