Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve code coverage to 99.31% #1373

Merged
merged 1 commit into from
Jul 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain this rewrite?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or check if you rebased correctly with the latest master.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xdata is created using yyyy, mm-1, and dd.
Getting xdata.getFullYear() and comparing it with what it was used to create it, it will always be true.
So, that line seemed redundant and of no use(it is like creating x from w, which is equal to 1 and comparing x.w with w or 1`.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, thanks.

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