Adicionado validacao do cpf

This commit is contained in:
2024-05-28 20:04:17 -04:00
parent 10a916b119
commit 7ceaf76c31
27 changed files with 1227 additions and 3 deletions

View File

@@ -0,0 +1,72 @@
import cnpj from '../src/validator/cnpj';
const emptyCnpj = '';
const validCnpjMasked = '31.257.435/0001-40';
const validCnpjUnmasked = '31257435000140';
const invalidCnpjMasked = '31.257.435/0001-4';
const invalidCnpjUnmasked = '3125743500014';
describe('CNPJ Validation Test', () => {
it('Should validate a valid CNPJ number', () => {
const isValid = cnpj.validate(emptyCnpj);
expect(isValid).toBeFalsy();
});
it('Should validate a valid CNPJ masked number', () => {
const isValid = cnpj.validate(validCnpjMasked);
expect(isValid).toBeTruthy();
});
it('Should validate a valid CNPJ unmasked number', () => {
const isValid = cnpj.validate(validCnpjUnmasked);
expect(isValid).toBeTruthy();
});
it('Should validate a invalid CNPJ masked number', () => {
const isValid = cnpj.validate(invalidCnpjMasked);
expect(isValid).toBeFalsy();
});
it('Should validate a invalid CNPJ unmasked number', () => {
const isValid = cnpj.validate(invalidCnpjUnmasked);
expect(isValid).toBeFalsy();
});
});
describe('CNPJ Mask Test', () => {
it('Should have mask on a valid cnpj or return empty string', () => {
const newCnpj = cnpj.mask(validCnpjUnmasked);
expect(newCnpj).toBe(validCnpjMasked);
});
it('Should return empty string on invalid CNPJ', () => {
const newCnpj = cnpj.mask(invalidCnpjUnmasked);
expect(newCnpj).toBe('');
});
});
describe('CNPJ Unmask Test', () => {
it('Should be unmasked string on a valid cnpj or return empty string', () => {
const newCnpj = cnpj.unmask(validCnpjMasked);
expect(newCnpj).toBe(validCnpjUnmasked);
});
it('Should return empty string on invalid CNPJ', () => {
const newCnpj = cnpj.unmask(invalidCnpjUnmasked);
expect(newCnpj).toBe('');
});
});
describe('CNPJ Generator Test', () => {
it('Should generate a valid cnpj', () => {
const newCnpj = cnpj.generate();
const isValid = cnpj.validate(newCnpj);
expect(isValid).toBeTruthy();
});
it('Should generate a valid cnpj and formmat', () => {
const newCnpj = cnpj.generate({format: true});
const isValid = cnpj.validate(newCnpj);
expect(isValid).toBeTruthy();
});
});

84
node_modules/brazilian-doc-validator/tests/cpf.test.ts generated vendored Normal file
View File

@@ -0,0 +1,84 @@
import cpf from '../src/validator/cpf';
const emptyCpf = '';
const validCpf = '047.145.880-52';
const validOnlyNumbers = '04714588052';
const invalidCpfLength = '047.145.880-5';
const invalidCpf = '047.145.880-54';
const invalidOnlyNumbers = '04714588054';
describe('CPF Validation test', () => {
it('Correct check if CPF is null or empty', () => {
const isEmpty = cpf.validate(emptyCpf);
expect(isEmpty).toBeFalsy();
});
it('Correct check if CPF provided is valid', () => {
const isValid = cpf.validate(validCpf);
expect(isValid).toBeTruthy();
});
it('Correct check if CPF provided is invalid', () => {
const isValid = cpf.validate(invalidCpf);
expect(isValid).toBeFalsy();
});
it('Correct check if CPF provided has correct length', () => {
const isValid = cpf.validate(invalidCpfLength);
expect(isValid).toBeFalsy();
});
it('Correct check if CPF provided is 00000000000 ', () => {
const isValid = cpf.validate('00000000000');
expect(isValid).toBeFalsy();
});
});
describe('CPF Mask test', () => {
it('Correct check if CPF is null or empty', () => {
const isEmpty = cpf.mask(emptyCpf);
expect(isEmpty).toBe('');
});
it('Correct check if CPF is masked in the right format ', () => {
const valid = cpf.mask(validOnlyNumbers);
expect(valid).toBe(validCpf);
});
it('Correct check if invalid CPF returns empty string', () => {
const invalid = cpf.mask(invalidOnlyNumbers);
expect(invalid).toBe('');
});
});
describe('CPF Unmask test', () => {
it('Correct check if CPF is null or empty', () => {
const isEmpty = cpf.unmask(emptyCpf);
expect(isEmpty).toBe('');
});
it('Correct check if CPF unmasked (only numbers)', () => {
const valid = cpf.unmask(validCpf);
expect(valid).toBe(validOnlyNumbers);
});
it('Correct check if invalid CPF returns empty string', () => {
const invalid = cpf.unmask(invalidOnlyNumbers);
expect(invalid).toBe('');
});
});
describe('CPF Generator test', () => {
it('Correct check if generated CPF is valid and unmasked', () => {
const cpfGenerated = cpf.generate({mask: true});
const isValid = cpf.validate(cpfGenerated);
expect(isValid).toBeTruthy();
});
it('Correct check if generated CPF is valid and masked', () => {
const cpfGenerated = cpf.generate({mask: false});
const isValid = cpf.validate(cpfGenerated);
expect(isValid).toBeTruthy();
});
});