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

test(pilot): assert posted-invoice cancellation retention and draft-only deletion

davoodmehraban89 committed Oct 14, 2026 at 08:30 UTC ddaeac6bcb86d1a96024c70d953a3d773b62e5af
1 file changed +29
scripts/accounting-document-workflow.spec.js
+29
@@ -218,6 +218,35 @@ test('pilot manual journal correction permits draft edits, balanced repost and a
218 expect(await page.evaluate(()=>jeTrialBalance().find(x=>x.accountId==='A_CASH').balance)).toBe(0);
219 });
220
221 +test('pilot cancellation preserves posted invoice record while only unposted drafts can be deleted',async({page})=>{
222 + const server=fakeServer();await installHarness(page,server);await authenticatedMockBrowser(page);
223 + await fillInvoice(page,'PILOT-CANCEL-001',2);await page.evaluate(()=>commitSaveInvoice());
224 + await expect.poll(()=>remoteInvoices(server).length,{timeout:13000}).toBe(1);
225 + const invoiceId=remoteInvoices(server)[0].id;
226 + await page.evaluate(id=>finalizeInvoiceDocument(id),invoiceId);
227 + const original=remoteInvoices(server)[0];
228 + expect(original.accountingStatus).toBe('posted');
229 + const blocked=await page.evaluate(id=>{try{deleteInvoicePilotDraft(id);return 'unexpected'}catch(e){return String(e.message)}},invoiceId);
230 + expect(blocked).not.toBe('unexpected');
231 + await page.evaluate(id=>cancelPostedInvoicePilot(id,'ابطال سند پایلوت'),invoiceId);
232 + await expect.poll(()=>[...server.records.values()].filter(x=>x.collection==='journalVouchers').length,{timeout:13000}).toBe(2);
233 + expect(remoteInvoices(server)[0].id).toBe(invoiceId);
234 + expect(remoteInvoices(server)[0].grandTotal).toBe(original.grandTotal);
235 + const status=await page.evaluate(id=>invoiceDocumentStatus(getMyInvoices().find(x=>x.id===id)),invoiceId);
236 + expect(status).toBe('reversed');
237 + const bad=await page.evaluate(async id=>{try{await reopenPostedInvoiceAsDraft(id,'تکرار');return 'unexpected'}catch(e){return String(e.message)}},invoiceId);
238 + expect(bad).not.toBe('unexpected');
239 + // A separate never-posted invoice may be deleted; posted history stays intact.
240 + await fillInvoice(page,'PILOT-DELETE-DRAFT-001',1);await page.evaluate(()=>commitSaveInvoice());
241 + await expect.poll(()=>remoteInvoices(server).length,{timeout:13000}).toBe(2);
242 + const draft=remoteInvoices(server).find(x=>x.number==='PILOT-DELETE-DRAFT-001');
243 + expect(draft).toBeTruthy();
244 + await page.evaluate(id=>deleteInvoicePilotDraft(id),draft.id);
245 + await expect.poll(()=>remoteInvoices(server).length,{timeout:13000}).toBe(1);
246 + expect(remoteInvoices(server)[0].id).toBe(invoiceId);
247 + expect([...server.records.values()].filter(x=>x.collection==='journalVouchers')).toHaveLength(2);
248 +});
249 +
250 test('cannot finalize draft if fiscal posting chart has no required account; draft remains intact',async({page})=>{
251 const server=fakeServer();server.records.delete('accounts|A_REV');await installHarness(page,server);await authenticatedMockBrowser(page);
252 await fillInvoice(page,'FIN-NO-REVENUE-ACCOUNT',2);await page.evaluate(()=>commitSaveInvoice());