@@ -3,6 +3,7 @@ var xpath = require('xpath');
33
44// The following debtor id is provided by German Bundesbank for testing purposes.
55const A_VALID_CREDITOR_ID = 'DE98ZZZ09999999999' ;
6+ const ANOTHER_VALID_CREDITOR_ID = 'IT66ZZZA1B2C3D4E5F6G7H8' ;
67
78const A_VALID_IBAN = 'DE43500105178994141576' ;
89
@@ -336,14 +337,15 @@ describe('xml generation for transfer documents', () => {
336337
337338describe ( 'xml generation for direct debit documents' , ( ) => {
338339 const PAIN_FOR_DIRECT_DEBIT = 'pain.008.001.08' ;
339- function validDirectDebitDocument ( { creditorId= A_VALID_CREDITOR_ID } ) {
340+ function validDirectDebitDocument ( { creditorId= A_VALID_CREDITOR_ID , originalCreditorId = null } ) {
340341 var doc = new SEPA . Document ( PAIN_FOR_DIRECT_DEBIT ) ;
341342 doc . grpHdr . created = new Date ( ) ;
342343
343344 var info = doc . createPaymentInfo ( ) ;
344345 info . collectionDate = new Date ( ) ;
345346 info . creditorIBAN = A_VALID_IBAN ;
346347 info . creditorId = creditorId ;
348+ info . originalCreditorId = originalCreditorId ;
347349 doc . addPaymentInfo ( info ) ;
348350
349351 var tx = info . createTransaction ( ) ;
@@ -388,6 +390,39 @@ describe('xml generation for direct debit documents', () => {
388390 expect ( creditorId ) . toBeUndefined ( ) ;
389391 } ) ;
390392
393+ test ( 'includes original creditor id when set' , ( ) => {
394+ // GIVEN
395+ const doc = validDirectDebitDocument ( { originalCreditorId : ANOTHER_VALID_CREDITOR_ID } ) ;
396+
397+ // WHEN
398+ const dom = doc . toXML ( ) ;
399+
400+ // THEN
401+ const select = xpath . useNamespaces ( {
402+ p : `urn:iso:std:iso:20022:tech:xsd:${ PAIN_FOR_DIRECT_DEBIT } ` ,
403+ } ) ;
404+
405+ const originalCreditorId = select ( '/p:Document/p:CstmrDrctDbtInitn/p:PmtInf/p:OrgnlCdtrSchmeId/p:Id/p:PrvtId/p:Othr/p:Id' , dom , true ) ;
406+ expect ( originalCreditorId ) . not . toBeUndefined ( ) ;
407+ expect ( originalCreditorId . textContent ) . toBe ( ANOTHER_VALID_CREDITOR_ID ) ;
408+ } ) ;
409+
410+ test ( 'works without setting original creditor id' , ( ) => {
411+ // GIVEN
412+ const doc = validDirectDebitDocument ( { originalCreditorId : null } ) ;
413+
414+ // WHEN
415+ const dom = doc . toXML ( ) ;
416+
417+ // THEN
418+ const select = xpath . useNamespaces ( {
419+ p : `urn:iso:std:iso:20022:tech:xsd:${ PAIN_FOR_DIRECT_DEBIT } ` ,
420+ } ) ;
421+
422+ const originalCreditorId = select ( '/p:Document/p:CstmrDrctDbtInitn/p:PmtInf/p:OrgnlCdtrSchmeId' , dom , true ) ;
423+ expect ( originalCreditorId ) . toBeUndefined ( ) ;
424+ } ) ;
425+
391426 test ( 'serialized document starts with proper xml declaration' , ( ) => {
392427 // GIVEN
393428 const doc = validDirectDebitDocument ( { } ) ;
0 commit comments