Skip to content

Commit

Permalink
fix: remove errors replace of null (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
dedicio committed Jan 25, 2021
1 parent 937960b commit 3ea882d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/creditcard.js
Expand Up @@ -30,6 +30,7 @@ export const isValid = (number) => {
};

function findCreditCardObjectByNumber(number) {
if (!number) return {};
const numberOnly = number.replace(/[^\d]/g, '');
return CARDS.find((card) => card.bins.test(numberOnly) && card) || {};
}
Expand Down
40 changes: 39 additions & 1 deletion src/creditcard.test.js
Expand Up @@ -67,6 +67,18 @@ describe('CreditCard', () => {
it('should return false when month is past', () => {
expect(isExpirationDateValid('01', '2017')).toBe(false);
});

it('should return false when send zero value', () => {
expect(isExpirationDateValid(0, 0)).toBe(false);
});

it('should return false when null values', () => {
expect(isExpirationDateValid(null, null)).toBe(false);
});

it('should return false when send no params', () => {
expect(isExpirationDateValid()).toBe(false);
});
});

describe('#isSecurityCodeValid', () => {
Expand Down Expand Up @@ -101,6 +113,18 @@ describe('CreditCard', () => {
it('should return false when its a not mapped card type and security code has not 3 digit', () => {
expect(isSecurityCodeValid('123', '99')).toBe(false);
});

it('should return false when send empty params', () => {
expect(isSecurityCodeValid('', '')).toBe(false);
});

it('should return false when send no params', () => {
expect(isSecurityCodeValid()).toBe(false);
});

it('should return false when send null params', () => {
expect(isSecurityCodeValid(null, null)).toBe(false);
});
});

describe('#getCreditCardNameByNumber', () => {
Expand Down Expand Up @@ -140,11 +164,25 @@ describe('CreditCard', () => {
expect(getCreditCardNameByNumber(CREDIT_CARDS.visaMask)).toBe('Visa');
});

it('should return false', () => {
it('should return false when card number is invalid', () => {
expect(getCreditCardNameByNumber(INVALID_CREDIT_CARD)).toBe(
'Credit card is invalid!'
);
});

it('should return false when send no params', () => {
expect(getCreditCardNameByNumber()).toBe('Credit card is invalid!');
});

it('should return false when send empty params', () => {
expect(getCreditCardNameByNumber('', '')).toBe('Credit card is invalid!');
});

it('should return false when send null params', () => {
expect(getCreditCardNameByNumber(null, null)).toBe(
'Credit card is invalid!'
);
});
});

describe('#validate', () => {
Expand Down

0 comments on commit 3ea882d

Please sign in to comment.