From 0233dc539c8558aea68cceb87f6a4724cb56dc0e Mon Sep 17 00:00:00 2001 From: Raphael Moutard Date: Mon, 3 Jun 2019 12:49:29 +0200 Subject: [PATCH] [FIX] InstrPrty has to be first --- .vscode/launch.json | 23 ++++++++++++++++++++++ lib/__tests__/sepa.test.js | 39 ++++++++++++++++++++++++++++++++++++++ lib/sepa.js | 3 ++- 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..9c79fa3 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,23 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Jest Current File", + "program": "${workspaceFolder}/node_modules/.bin/jest", + "args": [ + "${fileBasenameNoExtension}" + ], + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen", + "disableOptimisticBPs": true, + "windows": { + "program": "${workspaceFolder}/node_modules/jest/bin/jest", + } + } + ] +} diff --git a/lib/__tests__/sepa.test.js b/lib/__tests__/sepa.test.js index 71e5b0d..b56dcda 100644 --- a/lib/__tests__/sepa.test.js +++ b/lib/__tests__/sepa.test.js @@ -1,3 +1,5 @@ +var DOMParser = require('xmldom').DOMParser; + const Sepa = require('../sepa'); const SEPA_TYPE = 'pain.001.001.03'; // Customer Credit Transfer Initiation V3 @@ -15,4 +17,41 @@ describe('SEPA lib', () => { // Correctly build the initiatorName expect(xmlString).toMatch(/SPENDESK/); }); + + it('should have payment info in order with InstrPrty first', async () => { + const doc = new Sepa.Document(SEPA_TYPE); + + doc.grpHdr.id = 'ID_1'; + doc.grpHdr.created = new Date(); + doc.grpHdr.initiatorName = 'SPENDESK'; + + const paymentInfo = doc.createPaymentInfo(); + paymentInfo.requestedExecutionDate = new Date(); + // If set to true, banks will group all payements with the same supplier and date + // We do not want that + paymentInfo.batchBooking = false; + + paymentInfo.debtorIBAN = 'FR6130002056460000061183D58'; + paymentInfo.debtorBIC = 'CRLYFRPPCRL'; + paymentInfo.debtorName = 'AMAZON'; + paymentInfo.debtorId = 'DE98ZZZ09999999999'; + + const tx = paymentInfo.createTransaction(); + tx.mandateSignatureDate = new Date('2014-02-01'); + + tx.creditorName = 'AMAZON'; + tx.creditorIBAN = 'FR6130002056460000061183D58'; + tx.creditorBIC = 'CRLYFRPPCRL'; + tx.amount = 30; + tx.currency = 'EUR'; + tx.end2endId = '123'; + paymentInfo.addTransaction(tx); + + doc.addPaymentInfo(paymentInfo); + + const xmlString = doc.toString(); + var output = new DOMParser().parseFromString(xmlString); + + expect(output.getElementsByTagName('PmtTpInf')[0].toString()).toBe('NORMSEPA'); + }); }); diff --git a/lib/sepa.js b/lib/sepa.js index 98ade3f..7deb103 100644 --- a/lib/sepa.js +++ b/lib/sepa.js @@ -437,8 +437,9 @@ } var pmtTpInf = n(pmtInf, 'PmtTpInf'); - r(pmtTpInf, 'SvcLvl', 'Cd', 'SEPA'); + // ORDER IS IMPORTANT ! r(pmtTpInf, 'InstrPrty', this.instructionPriority); + r(pmtTpInf, 'SvcLvl', 'Cd', 'SEPA'); if (this.categoryPurpose) { r(pmtTpInf, 'CtgyPurp', 'Cd', this.categoryPurpose); }