Add missing tests and switch to coverall#1376
Add missing tests and switch to coverall#1376profnandaa merged 10 commits intovalidatorjs:masterfrom
Conversation
profnandaa
left a comment
There was a problem hiding this comment.
Thanks for the clean-up. Please check the comments I dropped below.
| 82: '澳门', | ||
| 91: '国外', | ||
| }; | ||
| const provincesAndCities = [ |
There was a problem hiding this comment.
Any reasons for this change?
There was a problem hiding this comment.
In the original version we are just checking if the first two numbers of the ID are a valid province number. It means having an object is unnecessary and probably the result of a copy/paste
There was a problem hiding this comment.
Sorry for late response. So that we don't lose the info on the provinces, could you add those as comments on each line instead?
11, // '北京'
...| '210203197503102721', | ||
| '520323197806058856', | ||
| '235477190110989', | ||
| '110101491001001', |
There was a problem hiding this comment.
Can add a note for this churn?
There was a problem hiding this comment.
Both values are correct, i think the old version is an improvements made by @ezkemboi to cover 15 characters ID cards that got overwritten when i merged my own existing changes. I Can undo it if you want to
| '(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))', | ||
| '?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$', | ||
| ]); | ||
| '(?:-((?:0|[1-9]\\d*|\\d*[a-z-][0-9a-z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-z-][0-9a-z-]*))*))', |
There was a problem hiding this comment.
Can explain these changes too?
There was a problem hiding this comment.
It was the only way to test/exec multilineRegexp second parameter. The method is only used in this function and there is no difference with the old regex except the fact that this one is shorter.
If we want 100% coverage we have to choose between keeping this little hack or removing completely flags parameter from multilineRegexp (We may use this function in other validators in the future)
| let check = /^[1-9]\d{7}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))\d{3}$/.test(idCardNo); | ||
| if (!check) return false; | ||
| let addressCode = idCardNo.substring(0, 6); | ||
| let addressCode = idCardNo.substring(0, 2); |
There was a problem hiding this comment.
Add a note too about this change.
There was a problem hiding this comment.
If you check the old implementation of checkAddressCode you can see that it accepts a 6 character string (addressCode), do a regexp check on it's length and verify if the first 2 characters are a valid provinceCode.
Since length check is unnecessary and already done in line 204, i am directly passing the provinceCode to checkAddressCode and it's a 2 characters numerical string
|
@tux-tn -- sorry, I see some of the stuff has been covered in your comments above; perhaps just add a comment in the code for some of the changes. |
|
@profnandaa what do you think about the switching to coverall? I think you can create the integration with your "Collaborator" access |
|
@tux-tn -- sure, we can try that, let me know what I should do. |
Hello,
As discussed in #1366 i worked on the tests to increase the coverage (i reached the goal of 100%).
Sorry i didn't see @ezkemboi work on #1373 and tried to base my work on what he did.
This is a summary of the content of this PR:
isIdentityCardespecially in CN validator. I tried to remove unnecessary code based on the specs of the validatorsisTaxIDto follow the behaviour of other validatorsisMultilineRegexWhat is planned:
This PR is a kind of work in progress, my initial goal was to have browsers tests running but it's harder and longer than what i expected. We need to build the tests suites, remove nodejs dependencies (utils, fs, ...) and integrate them to a browser testing platform (SauceLabs, browserstack, ...)
Actually i'm in the second step, most of the tests are running correctly in the browser. Should we keep the PR open until i finish integrating browser testing or create another PR (all code related to browser testing is uncommited) ?