From 70dc75b2177f4b54bffc1afc52ed633b2b32da5c Mon Sep 17 00:00:00 2001 From: Sarhan Date: Sun, 25 Apr 2021 17:49:04 +0100 Subject: [PATCH 1/3] fix(isTaxID): fix typo and remove unnecessary conditions --- src/lib/isTaxID.js | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/lib/isTaxID.js b/src/lib/isTaxID.js index f1ebae6d9..ee66ca326 100644 --- a/src/lib/isTaxID.js +++ b/src/lib/isTaxID.js @@ -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' || @@ -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' || @@ -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}$/, From c35559ffdff30478563fcc6a15ee19baebfca168 Mon Sep 17 00:00:00 2001 From: Sarhan Date: Sun, 25 Apr 2021 17:56:14 +0100 Subject: [PATCH 2/3] test: add more cases to handle uncovered branches/conditions --- test/validators.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/test/validators.js b/test/validators.js index 31b7f960e..9c5ea9d85 100644 --- a/test/validators.js +++ b/test/validators.js @@ -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', From f8f95e37df9d516a92fe79a46b328e93b8331fec Mon Sep 17 00:00:00 2001 From: Sarhan Date: Mon, 26 Apr 2021 11:46:56 +0100 Subject: [PATCH 3/3] chore: make coverage report for codecov more precise Switch from lcov to cobertura to allow handling branch coverage on PR reports --- .github/workflows/ci.yml | 5 +---- package.json | 3 +-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index efa41e11e..21686d855 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/package.json b/package.json index 72573e375..fc96f7622 100644 --- a/package.json +++ b/package.json @@ -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"