فینورا پرو - سامانه جامع حسابداری و صدور فاکتور

test(A01): cheque status dates, closed-period carryover and atomic refusal

davoodmehraban89 committed Oct 21, 2026 at 09:13 UTC 18516c48e1b8a23aac35d1d953015e5795023220
1 file changed +94
tests/retail-phase2.test.mjs
+94
@@ -828,3 +828,97 @@ test('A01: return cash flow requires structured reason and explicit approval bef
828 assert.equal((await accounts.trialBalance()).totals.debit,
829 (await accounts.trialBalance()).totals.credit);
830 });
831 +
832 +test('A01: cheque status uses selected open-period posting date after its due-date period closes',async()=>{
833 + const {period}=await setup();
834 + const issued=await retail.postCheque({
835 + id:'a01-cheque-carry',direction:'inbound',status:'pending',
836 + issueDate:date,dueDate:date,contactId:'contact-1',
837 + amount:250,chequeNumber:'A01-CARRY'
838 + });
839 + const before={
840 + journals:(await db.getAll('journal_entries')).length,
841 + audits:(await db.getAll('audit_events')).length,
842 + cash:(await db.getAll('treasury')).filter(x=>x.refChequeId===issued.id).length
843 + };
844 + await assert.rejects(retail.changeChequeStatus(issued.id,'cleared',{
845 + date:'1405/07/17',accountId:'cash-1'
846 + }),/پیش از تاریخ صدور/);
847 + await assert.rejects(retail.changeChequeStatus(issued.id,'cleared',{
848 + date:'',accountId:'cash-1'
849 + }),/تاریخ شمسی/);
850 + assert.equal((await db.getAll('journal_entries')).length,before.journals);
851 + assert.equal((await db.getAll('audit_events')).length,before.audits);
852 + assert.equal((await db.get('cheques',issued.id)).status,'pending');
853 + await accounts.closePeriod(period.id);
854 + const newPeriod=await accounts.createPeriod({
855 + name:'۱۴۰۶',startDate:'1406/01/01',endDate:'1406/12/29'
856 + });
857 + const beforeClosedAttempt={
858 + journals:(await db.getAll('journal_entries')).length,
859 + audits:(await db.getAll('audit_events')).length
860 + };
861 + await assert.rejects(retail.changeChequeStatus(issued.id,'cleared',{
862 + date,accountId:'cash-1'
863 + }),/دوره مالی باز/);
864 + assert.equal((await db.getAll('journal_entries')).length,beforeClosedAttempt.journals);
865 + assert.equal((await db.getAll('audit_events')).length,beforeClosedAttempt.audits);
866 + assert.equal((await db.get('cheques',issued.id)).status,'pending');
867 + assert.equal((await db.getAll('treasury')).filter(x=>x.refChequeId===issued.id).length,0);
868 +
869 + // Exercise the real controller forwarding, not only the retail service.
870 + const { ChequeController }=await import('../src/controllers/ChequeController.js');
871 + const eventDate='1406/01/05';
872 + const settled=await ChequeController.changeStatus(issued.id,'cleared',{
873 + date:eventDate,accountId:'cash-1'
874 + });
875 + assert.equal(settled.status,'cleared');
876 + assert.equal(settled.dueDate,date);
877 + assert.equal(settled.issueDate,date);
878 + assert.equal(settled.statusBusinessDate,eventDate);
879 + const statusJournal=await db.get('journal_entries',settled.statusJournalId);
880 + assert.equal(statusJournal.date,eventDate);
881 + assert.equal(statusJournal.periodId,newPeriod.id);
882 + const cash=(await db.getAll('treasury')).filter(x=>x.refChequeId===issued.id);
883 + assert.equal(cash.length,1);
884 + assert.equal(cash[0].date,eventDate);
885 + assert.equal(cash[0].journalId,statusJournal.id);
886 + const receipt=(await db.getAll('audit_events')).filter(x=>
887 + x.correlationId===statusJournal.id&&x.sourceId===statusJournal.id);
888 + assert.equal(receipt.length,1);
889 + assert.equal(receipt[0].businessDate,eventDate);
890 + await assert.rejects(ChequeController.changeStatus(issued.id,'cleared',{
891 + date:eventDate,accountId:'cash-1'
892 + }),/در جریان/);
893 + assert.equal((await db.getAll('treasury')).filter(x=>x.refChequeId===issued.id).length,1);
894 + const trial=await accounts.trialBalance();
895 + assert.equal(trial.totals.debit,trial.totals.credit);
896 +});
897 +
898 +test('A01: outbound bounced cheque in later open period reverses without cash posting',async()=>{
899 + const {period}=await setup();
900 + const outgoing=await retail.postCheque({
901 + id:'a01-cheque-outgoing',direction:'outbound',status:'pending',
902 + issueDate:date,dueDate:date,contactId:'contact-1',
903 + amount:120,chequeNumber:'A01-OUT'
904 + });
905 + await accounts.closePeriod(period.id);
906 + const next=await accounts.createPeriod({
907 + name:'۱۴۰۶',startDate:'1406/01/01',endDate:'1406/12/29'
908 + });
909 + const settled=await retail.changeChequeStatus(outgoing.id,'bounced',{
910 + date:'1406/01/09'
911 + });
912 + assert.equal(settled.status,'bounced');
913 + assert.equal(settled.dueDate,date);
914 + assert.equal(settled.statusBusinessDate,'1406/01/09');
915 + const journal=await db.get('journal_entries',settled.statusJournalId);
916 + assert.equal(journal.periodId,next.id);
917 + assert.equal(journal.date,'1406/01/09');
918 + assert.equal((await db.getAll('treasury')).filter(x=>x.refChequeId===outgoing.id).length,0);
919 + await assert.rejects(retail.changeChequeStatus(outgoing.id,'cleared',{
920 + date:'1406/01/09'
921 + }),/در جریان/);
922 + const trial=await accounts.trialBalance();
923 + assert.equal(trial.totals.debit,trial.totals.credit);
924 +});