فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
test(A03): positive metadata and negative atomic rollback regressions
davoodmehraban89 committed
Oct 19, 2026 at 18:27 UTC
80c6e01257873f4b9932a824384269b5f8a3b654
1 file changed
+29
tests/a03-audit-integration.test.mjs
+29
@@ -193,3 +193,32 @@ test('A03: standalone storage cannot forge audit or correction history', async (
193
}
194
assert.deepEqual(await AuditService.list(), before);
195
});
196
+
197
+test('A03: invalid audit metadata aborts business writes without leaking payloads', async () => {
198
+ await setup();
199
+ const before = (await AuditService.list()).length;
200
+ for (const businessDate of [{ secret: 'customer phone' }, 'customer-name', '1405/07/18 extra']) {
201
+ const id = StorageService.uid('rejected_');
202
+ await assert.rejects(StorageService.transaction(['audit_events', 'products'], async tx => {
203
+ await tx.add('products', { id, companyId: company, name: 'rollback' });
204
+ await AuditService.append(tx, {
205
+ companyId: company, eventType: 'journal_posted', sourceType: 'journal',
206
+ sourceId: id, commandKey: id, businessDate
207
+ });
208
+ }), /نامعتبر/);
209
+ assert.equal(await StorageService.get('products', id), undefined);
210
+ }
211
+ assert.equal((await AuditService.list()).length, before);
212
+});
213
+
214
+test('A03: valid audit date is retained and cannot be overwritten', async () => {
215
+ await setup();
216
+ const commandKey = StorageService.uid('valid_');
217
+ const event = { companyId: company, eventType: 'journal_posted',
218
+ sourceType: 'journal', sourceId: commandKey, commandKey, businessDate };
219
+ await StorageService.transaction('audit_events', tx => AuditService.append(tx, event));
220
+ const saved = (await AuditService.list()).find(x => x.sourceId === commandKey);
221
+ assert.equal(saved.businessDate, businessDate);
222
+ await assert.rejects(StorageService.transaction('audit_events', tx => AuditService.append(tx, event)));
223
+ assert.equal((await AuditService.list()).filter(x => x.sourceId === commandKey).length, 1);
224
+});