فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
test(A03): prove v6 to v7 additive migration preserves records
davoodmehraban89 committed
Oct 14, 2026 at 23:25 UTC
e394505091d58bc8702bedbfee163f1e9204e0c8
1 file changed
+36
tests/a03-v7-migration.test.mjs
new
+36
@@ -0,0 +1,36 @@
1
+import test from 'node:test';
2
+import assert from 'node:assert/strict';
3
+import 'fake-indexeddb/auto';
4
+import { StorageService } from '../src/core/StorageService.js';
5
+
6
+test('A03 migration: v6 invoices and ledgers survive an additive v7 upgrade', async () => {
7
+ const raw = await new Promise((resolve, reject) => {
8
+ const req = indexedDB.open('finora_pro_db', 6);
9
+ req.onupgradeneeded = () => {
10
+ const db = req.result;
11
+ db.createObjectStore('invoices', { keyPath: 'id' })
12
+ .put({ id: 'before-upgrade', companyId: 'c1', grandTotal: 1550 });
13
+ db.createObjectStore('journal_entries', { keyPath: 'id' })
14
+ .put({ id: 'historic-journal', companyId: 'c1', status: 'posted' });
15
+ };
16
+ req.onsuccess = () => resolve(req.result);
17
+ req.onerror = () => reject(req.error);
18
+ });
19
+ raw.close();
20
+
21
+ const db = await StorageService.init();
22
+ assert.equal(db.version, 7);
23
+ assert.equal((await StorageService.get('invoices', 'before-upgrade')).grandTotal, 1550);
24
+ assert.equal((await StorageService.get('journal_entries', 'historic-journal')).status, 'posted');
25
+ assert.ok(db.objectStoreNames.contains('audit_events'));
26
+ assert.ok(db.objectStoreNames.contains('document_corrections'));
27
+ assert.equal((await StorageService.getAll('audit_events')).length, 0,
28
+ 'Existing records must not be falsely presented as historically audited');
29
+
30
+ // A v6 snapshot is accepted by the v7 importer without fabricating audit events.
31
+ const legacy = { app: 'Factor-easyPro', version: 6,
32
+ data: { products: [{ id: 'old-stock', companyId: 'c1', name: 'Old stock' }] } };
33
+ await StorageService.importAll(legacy);
34
+ assert.equal((await StorageService.get('products', 'old-stock')).name, 'Old stock');
35
+ assert.equal((await StorageService.getAll('audit_events')).length, 0);
36
+});