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

chore: Increase coverage and make codecov more precise #1658

Merged
merged 3 commits into from Jul 16, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 1 addition & 4 deletions .github/workflows/ci.yml
Expand Up @@ -23,11 +23,8 @@ jobs:
run: npm install
- name: Run tests
run: npm test
- if: matrix.node-version == 14
name: Generate coverage file
run: npm run test:ci > coverage.lcov
- if: matrix.node-version == 14
name: Send coverage info to Codecov
uses: codecov/codecov-action@v1
with:
file: ./coverage.lcov
file: ./coverage/cobertura-coverage.xml
3 changes: 1 addition & 2 deletions package.json
Expand Up @@ -65,8 +65,7 @@
"build:node": "babel src -d .",
"build": "npm run build:browser && npm run build:node && npm run build:es",
"pretest": "npm run build && npm run lint",
"test": "nyc mocha --require @babel/register --reporter dot",
"test:ci": "nyc report --reporter=text-lcov"
"test": "nyc --reporter=cobertura --reporter=text-summary mocha --require @babel/register --reporter dot"
},
"engines": {
"node": ">= 0.10"
Expand Down
22 changes: 8 additions & 14 deletions src/lib/isTaxID.js
Expand Up @@ -860,14 +860,10 @@ function plPlCheck(tin) {
*/

function ptBrCheck(tin) {
tin = tin.replace(/[^\d]+/g, '');
if (tin === '') return false;

if (tin.length === 11) {
let sum;
let ramainder;
let remainder;
sum = 0;
tin = tin.replace(/[^\d]+/g, '');

if ( // Reject known invalid CPFs
tin === '11111111111' ||
Expand All @@ -883,21 +879,19 @@ function ptBrCheck(tin) {
) return false;

for (let i = 1; i <= 9; i++) sum += parseInt(tin.substring(i - 1, i), 10) * (11 - i);
ramainder = (sum * 10) % 11;
if ((ramainder === 10) || (ramainder === 11)) ramainder = 0;
if (ramainder !== parseInt(tin.substring(9, 10), 10)) return false;
remainder = (sum * 10) % 11;
if (remainder === 10) remainder = 0;
if (remainder !== parseInt(tin.substring(9, 10), 10)) return false;
sum = 0;

for (let i = 1; i <= 10; i++) sum += parseInt(tin.substring(i - 1, i), 10) * (12 - i);
ramainder = (sum * 10) % 11;
if ((ramainder === 10) || (ramainder === 11)) ramainder = 0;
if (ramainder !== parseInt(tin.substring(10, 11), 10)) return false;
remainder = (sum * 10) % 11;
if (remainder === 10) remainder = 0;
if (remainder !== parseInt(tin.substring(10, 11), 10)) return false;

return true;
}

if (tin.length !== 14) { return false; }

if ( // Reject know invalid CNPJs
tin === '00000000000000' ||
tin === '11111111111111' ||
Expand Down Expand Up @@ -1126,7 +1120,7 @@ const taxIdFormat = {
'mt-MT': /^\d{3,7}[APMGLHBZ]$|^([1-8])\1\d{7}$/i,
'nl-NL': /^\d{9}$/,
'pl-PL': /^\d{10,11}$/,
'pt-BR': /^\d{11,14}$/,
'pt-BR': /(?:^\d{11}$)|(?:^\d{14}$)/,
'pt-PT': /^\d{9}$/,
'ro-RO': /^\d{13}$/,
'sk-SK': /^\d{6}\/{0,1}\d{3,4}$/,
Expand Down
11 changes: 9 additions & 2 deletions test/validators.js
Expand Up @@ -10256,12 +10256,19 @@ describe('Validators', () => {
'05423994000172',
'11867044000130'],
invalid: [
'ABCDEFGH',
'170.691.440-72',
'01494282042',
'11494282142',
'74405265037',
'11111111111',
'48469799384',
'94.592.973/0001-82',
'28592361000192',
'11111111111111'],
'11111111111111',
'111111111111112',
'61938188550993',
'82168365502729',
],
});
test({
validator: 'isTaxID',
Expand Down