From 95ce430f269fa1b928a78e451efb3ebc8c29a3b3 Mon Sep 17 00:00:00 2001 From: Alfonso Strotgen Date: Wed, 10 Jul 2024 16:15:19 -0600 Subject: [PATCH] Fix the NIF validation for Portugal. --- src/pt/nif.spec.ts | 12 ++++++++++++ src/pt/nif.ts | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/pt/nif.spec.ts b/src/pt/nif.spec.ts index c2990352..4a21bcef 100644 --- a/src/pt/nif.spec.ts +++ b/src/pt/nif.spec.ts @@ -25,4 +25,16 @@ describe('pt/nif', () => { expect(result.error).toBeInstanceOf(InvalidChecksum); }); + + it('validate:PT 507 104 560', () => { + const result = validate('507104560'); + + expect(result.isValid && result.compact).toEqual('507104560'); + }); + + it('validate:PT 506 035 220', () => { + const result = validate('506035220'); + + expect(result.isValid && result.compact).toEqual('506035220'); + }); }); diff --git a/src/pt/nif.ts b/src/pt/nif.ts index 3c86c0b9..6a119191 100644 --- a/src/pt/nif.ts +++ b/src/pt/nif.ts @@ -61,7 +61,7 @@ const impl: Validator = { modulus: 11, }); - if (String((11 - sum) % 10) !== check) { + if (String((11 - sum) % 11 % 10) !== check) { return { isValid: false, error: new exceptions.InvalidChecksum() }; }