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

test(A05): verify draft journal and simultaneous fiscal-close idempotency

davoodmehraban89 committed Oct 16, 2026 at 23:44 UTC 36ab7a6e41f2ecce68425fa87f6676d8f5aea070
1 file changed +32
tests/a05-fiscal-close-gates.test.mjs
+32
@@ -61,3 +61,35 @@ test('A05: an open stocktake blocks period close without changing the period', a
61 await AccountingService.closePeriod(period.id);
62 await assert.rejects(AccountingService.closePeriod(period.id), /بسته/);
63 });
64 +
65 +test('A05: an unfinished journal blocks closing until the draft is removed', async () => {
66 + const { period } = await setup();
67 + const draftId = 'a05-unposted-ledger-draft';
68 + await StorageService.put('journal_entries', {
69 + id: draftId, companyId: 'a05', periodId: period.id,
70 + date: '1405/06/15', status: 'draft', sourceType: 'manual'
71 + });
72 + await assert.rejects(AccountingService.closePeriod(period.id), /اسناد پیش‌نویس/);
73 + assert.equal((await StorageService.get('fiscal_periods', period.id)).closed, false);
74 + assert.equal((await AuditService.list()).filter(x => x.eventType === 'period_closed').length, 0);
75 + await StorageService.delete('journal_entries', draftId);
76 + await AccountingService.closePeriod(period.id);
77 + assert.equal((await StorageService.get('fiscal_periods', period.id)).closed, true);
78 +});
79 +
80 +test('A05: simultaneous close commands commit only one period and one audit receipt', async () => {
81 + const { period } = await setup();
82 + const attempts = await Promise.allSettled([
83 + AccountingService.closePeriod(period.id),
84 + AccountingService.closePeriod(period.id)
85 + ]);
86 + assert.equal(attempts.filter(x => x.status === 'fulfilled').length, 1);
87 + assert.equal(attempts.filter(x => x.status === 'rejected').length, 1);
88 + assert.equal((await StorageService.get('fiscal_periods', period.id)).closed, true);
89 + const events = (await AuditService.list()).filter(x =>
90 + x.eventType === 'period_closed' && x.sourceId === period.id);
91 + assert.equal(events.length, 1);
92 + await assert.rejects(AccountingService.closePeriod(period.id), /بسته/);
93 + assert.equal((await AuditService.list()).filter(x =>
94 + x.eventType === 'period_closed' && x.sourceId === period.id).length, 1);
95 +});