سامانه صدور فاکتور و حسابداری
test(lifecycle): lock draft-first numbering and cascade deletion contract
davoodmehraban89 committed
Nov 18, 2026 at 09:06 UTC
74b9f51b63b3edf8479783e34fddc1f0978ee040
1 file changed
+46
scripts/document-lifecycle-contract.test.mjs
new
+46
@@ -0,0 +1,46 @@
1
+import test from 'node:test';
2
+import assert from 'node:assert/strict';
3
+import {readFileSync} from 'node:fs';
4
+
5
+const migration=readFileSync(new URL('../supabase/migrations/20261118100000_document_lifecycle_temp_permanent_atef.sql',import.meta.url),'utf8')
6
+ + readFileSync(new URL('../supabase/migrations/20261118101000_document_identity_trigger.sql',import.meta.url),'utf8')
7
+ + readFileSync(new URL('../supabase/migrations/20261118102000_document_lifecycle_security.sql',import.meta.url),'utf8');
8
+const rpc=readFileSync(new URL('../js/journal-rpc.js',import.meta.url),'utf8');
9
+const invoices=readFileSync(new URL('../js/invoices.js',import.meta.url),'utf8');
10
+const purchases=readFileSync(new URL('../js/purchases.js',import.meta.url),'utf8');
11
+
12
+test('lifecycle contract: ATEF is immutable and deletion is auditable',()=>{
13
+ assert.match(migration,/finora_next_atef/);
14
+ assert.match(migration,/DELETED_WITH_SOURCE/);
15
+ assert.match(migration,/DELETED_DRAFT_VOUCHER/);
16
+ assert.match(migration,/finora_document_lifecycle_audit/);
17
+ assert.match(migration,/FINORA_DELETE_SOURCE_REQUIRED/);
18
+ assert.match(migration,/CREATE TRIGGER finora_document_identity_trigger/);
19
+});
20
+
21
+test('lifecycle contract: all listed transactional families are converted to draft',()=>{
22
+ for(const c of ['journalVouchers','invoices','purchases','payments','expenses','cheques','contractStatements','payrollRuns','employeeBenefitAccruals','pettyCashTransactions']){
23
+ assert.match(migration,new RegExp(c));
24
+ }
25
+ assert.match(migration,/'status','draft'/);
26
+ assert.match(migration,/'documentStatus','draft'/);
27
+});
28
+
29
+test('lifecycle contract: posting allocates permanent number but never changes ATEF',()=>{
30
+ assert.match(migration,/finora_assign_permanent_document_number/);
31
+ assert.match(migration,/never changes ATEF/i);
32
+ assert.match(rpc,/finora_assign_permanent_document_number/);
33
+ assert.match(rpc,/finora_document_identity/);
34
+});
35
+
36
+test('lifecycle contract: sale and purchase start as drafts',()=>{
37
+ assert.match(invoices,/documentStatus:'draft',accountingStatus:'draft'/);
38
+ assert.match(purchases,/documentStatus:'draft',accountingStatus:'draft'/);
39
+ assert.match(purchases,/فاکتور خرید بهصورت پیشنویس ذخیره شد/);
40
+});
41
+
42
+test('lifecycle contract: linked voucher deletion must go through source',()=>{
43
+ assert.match(rpc,/finora_delete_draft_voucher/);
44
+ assert.match(migration,/finora_delete_draft_source/);
45
+ assert.match(migration,/FINORA_DELETE_SOURCE_REQUIRED/);
46
+});