@davoodmehraban89 / Factor-easy / commits / 4f20a50
Fork 0

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

test: cover ATF and atomic draft deletion contract

davoodmehraban89 committed Nov 18, 2026 at 09:01 UTC 4f20a5057eea0f31165e4c460079d45f79ea8a6e
1 file changed +41
scripts/journal-rpc-adapter.test.mjs
+41
@@ -351,3 +351,44 @@ test('client fails closed if the server posts a voucher without atomically linki
351 assert.equal(h.source.accountingPostingPending,true);
352 assert.equal(h.source.journalVoucherId,undefined);
353 });
354 +
355 +test('source draft deletion uses the atomic lifecycle RPC and never generic sync',async()=>{
356 + const h=sourceHarness('sale');
357 + h.source._serverVersion=7;
358 + const result=await h.context.jeRpcDeleteSourceDraft('invoices',h.source.id);
359 + const call=h.calls.find(x=>x.name==='finora_document_delete_draft');
360 + assert.ok(call);
361 + assert.equal(call.args.p_organization_id,'ORG_A');
362 + assert.equal(call.args.p_collection,'invoices');
363 + assert.equal(call.args.p_document_id,h.source.id);
364 + assert.equal(call.args.p_expected_version,7);
365 + assert.equal(h.calls.some(x=>x.name==='finora_sync_records'),false);
366 + assert.equal(result,undefined);
367 +});
368 +
369 +test('journal source-linked drafts are never exposed as directly deletable manual vouchers',async()=>{
370 + const h=harness({vouchers:[{id:'JV_SOURCE',status:'draft',sourceType:'sale',sourceId:'INV_SOURCE_1',companyId:'CO_A',fiscalYearId:'FY_A',_serverVersion:4}]});
371 + await assert.rejects(()=>h.context.jeRpcDeleteDraft('JV_SOURCE'),/فقط پیش‌نویس دستی/);
372 +});
373 +
374 +test('document lifecycle migration defines permanent ATF, temporary numbering, atomic source delete and generic-delete bypass protection',async()=>{
375 + const migration=await readFile(new URL('../supabase/migrations/20261118090000_document_lifecycle_atf_and_atomic_delete.sql',import.meta.url),'utf8');
376 + assert.match(migration,/finora_document_atf_counters/);
377 + assert.match(migration,/finora_document_temp_counters/);
378 + assert.match(migration,/atfNumber/);
379 + assert.match(migration,/temporaryNumber/);
380 + assert.match(migration,/FINORA_DELETE_VIA_SOURCE/);
381 + assert.match(migration,/finora_document_delete_draft/);
382 + assert.match(migration,/document_deleted/);
383 + assert.match(migration,/FINORA_DOCUMENT_DELETE_VIA_RPC/);
384 + assert.match(migration,/ux_finora_document_atf_journal/);
385 +});
386 +
387 +test('journal UI exposes ATF, temporary and final numbering states',async()=>{
388 + const ui=await readFile(new URL('../js/journal-ui.js',import.meta.url),'utf8');
389 + assert.match(ui,/شماره عطف/);
390 + assert.match(ui,/شماره موقت/);
391 + assert.match(ui,/v\.atfNumber/);
392 + assert.match(ui,/v\.temporaryNumber/);
393 + assert.match(ui,/v\.number/);
394 +});