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

test(A03): verify draft lifecycle audit and failure rollback

davoodmehraban89 committed Oct 14, 2026 at 23:41 UTC ac6c968075ea56eaf10340d5fc3bde3e8a465824
1 file changed +36
tests/a03-audit-integration.test.mjs
+36
@@ -111,3 +111,39 @@ test('A03: company backup rejects tampered historical audit records even in repl
111 await assert.rejects(SettingsController.importBackup(backup, { mode: 'replace' }), /بازنویسی سابقه/);
112 assert.ok((await AuditService.list()).some(e => e.eventType === 'journal_posted'));
113 });
114 +
115 +test('A03: draft journal creation, editing, posting and discarding are audited atomically', async () => {
116 + const state = await setup();
117 + const draft = await AccountingService.saveDraftJournal({
118 + periodId: state.period.id, date: businessDate,
119 + lines: [{ accountId: state.cash.id, debit: 1000, credit: 0 }]
120 + });
121 + await AccountingService.updateDraftJournal(draft.id, {
122 + periodId: state.period.id, date: businessDate,
123 + lines: [
124 + { accountId: state.cash.id, debit: 1000, credit: 0 },
125 + { accountId: state.sales.id, debit: 0, credit: 1000 }
126 + ]
127 + });
128 + const beforeFailure = (await AuditService.list()).length;
129 + await assert.rejects(AccountingService.updateDraftJournal(draft.id, {
130 + periodId: state.period.id, date: businessDate,
131 + lines: [
132 + { accountId: state.cash.id, debit: 1000, credit: 0 },
133 + { accountId: state.sales.id, debit: 0, credit: 999 }
134 + ]
135 + }, { post: true }), /تراز نیست/);
136 + assert.equal((await AuditService.list()).length, beforeFailure,
137 + 'A failed transaction must not persist a success audit event');
138 + await AccountingService.postDraftJournal(draft.id);
139 + const unused = await AccountingService.saveDraftJournal({
140 + periodId: state.period.id, date: businessDate,
141 + lines: [{ accountId: state.cash.id, debit: 4, credit: 0 }]
142 + });
143 + await AccountingService.discardDraftJournal(unused.id);
144 + const eventTypes = (await AuditService.list()).map(e => e.eventType);
145 + for (const type of ['period_opened', 'draft_created', 'draft_updated',
146 + 'draft_posted', 'draft_discarded']) {
147 + assert.ok(eventTypes.includes(type), type);
148 + }
149 +});