فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
test(A02): test safe Holoo extract source profiling and no writes
davoodmehraban89 committed
Oct 17, 2026 at 01:45 UTC
5981136e58849c84af3cffad2623c8e89e687f3e
1 file changed
+98
tests/a02-holoo-migration-preflight.test.mjs
new
+98
@@ -0,0 +1,98 @@
1
+import test from 'node:test';
2
+import assert from 'node:assert/strict';
3
+import { previewHolooExtract } from '../src/core/HolooMigrationPreflight.mjs';
4
+
5
+const clean = () => ({
6
+ sourceSystem: 'holoo',
7
+ // Names are placeholders for an explicitly exported/decoded, *synthetic*
8
+ // tabular source. Not claims about proprietary Holoo table/field names.
9
+ datasets: {
10
+ contacts: [{ code: 'C1', label: 'test', debit: 0, credit: 0 }],
11
+ products: [{ code: 'P1', label: 'item' }],
12
+ invoices: [{ id: 'I1', contact: 'C1', gross: 300, paid: 100 }],
13
+ invoiceLines: [{ invoice: 'I1', product: 'P1' }],
14
+ cheques: [{ code: 'Q1', total: 50 }]
15
+ },
16
+ columns: {
17
+ contacts: { sourceId: 'code', name: 'label', receivable: 'debit', payable: 'credit' },
18
+ products: { sourceId: 'code', name: 'label' },
19
+ invoices: { sourceId: 'id', contactId: 'contact', grandTotal: 'gross', paidAmount: 'paid' },
20
+ invoiceLines: { invoiceId: 'invoice', productId: 'product' },
21
+ cheques: { sourceId: 'code', amount: 'total' }
22
+ }
23
+});
24
+
25
+test('A02/Holoo synthetic explicit mapping preview never imports or writes anything', () => {
26
+ const data = clean(), before = structuredClone(data);
27
+ const result = previewHolooExtract(data);
28
+ assert.equal(result.issueCount, 0);
29
+ assert.equal(result.status, 'requires-source-and-accountant-review');
30
+ assert.equal(result.inspectedRows, 5);
31
+ assert.equal(result.importPerformed, false);
32
+ assert.equal(result.writePerformed, false);
33
+ assert.equal(result.canCommit, false);
34
+ assert.deepEqual(data, before);
35
+ assert.equal(Object.isFrozen(result), true);
36
+});
37
+
38
+test('A02/Holoo rejects duplicate source IDs and orphan references without identifying records', () => {
39
+ const data = clean();
40
+ data.datasets.contacts.push({ ...data.datasets.contacts[0], label: 'PRIVATE PERSON' });
41
+ data.datasets.invoiceLines[0].invoice = 'missing-personal-document';
42
+ data.datasets.invoiceLines[0].product = 'missing-secret-code';
43
+ const result = previewHolooExtract(data);
44
+ assert.equal(result.status, 'blocked');
45
+ assert.ok(result.issues.some(x => x.code === 'DUPLICATE_SOURCE_ID'));
46
+ assert.equal(result.issues.filter(x => x.code === 'REFERENCE_NOT_FOUND').length, 2);
47
+ for (const sensitive of ['PRIVATE PERSON', 'missing-personal-document', 'missing-secret-code']) {
48
+ assert.ok(!JSON.stringify(result).includes(sensitive));
49
+ }
50
+});
51
+
52
+test('A02/Holoo refuses fractional/invalid rial amounts and overpaid invoices', () => {
53
+ const data = clean();
54
+ data.datasets.invoices[0].gross = 100.25;
55
+ data.datasets.invoices[0].paid = 180;
56
+ const result = previewHolooExtract(data);
57
+ assert.ok(result.issues.some(x => x.code === 'AMOUNT_NOT_INTEGER_RIAL'));
58
+ data.datasets.invoices[0].gross = 100;
59
+ const result2 = previewHolooExtract(data);
60
+ assert.ok(result2.issues.some(x => x.code === 'PAID_EXCEEDS_GROSS'));
61
+});
62
+
63
+test('A02/Holoo never guesses missing schema mappings or backup decoders', () => {
64
+ const data = clean();
65
+ delete data.columns.cheques;
66
+ const result = previewHolooExtract(data);
67
+ assert.ok(result.issues.some(x => x.code === 'MAPPING_REQUIRED'));
68
+ assert.equal(result.canCommit, false);
69
+ assert.throws(() => previewHolooExtract({ ...data, sourceSystem: 'unknown' }));
70
+ assert.throws(() => previewHolooExtract({ ...data, datasets: { invoices: {} } }));
71
+});
72
+
73
+test('A02/Holoo exposes bounded diagnostics for big sensitive exports', () => {
74
+ const data = clean();
75
+ data.datasets.cheques = Array.from({ length: 15 }, (_, i) => ({
76
+ code: 'duplicate', total: -100, holder: 'PERSON ' + i
77
+ }));
78
+ const result = previewHolooExtract(data, { maxIssues: 2 });
79
+ assert.equal(result.issues.length, 2);
80
+ assert.equal(result.truncated, true);
81
+ assert.ok(result.issueCount > 2);
82
+ assert.ok(!JSON.stringify(result).includes('PERSON'));
83
+ for (const n of [0, -1, 1001, 1.5]) {
84
+ assert.throws(() => previewHolooExtract(data, { maxIssues: n }), RangeError);
85
+ }
86
+});
87
+
88
+test('A02/Holoo unrecognized snapshots are blocked and no false import readiness claimed', () => {
89
+ const missing = previewHolooExtract({ sourceSystem: 'holoo' });
90
+ assert.equal(missing.status, 'blocked');
91
+ assert.ok(missing.issues.some(x => x.code === 'SOURCE_HAS_NO_MAPPED_ROWS'));
92
+ const sparse = previewHolooExtract({ sourceSystem: 'holoo', datasets: {
93
+ products: [{ id: 'p1', name: 'some product' }]
94
+ }, columns: { products: { sourceId: 'id', name: 'name' } } });
95
+ assert.equal(sparse.issueCount, 0);
96
+ assert.equal(sparse.status, 'requires-source-and-accountant-review');
97
+ assert.equal(sparse.canCommit, false);
98
+});