Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "null" in Ctry, Street and address #64

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"\?>/);
});
});
});