@davoodmehraban89 / Factor-easy / commits / f551fc1
Fork 0

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

test(qa): reject unexpected Issue229 xfail states before expected failures

davoodmehraban89 committed Nov 22, 2026 at 18:54 UTC f551fc1fb5532a359a0976121586df707c78cb5f
1 file changed +49
scripts/accounting-document-workflow.spec.js
+49
@@ -3,6 +3,23 @@ const {test,expect}=require('@playwright/test');
3 const BASE=process.env.FINORA_TEST_BASE_URL||'http://127.0.0.1:4173/index.html';
4 const USER='FINORA_F0_FIXTURE_ONLY';
5 const copy=value=>JSON.parse(JSON.stringify(value));
6 +const {isDeepStrictEqual}=require('node:util');
7 +// Do not allow an unexpected third product state to masquerade as expected P0 RED.
8 +function assertKnownRedOrFixed(observed,knownBroken,required,label){
9 + if(isDeepStrictEqual(observed,knownBroken)||isDeepStrictEqual(observed,required))return;
10 + throw new Error('FINORA_ISSUE229_UNEXPECTED_PRODUCT_STATE '+label+' (not the known P0 RED): '+
11 + JSON.stringify({observed,knownBroken,required}));
12 +}
13 +test('P0 #229 sentinel rejects unexpected financial states before expected-RED markers',()=>{
14 + const broken={status:'posted',count:1,voucherStates:['posted']};
15 + const fixed={status:'draft',count:0,voucherStates:['draft']};
16 + expect(()=>assertKnownRedOrFixed(broken,broken,fixed,'fixture')).not.toThrow();
17 + expect(()=>assertKnownRedOrFixed(fixed,broken,fixed,'fixture')).not.toThrow();
18 + expect(()=>assertKnownRedOrFixed({status:'partial',count:2,voucherStates:['posted']},
19 + broken,fixed,'fixture')).toThrow(/FINORA_ISSUE229_UNEXPECTED_PRODUCT_STATE/);
20 + expect(()=>assertKnownRedOrFixed({status:'posted',count:1,voucherStates:['posted','orphan']},
21 + broken,fixed,'fixture')).toThrow(/FINORA_ISSUE229_UNEXPECTED_PRODUCT_STATE/);
22 +});
23 function fakeServer(){
24 const records=new Map();
25 for(const [collection,id,data] of [
@@ -983,6 +1000,13 @@ test('P0 #229 expected RED: purchase Save must not auto-post',async({page})=>{
1000 };
1001 // CURRENT: posted, posted, no linked draft, one posted voucher, one autopost.
1002 // REQUIRED: business source + linked draft; no final number/posted voucher.
1003 + assertKnownRedOrFixed(observed,{
1004 + documentStatus:'posted',accountingStatus:'posted',hasLinkedDraft:false,
1005 + postedVouchers:1,automaticPostCalls:1
1006 + },{
1007 + documentStatus:'draft',accountingStatus:'draft',hasLinkedDraft:true,
1008 + postedVouchers:0,automaticPostCalls:0
1009 + },'purchase-initial-save');
1010 test.fail(true,'#229: Save invokes automatic posting instead of persisted linked draft');
1011 expect(observed).toEqual({
1012 documentStatus:'draft',accountingStatus:'draft',hasLinkedDraft:true,
@@ -1014,6 +1038,11 @@ test('P0 #229 expected RED: linked journal draft stays draft for both sales and
1038 voucherStates:getMyJournalVouchers().filter(v=>v.id.endsWith('_JV_DRAFT')).map(v=>v.status)
1039 };
1040 });
1041 + assertKnownRedOrFixed(observed,{
1042 + sale:'posted',purchase:'legacy_review',voucherStates:['draft','draft']
1043 + },{
1044 + sale:'draft',purchase:'draft',voucherStates:['draft','draft']
1045 + },'linked-draft-status');
1046 test.fail(true,'#229: linked draft misclassified in sale and purchase status selectors');
1047 expect(observed).toEqual({sale:'draft',purchase:'draft',voucherStates:['draft','draft']});
1048 });
@@ -1050,6 +1079,17 @@ test('P0 #229 expected RED: formal sale Save must persist linked journal draft w
1079 };
1080 // CURRENT: source-only sale draft, no linked journal, no autopost.
1081 // REQUIRED ADR216: atomic source + linked journal draft, balanced lines, no final number.
1082 + assertKnownRedOrFixed(observed,{
1083 + documentStatus:'draft',accountingStatus:'draft',
1084 + hasLinkedDraft:false,linkedSourceMatches:false,
1085 + draftHasNoFinalNumber:false,draftHasBalancedLines:false,
1086 + postedVouchers:0,automaticPostCalls:0
1087 + },{
1088 + documentStatus:'draft',accountingStatus:'draft',
1089 + hasLinkedDraft:true,linkedSourceMatches:true,
1090 + draftHasNoFinalNumber:true,draftHasBalancedLines:true,
1091 + postedVouchers:0,automaticPostCalls:0
1092 + },'sale-initial-save');
1093 test.fail(true,'#229 / ADR216: formal sale Save still lacks server-persisted linked journal draft');
1094 expect(observed).toEqual({
1095 documentStatus:'draft',accountingStatus:'draft',
@@ -1112,6 +1152,15 @@ test('P0 #229 expected RED: posted purchase correction Save must remain linked a
1152 };
1153 // CURRENT: purchaseSaveSeamless directly calls finalizePurchasePilotDraft(newId)
1154 // on Save, bypassing independent accounting approval for the correction.
1155 + assertKnownRedOrFixed(observed,{
1156 + documentStatus:'posted',accountingStatus:'posted',
1157 + hasSourceLinkedJournalDraft:false,journalPointsToCorrection:true,
1158 + balancedDraftLines:true,correctionAlreadyPosted:true,originalReversalCount:1
1159 + },{
1160 + documentStatus:'draft',accountingStatus:'draft',
1161 + hasSourceLinkedJournalDraft:true,journalPointsToCorrection:true,
1162 + balancedDraftLines:true,correctionAlreadyPosted:false,originalReversalCount:1
1163 + },'purchase-correction-save');
1164 test.fail(true,'#229 / ADR216: correcting posted purchase Save auto-finalizes the new source');
1165 expect(observed).toEqual({
1166 documentStatus:'draft',accountingStatus:'draft',