سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 4, 06:45 UTC
test(qa): prove formal sale Save lacks atomic linked journal draft
davoodmehraban89 committed
Nov 22, 2026 at 17:42 UTC
71e4a2fe2803248d2ea7abf0122ecfc5cddfef6f
1 file changed
+41
scripts/accounting-document-workflow.spec.js
+41
@@ -1017,3 +1017,44 @@ test('P0 #229 expected RED: linked journal draft stays draft for both sales and
1017
test.fail(true,'#229: linked draft misclassified in sale and purchase status selectors');
1018
expect(observed).toEqual({sale:'draft',purchase:'draft',voucherStates:['draft','draft']});
1019
});
1020
+
1021
+
1022
+test('P0 #229 expected RED: formal sale Save must persist linked journal draft without posting',async({page})=>{
1023
+ const server=fakeServer();
1024
+ await installHarness(page,server);
1025
+ await authenticatedMockBrowser(page);
1026
+ await fillInvoice(page,'QA-ADR216-SALE-LINK-DRAFT',2);
1027
+ await page.evaluate(()=>commitSaveInvoice());
1028
+ await expect.poll(()=>remoteInvoices(server).length,{timeout:14000}).toBe(1);
1029
+ // A fixture failure is not allowed to masquerade as the expected accounting RED.
1030
+ await page.waitForFunction(()=>!syncPending&&!syncRunning);
1031
+ const source=remoteInvoices(server)[0];
1032
+ if(source.number!=='QA-ADR216-SALE-LINK-DRAFT'||source.kind!=='formal'||
1033
+ source.companyId!=='QA_CO'||source.grandTotal!==3000)
1034
+ throw Error('QA formal sale Save fixture invalid; NOT expected-red: '+JSON.stringify(source));
1035
+ const vouchers=[...server.records.values()].filter(row=>row.collection==='journalVouchers');
1036
+ const linked=vouchers.find(row=>row.id===source.journalVoucherId);
1037
+ const lines=[...server.records.values()].filter(row=>
1038
+ row.collection==='journalLines'&&row.data.voucherId===source.journalVoucherId);
1039
+ const debit=lines.reduce((sum,row)=>sum+Number(row.data.debit||0),0);
1040
+ const credit=lines.reduce((sum,row)=>sum+Number(row.data.credit||0),0);
1041
+ const observed={
1042
+ documentStatus:source.documentStatus,
1043
+ accountingStatus:source.accountingStatus,
1044
+ hasLinkedDraft:!!linked&&linked.data.status==='draft',
1045
+ linkedSourceMatches:!!linked&&linked.data.sourceType==='sale'&&linked.data.sourceId===source.id,
1046
+ draftHasNoFinalNumber:!!linked&&!linked.data.number,
1047
+ draftHasBalancedLines:lines.length>=2&&debit===credit&&debit===source.grandTotal,
1048
+ postedVouchers:vouchers.filter(row=>row.data.status==='posted').length,
1049
+ automaticPostCalls:server.autoPostCount||0
1050
+ };
1051
+ // CURRENT: source-only sale draft, no linked journal, no autopost.
1052
+ // REQUIRED ADR216: atomic source + linked journal draft, balanced lines, no final number.
1053
+ test.fail(true,'#229 / ADR216: formal sale Save still lacks server-persisted linked journal draft');
1054
+ expect(observed).toEqual({
1055
+ documentStatus:'draft',accountingStatus:'draft',
1056
+ hasLinkedDraft:true,linkedSourceMatches:true,
1057
+ draftHasNoFinalNumber:true,draftHasBalancedLines:true,
1058
+ postedVouchers:0,automaticPostCalls:0
1059
+ });
1060
+});