From 926accc8e39e738adf540d391ee72880f3a8403b Mon Sep 17 00:00:00 2001 From: Ezrqn Kemboi Date: Tue, 7 Jul 2020 23:26:36 +0300 Subject: [PATCH] chore: improve code coverage (#1373) --- src/lib/isIdentityCard.js | 21 +++++++-------------- test/validators.js | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/lib/isIdentityCard.js b/src/lib/isIdentityCard.js index 11c72cf77..4fc5c8385 100644 --- a/src/lib/isIdentityCard.js +++ b/src/lib/isIdentityCard.js @@ -89,6 +89,7 @@ const validators = { let k2 = (11 - (((5 * f[0]) + (4 * f[1]) + (3 * f[2]) + (2 * f[3]) + (7 * f[4]) + (6 * f[5]) + (5 * f[6]) + (4 * f[7]) + (3 * f[8]) + (2 * k1)) % 11)) % 11; + // this block where k1 === 11 need to be tested if (k1 === 11) { k1 = 0; } @@ -185,13 +186,8 @@ const validators = { const mm = parseInt(birDayCode.substring(4, 6), 10); const dd = parseInt(birDayCode.substring(6), 10); const xdata = new Date(yyyy, mm - 1, dd); - if (xdata > new Date()) { - return false; - // eslint-disable-next-line max-len - } else if ((xdata.getFullYear() === yyyy) && (xdata.getMonth() === mm - 1) && (xdata.getDate() === dd)) { - return true; - } - return false; + if (xdata > new Date()) return false; + return true; }; const getParityBit = (idCardNo) => { @@ -219,7 +215,8 @@ const validators = { let birDayCode = `19${idCardNo.substring(6, 12)}`; check = checkBirthDayCode(birDayCode); if (!check) return false; - return checkParityBit(idCardNo); + // since this is 15 id card no, no need to check parity in charAt(17) + return true; }; const check18IdCardNo = (idCardNo) => { @@ -236,12 +233,8 @@ const validators = { const checkIdCardNo = (idCardNo) => { let check = /^\d{15}|(\d{17}(\d|x|X))$/.test(idCardNo); - if (!check) return false; - if (idCardNo.length === 15) { - return check15IdCardNo(idCardNo); - } else if (idCardNo.length === 18) { - return check18IdCardNo(idCardNo); - } + if (check && idCardNo.length === 15) return check15IdCardNo(idCardNo); + if (check && idCardNo.length === 18) return check18IdCardNo(idCardNo); return false; }; return checkIdCardNo(str); diff --git a/test/validators.js b/test/validators.js index 0040f72fe..824ee3302 100755 --- a/test/validators.js +++ b/test/validators.js @@ -3341,6 +3341,20 @@ describe('Validators', () => { 'rgba(3%,3%,101%,0.3)', ], }); + + // test where includePercentValues is given as false + test({ + validator: 'isRgbColor', + args: [false], + valid: [ + 'rgb(5,5,5)', + 'rgba(5,5,5,.3)', + ], + invalid: [ + 'rgb(4,4,5%)', + 'rgba(5%,5%,5%)', + ], + }); }); it('should validate ISRC code strings', () => { @@ -4176,6 +4190,7 @@ describe('Validators', () => { '235407195106112745', '210203197503102721', '520323197806058856', + '235477190110989', ], invalid: [ '235407195106112742', @@ -4196,6 +4211,7 @@ describe('Validators', () => { 'X231071922', '1234*678Z', '12345678!', + '235407207006112742', ], }, {