@davoodmehraban89 / Factor-easy / commits / 3b49e12
Fork 0

سامانه صدور فاکتور و حسابداری

test: enforce posting uniqueness, acknowledged sync, draft exclusion and watermark contracts

davoodmehraban89 committed Oct 11, 2026 at 21:06 UTC 3b49e122fe1b995f5c70cbc889d7fca58467bea2
1 file changed +26
scripts/posting-idempotency-check.mjs new
+26
@@ -0,0 +1,26 @@
1 +import {readFileSync} from 'node:fs';
2 +import assert from 'node:assert/strict';
3 +const migration=readFileSync('supabase/migrations/20261011183500_posted_source_idempotency_index.sql','utf8');
4 +const invoice=readFileSync('js/invoices.js','utf8');
5 +const manager=readFileSync('js/document-management.js','utf8');
6 +const product=readFileSync('js/products.js','utf8');
7 +const inventory=readFileSync('js/phase5-enterprise.js','utf8');
8 +const cash=readFileSync('js/payments.js','utf8');
9 +const print=readFileSync('js/print.js','utf8');
10 +assert.match(migration,/CREATE UNIQUE INDEX IF NOT EXISTS ux_finora_posted_source_identity/);
11 +assert.match(migration,/coalesce\(organization_id::text,owner_id::text\)/);
12 +assert.match(migration,/data->>'sourceType'/);
13 +assert.match(migration,/data->>'sourceId'/);
14 +assert.match(migration,/data->>'sourceVersion'/);
15 +assert.match(migration,/posted','reversed'/);
16 +assert.match(invoice,/documentStatus:'draft',accountingStatus:'draft'/);
17 +assert.match(invoice,/async function finalizeInvoiceDocument\(/);
18 +assert.match(invoice,/await runSync\(\)/);
19 +assert.match(invoice,/syncSnap\.has\('journalVouchers\|'/);
20 +assert.doesNotMatch(invoice,/if\(invoiceCreatesAccountingEntry\(kind\).*?jePostSourceRecord\('sale',record\)/s);
21 +assert.match(manager,/invoiceDocumentStatus\(inv\)/);
22 +assert.match(product,/invoiceDocumentStatus\(x\)==='posted'/);
23 +assert.match(inventory,/invoiceDocumentStatus\(d\)==='posted'/);
24 +assert.match(cash,/invoiceDocumentStatus\(inv\)!=='posted'/);
25 +assert.match(print,/پیش‌نویس — غیرقطعی/);
26 +console.log('Financial draft/posted data safety invariants PASS');