Skip to content

Commit

Permalink
[FIX] InstrPrty has to be first
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphael Moutard committed Jun 3, 2019
1 parent 34d6c6d commit 0233dc5
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
23 changes: 23 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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",
}
}
]
}
39 changes: 39 additions & 0 deletions lib/__tests__/sepa.test.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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('<PmtTpInf><InstrPrty>NORM</InstrPrty><SvcLvl><Cd>SEPA</Cd></SvcLvl></PmtTpInf>');
});
});
3 changes: 2 additions & 1 deletion lib/sepa.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 0233dc5

Please sign in to comment.