diff --git a/src/helpers/constants.js b/src/helpers/constants.js index 6a40fe2185..788bbe2b93 100644 --- a/src/helpers/constants.js +++ b/src/helpers/constants.js @@ -224,6 +224,7 @@ module.exports = { [this.RECEIVED]: 'Reçu', [this.XML_GENERATED]: 'Fichier XML associé', [this.PAID]: 'Réglé', + [this.CANCELLED]: 'Annulé', }; }, NOT_INVOICED: 'not_invoiced', diff --git a/tests/integration/exports.test.js b/tests/integration/exports.test.js index 70650b5344..6820071232 100644 --- a/tests/integration/exports.test.js +++ b/tests/integration/exports.test.js @@ -200,6 +200,7 @@ const vendorHistoryExportTypes = [ `"Paiement";"REG-00001";"09/03/2022";"FACT-00001";${authCompany._id};1;"Prélèvement";"1100,00";"Fichier XML associé";"Prélèvements Septembre 2025";"14/03/2022";`, `"Paiement";"REG-00003";"09/03/2022";"FACT-00005";${courseFundingOrganisation._id};1;"Espèces";"300,00";"Reçu";;;`, `"Paiement";"REG-00006";"01/04/2022";"FACT-00001";${authCompany._id};2;"Prélèvement";"50,00";"En attente";;;`, + `"Paiement";"REG-00007";"10/03/2022";"FACT-00002";${courseFundingOrganisation._id};1;"Prélèvement";"1200,00";"Annulé";;;`, `"Remboursement";"REMB-00001";"11/03/2022";"FACT-00005";${courseFundingOrganisation._id};2;"Chèque";"200,00";"Reçu";;;`, ], query: 'startDate=2022-03-01T10:00:00.000Z&endDate=2022-04-20T10:00:00.000Z', diff --git a/tests/integration/seed/exportsSeed.js b/tests/integration/seed/exportsSeed.js index 8bebb63e35..fffe893851 100644 --- a/tests/integration/seed/exportsSeed.js +++ b/tests/integration/seed/exportsSeed.js @@ -97,6 +97,7 @@ const { PENDING, RECEIVED, XML_GENERATED, + CANCELLED, BANK_TRANSFER, PRESENT, MISSING, @@ -1462,7 +1463,7 @@ const courseFundingOrganisation = { const courseBillNumber = { _id: new ObjectId(), seq: 8 }; const courseCreditNoteNumber = { _id: new ObjectId(), seq: 2 }; const coursePaymentNumber = [ - { _id: new ObjectId(), seq: 6, nature: PAYMENT }, + { _id: new ObjectId(), seq: 7, nature: PAYMENT }, { _id: new ObjectId(), seq: 4, nature: REFUND }, ]; @@ -1664,6 +1665,16 @@ const coursePaymentList = [ type: DIRECT_DEBIT, status: PENDING, }, + { // 10 cancelled because of creditNote + number: 'REG-00007', + date: '2022-03-10T00:00:00.000Z', + companies: [authCompany._id], + courseBill: courseBillList[1]._id, + netInclTaxes: 1200, + nature: PAYMENT, + type: DIRECT_DEBIT, + status: CANCELLED, + }, ]; const xmlSEPAFileInfos = { diff --git a/tests/unit/helpers/vendorHistoryExport.test.js b/tests/unit/helpers/vendorHistoryExport.test.js index 00a762e12b..f35b4969d7 100644 --- a/tests/unit/helpers/vendorHistoryExport.test.js +++ b/tests/unit/helpers/vendorHistoryExport.test.js @@ -22,6 +22,7 @@ const { VENDOR_ADMIN, NO_DATA, CHECK, + DIRECT_DEBIT, REFUND, ESTIMATED_START_DATE_EDITION, WEBAPP, @@ -32,6 +33,7 @@ const { RECEIVED, PENDING, PAID, + CANCELLED, PRESENT, MISSING, DRAFT, @@ -2918,7 +2920,7 @@ describe('exportCoursePaymentHistory', () => { }); it('should return an array with the header and 3 rows', async () => { - const courseBillIds = [new ObjectId(), new ObjectId()]; + const courseBillIds = [new ObjectId(), new ObjectId(), new ObjectId()]; const payerId = new ObjectId(); const coursePaymentList = [ { @@ -2967,6 +2969,21 @@ describe('exportCoursePaymentHistory', () => { netInclTaxes: 200, status: RECEIVED, }, + { + _id: new ObjectId(), + nature: PAYMENT, + number: 'REG-5', + date: '2022-01-15T23:00:00.000Z', + courseBill: { + _id: courseBillIds[2], + number: 'FACT-3', + payer: { _id: payerId }, + course: { type: INTRA, trainees: [{ _id: new ObjectId(), identity: { firstname: 'Archie', lastname: 'Pelle' } }] }, + }, + type: DIRECT_DEBIT, + netInclTaxes: 50, + status: CANCELLED, + }, ]; findCoursePayment .onCall(0) @@ -2975,6 +2992,7 @@ describe('exportCoursePaymentHistory', () => { [ { _id: coursePaymentList[0], courseBill: courseBillIds[0] }, { _id: coursePaymentList[2], courseBill: courseBillIds[1] }, + { _id: coursePaymentList[3], courseBill: courseBillIds[2] }, ], ['setOptions', 'lean']) ); @@ -2986,6 +3004,7 @@ describe('exportCoursePaymentHistory', () => { ['Nature', 'Identifiant', 'Date', 'Facture associée', 'Id payeur facture', 'Numéro du paiement (parmi ceux de la même facture)', 'Moyen de paiement', 'Montant', 'Statut', 'Nom de lot fichier XML', 'Date d\'effet du prélèvement', 'Apprenant'], ['Remboursement', 'REG-2', '23/01/2022', 'FACT-2', payerId, 2, 'Chèque', '22,00', 'Reçu', 'LOT-002', '22/01/2022', 'Archie PELLE'], ['Remboursement', 'REG-4', '11/01/2022', 'FACT-1', payerId, 1, 'Chèque', '200,00', 'Reçu', '', '', ''], + ['Paiement', 'REG-5', '16/01/2022', 'FACT-3', payerId, 1, 'Prélèvement', '50,00', 'Annulé', '', '', ''], ]); SinonMongoose.calledWithExactly( findCoursePayment,