Skip to content

Commit d36f79c

Browse files
authored
chore: Increase coverage and make codecov more precise (#1658)
* fix(isTaxID): fix typo and remove unnecessary conditions * test: add more cases to handle uncovered branches/conditions * chore: make coverage report for codecov more precise Switch from lcov to cobertura to allow handling branch coverage on PR reports
1 parent e08e79a commit d36f79c

File tree

4 files changed

+19
-22
lines changed

4 files changed

+19
-22
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,8 @@ jobs:
2323
run: npm install
2424
- name: Run tests
2525
run: npm test
26-
- if: matrix.node-version == 14
27-
name: Generate coverage file
28-
run: npm run test:ci > coverage.lcov
2926
- if: matrix.node-version == 14
3027
name: Send coverage info to Codecov
3128
uses: codecov/codecov-action@v1
3229
with:
33-
file: ./coverage.lcov
30+
file: ./coverage/cobertura-coverage.xml

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@
6565
"build:node": "babel src -d .",
6666
"build": "npm run build:browser && npm run build:node && npm run build:es",
6767
"pretest": "npm run build && npm run lint",
68-
"test": "nyc mocha --require @babel/register --reporter dot",
69-
"test:ci": "nyc report --reporter=text-lcov"
68+
"test": "nyc --reporter=cobertura --reporter=text-summary mocha --require @babel/register --reporter dot"
7069
},
7170
"engines": {
7271
"node": ">= 0.10"

src/lib/isTaxID.js

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -860,14 +860,10 @@ function plPlCheck(tin) {
860860
*/
861861

862862
function ptBrCheck(tin) {
863-
tin = tin.replace(/[^\d]+/g, '');
864-
if (tin === '') return false;
865-
866863
if (tin.length === 11) {
867864
let sum;
868-
let ramainder;
865+
let remainder;
869866
sum = 0;
870-
tin = tin.replace(/[^\d]+/g, '');
871867

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

885881
for (let i = 1; i <= 9; i++) sum += parseInt(tin.substring(i - 1, i), 10) * (11 - i);
886-
ramainder = (sum * 10) % 11;
887-
if ((ramainder === 10) || (ramainder === 11)) ramainder = 0;
888-
if (ramainder !== parseInt(tin.substring(9, 10), 10)) return false;
882+
remainder = (sum * 10) % 11;
883+
if (remainder === 10) remainder = 0;
884+
if (remainder !== parseInt(tin.substring(9, 10), 10)) return false;
889885
sum = 0;
890886

891887
for (let i = 1; i <= 10; i++) sum += parseInt(tin.substring(i - 1, i), 10) * (12 - i);
892-
ramainder = (sum * 10) % 11;
893-
if ((ramainder === 10) || (ramainder === 11)) ramainder = 0;
894-
if (ramainder !== parseInt(tin.substring(10, 11), 10)) return false;
888+
remainder = (sum * 10) % 11;
889+
if (remainder === 10) remainder = 0;
890+
if (remainder !== parseInt(tin.substring(10, 11), 10)) return false;
895891

896892
return true;
897893
}
898894

899-
if (tin.length !== 14) { return false; }
900-
901895
if ( // Reject know invalid CNPJs
902896
tin === '00000000000000' ||
903897
tin === '11111111111111' ||
@@ -1126,7 +1120,7 @@ const taxIdFormat = {
11261120
'mt-MT': /^\d{3,7}[APMGLHBZ]$|^([1-8])\1\d{7}$/i,
11271121
'nl-NL': /^\d{9}$/,
11281122
'pl-PL': /^\d{10,11}$/,
1129-
'pt-BR': /^\d{11,14}$/,
1123+
'pt-BR': /(?:^\d{11}$)|(?:^\d{14}$)/,
11301124
'pt-PT': /^\d{9}$/,
11311125
'ro-RO': /^\d{13}$/,
11321126
'sk-SK': /^\d{6}\/{0,1}\d{3,4}$/,

test/validators.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10314,12 +10314,19 @@ describe('Validators', () => {
1031410314
'05423994000172',
1031510315
'11867044000130'],
1031610316
invalid: [
10317+
'ABCDEFGH',
1031710318
'170.691.440-72',
10318-
'01494282042',
10319+
'11494282142',
10320+
'74405265037',
1031910321
'11111111111',
10322+
'48469799384',
1032010323
'94.592.973/0001-82',
1032110324
'28592361000192',
10322-
'11111111111111'],
10325+
'11111111111111',
10326+
'111111111111112',
10327+
'61938188550993',
10328+
'82168365502729',
10329+
],
1032310330
});
1032410331
test({
1032510332
validator: 'isTaxID',

0 commit comments

Comments
 (0)