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

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

test: fail closed when autopost source link is not atomic

davoodmehraban89 committed Nov 17, 2026 at 14:25 UTC fd6852808c09d5387bf9989f1a477bbf57b9a9b9
1 file changed +10 -2
scripts/journal-rpc-adapter.test.mjs
+10 -2
@@ -135,7 +135,7 @@ test('fresh membership and pending generic sync are hard preconditions before mu
135 });
136
137
138 -function sourceHarness(kind='sale',{journalDirty=false,failSourceSync=false,loseFirstResponse=false,rejectWithCode=false}={}){
138 +function sourceHarness(kind='sale',{journalDirty=false,failSourceSync=false,loseFirstResponse=false,rejectWithCode=false,noAtomicLink=false}={}){
139 const h=harness(),collection=kind==='sale'?'invoices':'purchases';
140 const source={id:kind==='sale'?'INV_SOURCE_1':'PUR_SOURCE_1',ownerUserId:'USER_A',companyId:'CO_A',
141 date:'1405/07/19',number:'SRC-1',description:'synthetic source',reference:'REF-1',
@@ -170,7 +170,7 @@ function sourceHarness(kind='sale',{journalDirty=false,failSourceSync=false,lose
170 const voucher=serverVoucher||{id:'JV_SERVER_'+kind,status:'posted',version:2,postedAt:'1405-07-19T10:00:00Z',postedBy:'USER_A'};
171 if(!serverVoucher){
172 serverVoucher=voucher;
173 - serverSource={...serverSource,journalVoucherId:voucher.id,accountingStatus:'posted',
173 + if(!noAtomicLink)serverSource={...serverSource,journalVoucherId:voucher.id,accountingStatus:'posted',
174 accountingPostedAt:voucher.postedAt,documentStatus:'posted',documentPostedAt:voucher.postedAt,
175 documentPostedBy:voucher.postedBy,documentVersion:1};
176 }
@@ -335,3 +335,11 @@ test('concurrent source autopost submissions serialize before generic source flu
335 assert.equal(voucher.id,'JV_SERVER_sale');
336 assert.equal(h.source.journalVoucherId,voucher.id);
337 });
338 +
339 +
340 +test('client fails closed if the server posts a voucher without atomically linking the source',async()=>{
341 + const h=sourceHarness('sale',{noAtomicLink:true});
342 + await assert.rejects(()=>h.context.jeRpcAutoPost('sale',h.source.id),/پیوند منبع در همان تراکنش سرور تأیید نشد/);
343 + assert.equal(h.source.accountingPostingPending,true);
344 + assert.equal(h.source.journalVoucherId,undefined);
345 +});