@davoodmehraban89 / Factor-easy / commits / 6d7c9c9
Fork 0

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

test(adr216): expected-RED purchase Save and linked-draft status browser contracts

davoodmehraban89 committed Nov 22, 2026 at 08:36 UTC 6d7c9c937b3de7cfa7ef621524ab85f15e32566f
2 files changed +84
docs/EXECUTION_STATUS.md
+6
@@ -1,5 +1,11 @@
1 # وضعیت اجرای فینورا
2
3 +### ۲۰۲۶-۱۱-۲۲ — آزمون‌های موردانتظار RED برای Issue229
4 +- **مبنای محفوظ:** PR228 SHA `ae6a0557d575389853c4545ca99ec57c8015a0e0` چهار گیت موفق (Quality `44986537956`، WP1 `44986538027`، WP2 `44986537948`، Security `44986537938`). مسیرهای آزموده‌شده مستقیماً قطعی می‌کنند و draft-first را اثبات نمی‌کنند.
5 +- **کاندیدای جدید:** افزودن دو تست `test.fail` صریح در اسکریپت Playwright موجود: یک کلیک واقعی خرید که نباید خودش سند قطعی ایجاد کند و باید منبع+سند حسابداری موقت را ذخیره کند؛ و یک کنترل وضعیت سند موقتِ دارای پیوند در فروش و خرید. هدف دریافت **شکست موردانتظار روی assertion مالی** است؛ قبولی کلی CI به‌معنی رفع نقص نیست. اگر خطای setup رخ دهد، باید fixture اصلاح شود و آن را RED مالی ننامیم.
6 +- **حریم:** فقط تست و اسناد؛ هیچ SQL migration، محصول، UI اجرایی، RLS/Auth، Production یا `main` تغییر نمی‌کند. پس از اصلاح واقعی توسط Codex اصلی باید انتظار شکست حذف شود و همان آزمون‌ها PASS واقعی بدهند.
7 +
8 +
9 ### ۲۰۲۶-۱۱-۲۲ — FIN-QA-PURCHASE-JWT؛ آزمون خرید اعتباری با JWT حقیقی
10 - **سرآغاز اثبات‌شده:** PR227 روی SHA `9c66f0d872c3b14c6fb3a7e0d600477adf2755fe`؛ Quality `44985352819`، WP1 `44985352864`، WP2 `44985352836`، Security `44985352817` همگی SUCCESS. ۲۵۱/۲۵۱ مرورگر + ۴/۴، نمونهٔ واقعی فروش و عدم ویرایش فاکتور قطعی نیز PASS.
11 - **شکاف خاص:** مسیر خرید و نگاشت خرید اعتباری قبلاً در `supabase/tests/wp1_phase1a_stage1_sale_purchase_negatives.sql` با SQL و کاربر شبیه‌سازی‌شده بررسی می‌شد، اما از Auth صادرشده و HTTP واقعی PostgREST در WP2 شواهد مستقل نداشت.
scripts/accounting-document-workflow.spec.js
+78
@@ -939,3 +939,81 @@ test('contact operational balance reflects a saved unallocated supplier payment
939 await expect(page.locator('[data-contact-net]')).toHaveAttribute('data-contact-net','-550');
940 expect(remotePayments(server)).toHaveLength(1);
941 });
942 +
943 +
944 +// Issue #229 / ADR0216: executable expected-RED acceptance contracts.
945 +// test.fail is a transparent temporary xfail, NOT a product PASS. Remove
946 +// annotations only after the linked-draft lifecycle works end-to-end.
947 +test('P0 #229 expected RED: purchase Save must not auto-post',async({page})=>{
948 + test.fail(true,'#229: current purchase Save immediately posts without separate authorization');
949 + const server=fakeServer();
950 + await installHarness(page,server);
951 + await authenticatedMockBrowser(page);
952 + await page.evaluate(()=>{
953 + switchView('view-purchases');
954 + refreshAllSurfaces();
955 + const supplier=document.getElementById('pur-supplier');
956 + if(!supplier?.querySelector('option[value="QA_CONTACT"]'))
957 + throw Error('QA supplier option missing: fixture setup failure, NOT accounting RED');
958 + supplier.value='QA_CONTACT';
959 + document.getElementById('pur-number').value='QA-ADR216-PUR-NO-AUTOPOST';
960 + document.getElementById('pur-date').value='1405/07/19';
961 + document.getElementById('pur-payment-method').value='credit';
962 + const row=document.querySelector('#pur-items-body tr');
963 + if(!row?.querySelector('.pur-prod option[value="QA_PROD"]'))
964 + throw Error('QA product option missing: fixture setup failure, NOT accounting RED');
965 + row.querySelector('.pur-prod').value='QA_PROD';
966 + row.querySelector('.pur-qty').value='2';
967 + row.querySelector('.pur-price').value='100';
968 + purRecalc();
969 + });
970 + await page.locator('#pur-save-btn').click();
971 + await expect.poll(()=>[...server.records.values()].filter(x=>x.collection==='purchases').length,
972 + {timeout:15000}).toBe(1);
973 + await expect.poll(()=>page.evaluate(()=>!document.getElementById('pur-save-btn').disabled),
974 + {timeout:15000}).toBe(true);
975 + const purchase=[...server.records.values()].find(x=>x.collection==='purchases');
976 + const vouchers=[...server.records.values()].filter(x=>x.collection==='journalVouchers');
977 + const observed={
978 + documentStatus:purchase?.data.documentStatus,
979 + accountingStatus:purchase?.data.accountingStatus,
980 + hasLinkedDraft:!!purchase?.data.journalVoucherId&&vouchers.some(v=>
981 + v.id===purchase.data.journalVoucherId&&v.data.status==='draft'),
982 + postedVouchers:vouchers.filter(v=>v.data.status==='posted').length,
983 + automaticPostCalls:server.autoPostCount||0
984 + };
985 + // CURRENT: posted, posted, no linked draft, one posted voucher, one autopost.
986 + // REQUIRED: business source + linked draft; no final number/posted voucher.
987 + expect(observed).toEqual({
988 + documentStatus:'draft',accountingStatus:'draft',hasLinkedDraft:true,
989 + postedVouchers:0,automaticPostCalls:0
990 + });
991 +});
992 +
993 +test('P0 #229 expected RED: linked journal draft stays draft for both sales and purchases',async({page})=>{
994 + test.fail(true,'#229: sale treats any link as posted; purchase labels a linked draft legacy_review');
995 + const server=fakeServer();
996 + await installHarness(page,server);
997 + await authenticatedMockBrowser(page);
998 + const observed=await page.evaluate(()=>{
999 + const ownerUserId=currentUser.id,companyId='QA_CO';
1000 + const sale={id:'QA_SALE_LINK_DRAFT',ownerUserId,companyId,kind:'formal',
1001 + journalVoucherId:'QA_SALE_JV_DRAFT',accountingStatus:'draft',documentStatus:'draft'};
1002 + const purchase={id:'QA_PUR_LINK_DRAFT',ownerUserId,companyId,
1003 + journalVoucherId:'QA_PUR_JV_DRAFT',accountingStatus:'draft',documentStatus:'draft'};
1004 + datastore.invoices.push(sale);
1005 + datastore.purchases.push(purchase);
1006 + datastore.journalVouchers.push(
1007 + {id:'QA_SALE_JV_DRAFT',ownerUserId,companyId,status:'draft',
1008 + sourceType:'sale',sourceId:sale.id},
1009 + {id:'QA_PUR_JV_DRAFT',ownerUserId,companyId,status:'draft',
1010 + sourceType:'purchase',sourceId:purchase.id}
1011 + );
1012 + return {
1013 + sale:invoiceDocumentStatus(sale),
1014 + purchase:purchaseDocumentStatus(purchase),
1015 + voucherStates:getMyJournalVouchers().filter(v=>v.id.endsWith('_JV_DRAFT')).map(v=>v.status)
1016 + };
1017 + });
1018 + expect(observed).toEqual({sale:'draft',purchase:'draft',voucherStates:['draft','draft']});
1019 +});