Skip to content

Commit

Permalink
chore: improve code coverage (#1373)
Browse files Browse the repository at this point in the history
  • Loading branch information
ezkemboi committed Jul 7, 2020
1 parent 18caa0a commit 926accc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
21 changes: 7 additions & 14 deletions src/lib/isIdentityCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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) => {
Expand All @@ -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);
Expand Down
16 changes: 16 additions & 0 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -4176,6 +4190,7 @@ describe('Validators', () => {
'235407195106112745',
'210203197503102721',
'520323197806058856',
'235477190110989',
],
invalid: [
'235407195106112742',
Expand All @@ -4196,6 +4211,7 @@ describe('Validators', () => {
'X231071922',
'1234*678Z',
'12345678!',
'235407207006112742',
],
},
{
Expand Down

0 comments on commit 926accc

Please sign in to comment.