Repository: validatorjs/validator.js
Pull request #1373 (2020-07-04 19:48:53)

improve code coverage to 99.31%
<!--
Add a descriptive title textbox above, e.g.
feat(validatorName): brief title of what has been done
-->

Improve test coverage

## Checklist

- [ ] PR contains only changes related; no stray files, etc.
- [ ] README updated (where applicable)
- [ ] Tests written (where applicable)



Patch:
diff --git a/src/lib/isIdentityCard.js b/src/lib/isIdentityCard.js
index 11c72cf..4fc5c83 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);


Test patch:
diff --git a/test/validators.js b/test/validators.js
index 0040f72..824ee33 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',
         ],
       },
       {