فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
test(A03): account for newly recorded fiscal-period opening audit event
davoodmehraban89 committed
Oct 14, 2026 at 23:40 UTC
75da373c719b6ed426625b14f53cfafcbe845d36
1 file changed
+19
-18
tests/a03-audit-integration.test.mjs
+19
-18
@@ -39,25 +39,26 @@ test('A03: posting and reversal produce immutable-in-service, scoped, minimal au
39
const state = await setup();
40
const posted = await AccountingService.postJournal(journal(state));
41
let events = await AuditService.list();
42
- assert.equal(events.length, 1);
43
- assert.equal(events[0].eventType, 'journal_posted');
44
- assert.equal(events[0].actorId, 'audit-admin');
45
- assert.equal(events[0].companyId, company);
46
- assert.equal(events[0].sourceId, posted.id);
47
- assert.equal(events[0].safeSummary.lineCount, 2);
48
- assert.equal(events[0].result, 'committed');
42
+ assert.equal(events.length, 2);
43
+ const postedEvent = events.find(e => e.eventType === 'journal_posted');
44
+ assert.ok(postedEvent);
45
+ assert.equal(postedEvent.actorId, 'audit-admin');
46
+ assert.equal(postedEvent.companyId, company);
47
+ assert.equal(postedEvent.sourceId, posted.id);
48
+ assert.equal(postedEvent.safeSummary.lineCount, 2);
49
+ assert.equal(postedEvent.result, 'committed');
50
assert.ok(!JSON.stringify(events).includes('Sensitive customer name'));
51
52
const reversed = await AccountingService.reverseJournal(posted.id, {
53
periodId: state.period.id, date: '1405/07/19'
54
});
55
events = await AuditService.list();
55
- assert.equal(events.length, 2);
56
+ assert.equal(events.length, 3);
57
assert.ok(events.some(e => e.eventType === 'journal_reversed' && e.sourceId === reversed.id));
58
await assert.rejects(AccountingService.reverseJournal(posted.id, {
59
periodId: state.period.id, date: '1405/07/20'
60
}), /قابل برگشت/);
60
- assert.equal((await AuditService.list()).length, 2);
61
+ assert.equal((await AuditService.list()).length, 3);
62
63
CompanyService.activeCompanyId = 'audit-c2';
64
assert.deepEqual(await AuditService.list(), []);
@@ -78,17 +79,17 @@ test('A03: duplicate audit command aborts unrelated financial writes atomically'
79
await AuditService.append(tx, event);
80
}));
81
assert.equal(await StorageService.get('products', 'never-written'), undefined);
81
- assert.equal((await AuditService.list()).length, 1);
82
+ assert.equal((await AuditService.list()).length, 2);
83
});
84
85
test('A03: fiscal closing appends an event and does not permit double close', async () => {
86
const { period } = await setup();
87
await AccountingService.closePeriod(period.id);
88
const events = await AuditService.list();
88
- assert.equal(events.length, 1);
89
- assert.equal(events[0].eventType, 'period_closed');
89
+ assert.equal(events.length, 2);
90
+ assert.ok(events.some(e => e.eventType === 'period_closed'));
91
await assert.rejects(AccountingService.closePeriod(period.id), /بسته/);
91
- assert.equal((await AuditService.list()).length, 1);
92
+ assert.equal((await AuditService.list()).length, 2);
93
});
94
95
test('A03: company backup includes audit store, without ever exporting user credentials', async () => {
@@ -96,17 +97,17 @@ test('A03: company backup includes audit store, without ever exporting user cred
97
await AccountingService.postJournal(journal(state));
98
const backup = await StorageService.exportAll();
99
assert.equal(backup.version, 7);
99
- assert.equal(backup.data.audit_events.length, 1);
100
+ assert.equal(backup.data.audit_events.length, 2);
101
assert.ok(Array.isArray(backup.data.document_corrections));
101
- assert.equal(backup.data.audit_events[0].safeSummary.lineCount, 2);
102
+ assert.equal(backup.data.audit_events.find(x => x.eventType === 'journal_posted').safeSummary.lineCount, 2);
103
});
104
105
test('A03: company backup rejects tampered historical audit records even in replace mode', async () => {
106
const state = await setup();
107
await AccountingService.postJournal(journal(state));
108
const backup = await SettingsController.exportBackup();
108
- assert.equal(backup.data.audit_events.length, 1);
109
- backup.data.audit_events[0].eventType = 'period_closed';
109
+ assert.equal(backup.data.audit_events.length, 2);
110
+ backup.data.audit_events.find(x => x.eventType === 'journal_posted').eventType = 'period_closed';
111
await assert.rejects(SettingsController.importBackup(backup, { mode: 'replace' }), /بازنویسی سابقه/);
111
- assert.equal((await AuditService.list())[0].eventType, 'journal_posted');
112
+ assert.ok((await AuditService.list()).some(e => e.eventType === 'journal_posted'));
113
});