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

test(A03): restore real legacy v6 company backup envelope

davoodmehraban89 committed Oct 20, 2026 at 08:42 UTC 51cc5fc571909dfc87240a7cbe836950462802dc
1 file changed +20
tests/a03-audit-integration.test.mjs
+20
@@ -272,3 +272,23 @@ test('A03: direct historical restore without authorization is rejected', async (
272 })), /بازیابی مستقیم ممیزی/);
273 assert.equal(await StorageService.get('audit_events', 'forged-restore'), undefined);
274 });
275 +
276 +
277 +test('A03: legacy v6 company backup without audit hashes is migrated', async () => {
278 + await StorageService.clearAll();
279 + Auth.currentUser = { id: 'audit-admin', role: 'admin', username: 'manager' };
280 + await StorageService.put('companies', { id: company, name: 'Legacy company' });
281 + CompanyService.activeCompanyId = company;
282 + const legacy = {
283 + app: 'Factor-easyPro', version: '2.0.0', scope: 'company',
284 + companyId: company, schemaVersion: 6,
285 + data: { audit_events: [{ id: 'legacy-audit', companyId: company,
286 + eventType: 'journal_posted', commandKey: company + ':legacy-journal' }] }
287 + };
288 + await SettingsController.importBackup(legacy);
289 + const restored = await StorageService.get('audit_events', 'legacy-audit');
290 + assert.equal(restored.actorId, 'legacy-unknown');
291 + assert.equal(restored.sourceType, 'legacy');
292 + assert.match(restored.eventHash, /^[0-9a-f]{64}$/);
293 + assert.equal((await AuditService.verifyChain()).valid, true);
294 +});