Skip to content

Commit

Permalink
Fix error "null" in Ctry, Street and Address for Credit.
Browse files Browse the repository at this point in the history
  • Loading branch information
William authored and kewisch committed Dec 19, 2023
1 parent 5254f8c commit 110399e
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 5 deletions.
6 changes: 3 additions & 3 deletions lib/sepa.js
Original file line number Diff line number Diff line change
Expand Up @@ -609,9 +609,9 @@

if (this[pullFrom + 'Street'] && this[pullFrom + 'City'] && this[pullFrom + 'Country']) {
var pstl = n(reciever, 'PstlAdr');
r(pstl, 'Ctry', this.debtorCountry);
r(pstl, 'AdrLine', this.debtorStreet);
r(pstl, 'AdrLine', this.debtorCity);
r(pstl, 'Ctry', this[pullFrom + 'Country']);
r(pstl, 'AdrLine', this[pullFrom + 'Street']);
r(pstl, 'AdrLine', this[pullFrom + 'City']);
}

r(txInf, recieverNodeName + 'Acct', 'Id', 'IBAN', this[pullFrom + 'IBAN']);
Expand Down
56 changes: 54 additions & 2 deletions lib/sepa.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,15 @@ describe('IBAN tests',
describe('xml generation for transfer documents', () => {
const PAIN_FOR_TRANSFERS = 'pain.001.003.03';

function validTransferDocument({debtorId=A_VALID_CREDITOR_ID, debtorName='default-debtor-name'}) {
function validTransferDocument({
debtorId=A_VALID_CREDITOR_ID,
debtorName='default-debtor-name',
debtorCity=null,
debtorCountry=null,
debtorStreet=null,
creditorCity=null,
creditorCountry=null,
creditorStreet=null}) {
const doc = new SEPA.Document(PAIN_FOR_TRANSFERS);
doc.grpHdr.created = new Date();

Expand All @@ -50,13 +58,23 @@ describe('xml generation for transfer documents', () => {
info.debtorName = debtorName;
info.debtorId = debtorId;
info.requestedExecutionDate = new Date();

info.debtorCountry = debtorCountry;
info.debtorCity = debtorCity;
info.debtorStreet = debtorStreet;

doc.addPaymentInfo(info);

const tx = info.createTransaction();
tx.creditorName = 'creditor-name';
tx.creditorIBAN = A_VALID_IBAN;
tx.amount = 1.0;
tx.mandateSignatureDate = new Date();

tx.creditorCountry = creditorCountry;
tx.creditorCity = creditorCity;
tx.creditorStreet = creditorStreet;

info.addTransaction(tx);
return doc;
}
Expand Down Expand Up @@ -212,6 +230,40 @@ describe('xml generation for transfer documents', () => {
// WHEN THEN
expect(()=>doc.toXML()).toThrow(Error);
});

test('ctry and address field not null', () => {
// GIVEN
const doc = validTransferDocument({
debtorCountry: 'FR',
debtorStreet: 'Rue du debtor',
debtorCity: 'DebtorCity',
creditorCountry: 'FR',
creditorStreet: 'Rue du creditor',
creditorCity: 'CreditorCity'});

// WHEN
const dom = doc.toXML();

// THEN
const select = xpath.useNamespaces({
p: `urn:iso:std:iso:20022:tech:xsd:${PAIN_FOR_TRANSFERS}`,
});

const debtorCtry = select('/p:Document/p:CstmrCdtTrfInitn/p:PmtInf/p:Dbtr/p:PstlAdr/p:Ctry', dom, true);
const debtorStreet = select('/p:Document/p:CstmrCdtTrfInitn/p:PmtInf/p:Dbtr/p:PstlAdr/p:AdrLine[1]', dom, true);
const debtorCity = select('/p:Document/p:CstmrCdtTrfInitn/p:PmtInf/p:Dbtr/p:PstlAdr/p:AdrLine[2]', dom, true);
expect(debtorCtry.textContent).toBe('FR');
expect(debtorStreet.textContent).toBe('Rue du debtor');
expect(debtorCity.textContent).toBe('DebtorCity');

const creditorCtry = select('/p:Document/p:CstmrCdtTrfInitn/p:PmtInf/p:CdtTrfTxInf[1]/p:Cdtr/p:PstlAdr/p:Ctry', dom, true);
const creditorStreet = select('/p:Document/p:CstmrCdtTrfInitn/p:PmtInf/p:CdtTrfTxInf[1]/p:Cdtr/p:PstlAdr/p:AdrLine[1]', dom, true);
const creditorCity = select('/p:Document/p:CstmrCdtTrfInitn/p:PmtInf/p:CdtTrfTxInf[1]/p:Cdtr/p:PstlAdr/p:AdrLine[2]', dom, true);

expect(creditorCtry.textContent).toBe('FR');
expect(creditorStreet.textContent).toBe('Rue du creditor');
expect(creditorCity.textContent).toBe('CreditorCity');
});
});

describe('xml generation for direct debit documents', () => {
Expand Down Expand Up @@ -276,4 +328,4 @@ describe('xml generation for direct debit documents', () => {
// THEN
expect(xmlString).toMatch(/^<\?xml version="1.0" encoding="UTF-8"\?>/);
});
});
});

0 comments on commit 110399e

Please sign in to comment.