diff --git a/changelog.md b/changelog.md index 1af7510..2426b6d 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,10 @@ # Changelog +## v2.0.1 + +- Fixed all unit tests to actually get full year +- Fixed expired functionality to be able to handle invalid dates + ## v2.0.0 #### Breaking Changes diff --git a/package.json b/package.json index db4bc8c..d3c6bfa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "simple-card", - "version": "2.0.0", + "version": "2.0.1", "description": "a simple plug and play credit card validation library using the lugn algorithm", "main": "simple-card.min.js", "directories": { diff --git a/src/expired/index.js b/src/expired/index.js index 43b392a..3a698ac 100644 --- a/src/expired/index.js +++ b/src/expired/index.js @@ -39,7 +39,7 @@ const expired = date => { const currDate = generateDate(); const expireDate = new Date(normalizeDate(date)); - const isExpired = currDate > expireDate; + const isExpired = !isNaN(expireDate) ? currDate > expireDate : true; return { isValid: !isExpired, diff --git a/src/expired/tests.js b/src/expired/tests.js index f11bb55..94a9de9 100644 --- a/src/expired/tests.js +++ b/src/expired/tests.js @@ -4,7 +4,7 @@ import test from 'ava'; const today = new Date(); test('Test Date validation', t => { - const { isValid, isExpired } = expired(`${today.getMonth() + 1}/${today.getFullYear}`); + const { isValid, isExpired } = expired(`${today.getMonth() + 1}/${today.getFullYear()}`); t.true(isValid, 'Is a valid date'); t.false(isExpired, 'Not Expired'); @@ -32,3 +32,10 @@ test('Throws type error when given date object', t => { t.is(err.message, 'date should be a string type'); }); + +test('Throws type error when given date object', t => { + const results = expired('21/21'); + + t.true(results.isExpired); + t.false(results.isValid); +}); diff --git a/src/validate/tests.js b/src/validate/tests.js index 41ec4a2..ffd6e17 100644 --- a/src/validate/tests.js +++ b/src/validate/tests.js @@ -2,7 +2,7 @@ import simpleCard from './index'; import test from 'ava'; const today = new Date(); -const currDate = `${today.getMonth() + 1}/${today.getFullYear}`; +const currDate = `${today.getMonth() + 1}/${today.getFullYear()}`; const validData = { visaCard: {