@@ -266,9 +266,7 @@ describe('Transaction()', () => {
266266
267267 expect ( test . toString ( ) ) . toContain ( deviceString ) ;
268268
269- expect ( test . toString ( ) ) . toContain (
270- '"credit_card":{"last_4_digits":"1234"}'
271- ) ;
269+ expect ( test . toString ( ) ) . toContain ( '"credit_card":{"last_digits":"1234"}' ) ;
272270 } ) ;
273271
274272 it ( 'it handles optional order field' , ( ) => {
@@ -317,7 +315,7 @@ describe('Transaction()', () => {
317315 } ) ;
318316
319317 describe ( 'key casing conversion' , ( ) => {
320- describe ( '`creditCard.last4digits` => `creditCard.last_4_digits `' , ( ) => {
318+ describe ( '`creditCard.lastDigits/ last4digits` => `creditCard.lastDigits `' , ( ) => {
321319 test ( 'typed value is mapped' , ( ) => {
322320 const test = JSON . parse (
323321 new Transaction ( {
@@ -328,7 +326,7 @@ describe('Transaction()', () => {
328326 } ) . toString ( )
329327 ) ;
330328
331- expect ( test . credit_card ) . toHaveProperty ( 'last_4_digits ' , '1234' ) ;
329+ expect ( test . credit_card ) . toHaveProperty ( 'last_digits ' , '1234' ) ;
332330 } ) ;
333331
334332 test ( 'null value is mapped' , ( ) => {
@@ -343,7 +341,35 @@ describe('Transaction()', () => {
343341 } ) . toString ( )
344342 ) ;
345343
346- expect ( test . credit_card ) . toHaveProperty ( 'last_4_digits' , null ) ;
344+ expect ( test . credit_card ) . toHaveProperty ( 'last_digits' , null ) ;
345+ } ) ;
346+
347+ test ( 'typed value is mapped' , ( ) => {
348+ const test = JSON . parse (
349+ new Transaction ( {
350+ device : new Device ( {
351+ ipAddress : '1.1.1.1' ,
352+ } ) ,
353+ creditCard : new CreditCard ( { lastDigits : '1234' } ) ,
354+ } ) . toString ( )
355+ ) ;
356+
357+ expect ( test . credit_card ) . toHaveProperty ( 'last_digits' , '1234' ) ;
358+ } ) ;
359+
360+ test ( 'null value is mapped' , ( ) => {
361+ const test = JSON . parse (
362+ new Transaction ( {
363+ device : new Device ( {
364+ ipAddress : '1.1.1.1' ,
365+ } ) ,
366+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
367+ // @ts -ignore explicit null
368+ creditCard : new CreditCard ( { lastDigits : null } ) ,
369+ } ) . toString ( )
370+ ) ;
371+
372+ expect ( test . credit_card ) . toHaveProperty ( 'last_digits' , null ) ;
347373 } ) ;
348374 } ) ;
349375
@@ -415,4 +441,63 @@ describe('Transaction()', () => {
415441 } ) ;
416442 } ) ;
417443 } ) ;
444+
445+ describe ( '6 or 8 digit iins and 2 or 4 digit lastDigits' , ( ) => {
446+ it ( 'it handles 8 digit iins with 2 digit lastDigits' , ( ) => {
447+ const test = new Transaction ( {
448+ creditCard : new CreditCard ( {
449+ issuerIdNumber : '12345678' ,
450+ lastDigits : '12' ,
451+ } ) ,
452+ device : new Device ( {
453+ ipAddress : '1.1.1.1' ,
454+ sessionAge : 100 ,
455+ } ) ,
456+ } ) ;
457+
458+ expect ( isJSON ( test . toString ( ) ) ) . toBe ( true ) ;
459+
460+ expect ( test . toString ( ) ) . toContain (
461+ '"credit_card":{"issuer_id_number":"12345678","last_digits":"12"}'
462+ ) ;
463+ } ) ;
464+
465+ it ( 'it handles 8 digit iins with 4 digit lastDigits' , ( ) => {
466+ const test = new Transaction ( {
467+ creditCard : new CreditCard ( {
468+ issuerIdNumber : '12345678' ,
469+ lastDigits : '1234' ,
470+ } ) ,
471+ device : new Device ( {
472+ ipAddress : '1.1.1.1' ,
473+ sessionAge : 100 ,
474+ } ) ,
475+ } ) ;
476+
477+ expect ( isJSON ( test . toString ( ) ) ) . toBe ( true ) ;
478+
479+ expect ( test . toString ( ) ) . toContain (
480+ '"credit_card":{"issuer_id_number":"12345678","last_digits":"1234"}'
481+ ) ;
482+ } ) ;
483+
484+ it ( 'it handles 6 digit iins with 2 digit lastDigits' , ( ) => {
485+ const test = new Transaction ( {
486+ creditCard : new CreditCard ( {
487+ issuerIdNumber : '123456' ,
488+ lastDigits : '12' ,
489+ } ) ,
490+ device : new Device ( {
491+ ipAddress : '1.1.1.1' ,
492+ sessionAge : 100 ,
493+ } ) ,
494+ } ) ;
495+
496+ expect ( isJSON ( test . toString ( ) ) ) . toBe ( true ) ;
497+
498+ expect ( test . toString ( ) ) . toContain (
499+ '"credit_card":{"issuer_id_number":"123456","last_digits":"12"}'
500+ ) ;
501+ } ) ;
502+ } ) ;
418503} ) ;
0 commit comments