@davoodmehraban89 / Factor-easy / commits / 43eac47
Fork 0

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

Add Phase 4 behavioral reconciliation tests

davoodmehraban89 committed Sep 29, 2026 at 12:50 UTC 43eac4705bed4217848e5348b55b6e8dcfa8d506
1 file changed +15
scripts/phase4-behavior-check.mjs new
+15
@@ -0,0 +1,15 @@
1 +import fs from 'node:fs';import vm from 'node:vm';
2 +const code=fs.readFileSync('js/phase4-contracting.js','utf8');
3 +const ds={contracts:[],contractAmendments:[],contractParties:[],contractDeductions:[],guarantees:[],guaranteeEvents:[],contractStatements:[],phase4Audit:[],expenses:[],purchases:[]};
4 +const ctx={console,datastore:ds,currentUser:{id:'u1'},afCompanyId:()=> 'c1',getMyGlobalProjects:()=>[{id:'p1',name:'P'}],getMyContacts:()=>[{id:'e1',name:'E'},{id:'k1',name:'K'}],getMyJournalVouchers:()=>[],getMyExpenses:()=>ds.expenses,getMyPurchases:()=>ds.purchases,esc:String,requireWrite:()=>true,saveDatastore:()=>true,renderPhase4:()=>{},alert:()=>{},getJalaliNumeric:()=> '1405/07/07',toEnDigits:String,document:{getElementById:()=>null},afNeedCompany:()=> 'c1',jeAccountByCode:()=>null,jeRevenueAccount:()=>null,jeDimensionAssignmentsForContext:()=>[],jeCreateDraft:()=>{},jePost:()=>{},jeReverse:()=>{},prompt:()=>null,Date,Math};
5 +vm.createContext(ctx);vm.runInContext(code,ctx);
6 +ds.contracts.push({id:'c',ownerUserId:'u1',companyId:'c1',baseAmount:1000,status:'active',projectId:'p1',employerId:'e1',contractorId:'k1'});
7 +ds.contractAmendments.push({id:'a',ownerUserId:'u1',companyId:'c1',contractId:'c',amountDelta:250,status:'approved'},{id:'b',ownerUserId:'u1',companyId:'c1',contractId:'c',amountDelta:500,status:'draft'});
8 +if(ctx.p4EffectiveValue(ds.contracts[0])!==1250)throw new Error('approved amendment value failed');
9 +if(ctx.p4StatementNet({grossAmount:1000,deductionAmount:150})!==850)throw new Error('statement net failed');
10 +if(ctx.p4ContractLocked(ds.contracts[0]))throw new Error('active contract locked');
11 +ds.expenses.push({ownerUserId:'u1',projectId:'p1',kind:'expense',amount:100});ds.purchases.push({ownerUserId:'u1',projectId:'p1',grandTotal:200});
12 +ds.contractStatements.push({ownerUserId:'u1',companyId:'c1',contractId:'c',status:'posted',grossAmount:1000});
13 +const pr=ctx.p4ContractProfit(ds.contracts[0]);if(pr.revenue!==1000||pr.cost!==300||pr.profit!==700)throw new Error('profitability reconciliation failed');
14 +for(const token of ['p4PostStatement','p4ReverseStatement','p4Audit','contractDeductions','guaranteeEvents'])if(!code.includes(token))throw new Error('missing '+token);
15 +console.log('Phase 4 behavior checks passed');