validation-br 2.0.0-next-2 → 2.0.0-next-3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/settings.json +5 -0
- package/dist/test/_helpers/crc.spec.js +11 -1
- package/dist/test/_helpers/crc.spec.js.map +1 -1
- package/dist/test/_helpers/crokford.spec.d.ts +2 -0
- package/dist/test/_helpers/crokford.spec.d.ts.map +1 -0
- package/dist/test/_helpers/crokford.spec.js +89 -0
- package/dist/test/_helpers/crokford.spec.js.map +1 -0
- package/dist/test/_helpers/mask.spec.d.ts +2 -0
- package/dist/test/_helpers/mask.spec.d.ts.map +1 -0
- package/dist/test/_helpers/mask.spec.js +18 -0
- package/dist/test/_helpers/mask.spec.js.map +1 -0
- package/dist/test/_helpers/random.spec.d.ts +2 -0
- package/dist/test/_helpers/random.spec.d.ts.map +1 -0
- package/dist/test/_helpers/random.spec.js +77 -0
- package/dist/test/_helpers/random.spec.js.map +1 -0
- package/dist/test/_helpers/utils/checkRepeatedSequence.spec.d.ts +2 -0
- package/dist/test/_helpers/utils/checkRepeatedSequence.spec.d.ts.map +1 -0
- package/dist/test/{utils-checkRepeatedSequence.test.js → _helpers/utils/checkRepeatedSequence.spec.js} +2 -2
- package/dist/test/_helpers/utils/checkRepeatedSequence.spec.js.map +1 -0
- package/dist/test/_helpers/utils/clearValue.spec.d.ts +2 -0
- package/dist/test/_helpers/utils/clearValue.spec.d.ts.map +1 -0
- package/dist/test/{utils-clearValue.test.js → _helpers/utils/clearValue.spec.js} +2 -2
- package/dist/test/_helpers/utils/clearValue.spec.js.map +1 -0
- package/dist/test/_helpers/utils/insertAtPosition.spec.d.ts +2 -0
- package/dist/test/_helpers/utils/insertAtPosition.spec.d.ts.map +1 -0
- package/dist/test/{utils-insertAtPosition.test.js → _helpers/utils/insertAtPosition.spec.js} +2 -2
- package/dist/test/_helpers/utils/insertAtPosition.spec.js.map +1 -0
- package/dist/test/_helpers/utils/removeFromPosition.spec.d.ts +2 -0
- package/dist/test/_helpers/utils/removeFromPosition.spec.d.ts.map +1 -0
- package/dist/test/{utils-removeFromPosition.test.js → _helpers/utils/removeFromPosition.spec.js} +2 -2
- package/dist/test/_helpers/utils/removeFromPosition.spec.js.map +1 -0
- package/dist/test/_helpers/utils/sumElementsByMultipliers.spec.d.ts +2 -0
- package/dist/test/_helpers/utils/sumElementsByMultipliers.spec.d.ts.map +1 -0
- package/dist/test/{utils-sumElementsByMultipliers.test.js → _helpers/utils/sumElementsByMultipliers.spec.js} +2 -2
- package/dist/test/_helpers/utils/sumElementsByMultipliers.spec.js.map +1 -0
- package/dist/test/_helpers/utils/sumToDV.test.d.ts +2 -0
- package/dist/test/_helpers/utils/sumToDV.test.d.ts.map +1 -0
- package/dist/test/{utils-sumToDV.test.js → _helpers/utils/sumToDV.test.js} +2 -2
- package/dist/test/_helpers/utils/sumToDV.test.js.map +1 -0
- package/dist/test/base.spec.d.ts +2 -0
- package/dist/test/base.spec.d.ts.map +1 -0
- package/dist/test/base.spec.js +12 -0
- package/dist/test/base.spec.js.map +1 -0
- package/dist/test/carplate.spec.js +15 -1
- package/dist/test/carplate.spec.js.map +1 -1
- package/dist/test/cbi_sinter.spec.d.ts +2 -0
- package/dist/test/cbi_sinter.spec.d.ts.map +1 -0
- package/dist/test/cbi_sinter.spec.js +58 -0
- package/dist/test/cbi_sinter.spec.js.map +1 -0
- package/dist/test/cep.spec.js +12 -0
- package/dist/test/cep.spec.js.map +1 -1
- package/dist/test/certidao.spec.d.ts +2 -0
- package/dist/test/certidao.spec.d.ts.map +1 -0
- package/dist/test/certidao.spec.js +58 -0
- package/dist/test/certidao.spec.js.map +1 -0
- package/dist/test/cnh.spec.js +20 -1
- package/dist/test/cnh.spec.js.map +1 -1
- package/dist/test/cnpj.spec.js +19 -0
- package/dist/test/cnpj.spec.js.map +1 -1
- package/dist/test/cpf.spec.js +9 -0
- package/dist/test/cpf.spec.js.map +1 -1
- package/dist/test/email.spec.d.ts +2 -0
- package/dist/test/email.spec.d.ts.map +1 -0
- package/dist/test/email.spec.js +19 -0
- package/dist/test/email.spec.js.map +1 -0
- package/dist/test/index.spec.d.ts +2 -0
- package/dist/test/index.spec.d.ts.map +1 -0
- package/dist/test/{index.test.js → index.spec.js} +1 -1
- package/dist/test/{index.test.js.map → index.spec.js.map} +1 -1
- package/dist/test/judicial-process.spec.js +55 -9
- package/dist/test/judicial-process.spec.js.map +1 -1
- package/dist/test/nup17.spec.js +16 -0
- package/dist/test/nup17.spec.js.map +1 -1
- package/dist/test/phone.spec.js +28 -9
- package/dist/test/phone.spec.js.map +1 -1
- package/dist/test/pis-pasep.spec.js +16 -0
- package/dist/test/pis-pasep.spec.js.map +1 -1
- package/dist/test/pix-copy-paste.spec.js +22 -5
- package/dist/test/pix-copy-paste.spec.js.map +1 -1
- package/dist/test/pix-key.spec.js +34 -1
- package/dist/test/pix-key.spec.js.map +1 -1
- package/dist/test/postal-track-code.spec.d.ts +2 -0
- package/dist/test/postal-track-code.spec.d.ts.map +1 -0
- package/dist/test/{postal-track-code.test.js → postal-track-code.spec.js} +9 -2
- package/dist/test/{postal-track-code.test.js.map → postal-track-code.spec.js.map} +1 -1
- package/dist/test/renavam.spec.js +13 -0
- package/dist/test/renavam.spec.js.map +1 -1
- package/dist/test/tituloEleitor.spec.js +31 -7
- package/dist/test/tituloEleitor.spec.js.map +1 -1
- package/dist/test/uf.spec.d.ts +2 -0
- package/dist/test/uf.spec.d.ts.map +1 -0
- package/dist/test/uf.spec.js +92 -0
- package/dist/test/uf.spec.js.map +1 -0
- package/dist/test/uuid.spec.d.ts +2 -0
- package/dist/test/uuid.spec.d.ts.map +1 -0
- package/dist/test/uuid.spec.js +54 -0
- package/dist/test/uuid.spec.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +14 -1
- package/test/_helpers/crc.spec.ts +13 -1
- package/test/_helpers/crokford.spec.ts +108 -0
- package/test/_helpers/mask.spec.ts +17 -0
- package/test/_helpers/random.spec.ts +90 -0
- package/test/{utils-checkRepeatedSequence.test.ts → _helpers/utils/checkRepeatedSequence.spec.ts} +1 -1
- package/test/{utils-clearValue.test.ts → _helpers/utils/clearValue.spec.ts} +1 -1
- package/test/{utils-insertAtPosition.test.ts → _helpers/utils/insertAtPosition.spec.ts} +1 -1
- package/test/{utils-removeFromPosition.test.ts → _helpers/utils/removeFromPosition.spec.ts} +1 -1
- package/test/{utils-sumElementsByMultipliers.test.ts → _helpers/utils/sumElementsByMultipliers.spec.ts} +1 -1
- package/test/{utils-sumToDV.test.ts → _helpers/utils/sumToDV.test.ts} +1 -1
- package/test/base.spec.ts +10 -0
- package/test/carplate.spec.ts +19 -1
- package/test/cbi_sinter.spec.ts +69 -0
- package/test/cep.spec.ts +16 -0
- package/test/certidao.spec.ts +66 -0
- package/test/cnh.spec.ts +25 -1
- package/test/cnpj.spec.ts +27 -1
- package/test/cpf.spec.ts +14 -2
- package/test/email.spec.ts +19 -0
- package/test/judicial-process.spec.ts +68 -11
- package/test/nup17.spec.ts +20 -0
- package/test/phone.spec.ts +35 -9
- package/test/pis-pasep.spec.ts +19 -0
- package/test/pix-copy-paste.spec.ts +30 -10
- package/test/pix-key.spec.ts +35 -1
- package/test/{postal-track-code.test.ts → postal-track-code.spec.ts} +9 -2
- package/test/renavam.spec.ts +17 -0
- package/test/tituloEleitor.spec.ts +41 -13
- package/test/uf.spec.ts +104 -0
- package/test/uuid.spec.ts +65 -0
- package/todo.md +2 -1
- package/dist/test/index.test.d.ts +0 -2
- package/dist/test/index.test.d.ts.map +0 -1
- package/dist/test/postal-track-code.test.d.ts +0 -2
- package/dist/test/postal-track-code.test.d.ts.map +0 -1
- package/dist/test/utils-checkRepeatedSequence.test.d.ts +0 -2
- package/dist/test/utils-checkRepeatedSequence.test.d.ts.map +0 -1
- package/dist/test/utils-checkRepeatedSequence.test.js.map +0 -1
- package/dist/test/utils-clearValue.test.d.ts +0 -2
- package/dist/test/utils-clearValue.test.d.ts.map +0 -1
- package/dist/test/utils-clearValue.test.js.map +0 -1
- package/dist/test/utils-insertAtPosition.test.d.ts +0 -2
- package/dist/test/utils-insertAtPosition.test.d.ts.map +0 -1
- package/dist/test/utils-insertAtPosition.test.js.map +0 -1
- package/dist/test/utils-removeFromPosition.test.d.ts +0 -2
- package/dist/test/utils-removeFromPosition.test.d.ts.map +0 -1
- package/dist/test/utils-removeFromPosition.test.js.map +0 -1
- package/dist/test/utils-sumElementsByMultipliers.test.d.ts +0 -2
- package/dist/test/utils-sumElementsByMultipliers.test.d.ts.map +0 -1
- package/dist/test/utils-sumElementsByMultipliers.test.js.map +0 -1
- package/dist/test/utils-sumToDV.test.d.ts +0 -2
- package/dist/test/utils-sumToDV.test.d.ts.map +0 -1
- package/dist/test/utils-sumToDV.test.js.map +0 -1
- /package/test/{index.test.ts → index.spec.ts} +0 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { CBISinter } from "../src/cbi_sinter";
|
|
2
|
+
|
|
3
|
+
describe('CBISinter', () => {
|
|
4
|
+
describe('validate()', () => {
|
|
5
|
+
test('Deve validar um CIB válido com máscara (Exemplo Oficial)', () => {
|
|
6
|
+
const cbi = new CBISinter('A3N8Z4F-Y');
|
|
7
|
+
expect(cbi.value).toBe('A3N8Z4FY');
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
test('Deve validar um CIB válido sem máscara', () => {
|
|
11
|
+
const cbi = new CBISinter('A3N8Z4FY');
|
|
12
|
+
expect(cbi.value).toBe('A3N8Z4FY');
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test('Deve validar um CIB válido com letras minúsculas', () => {
|
|
16
|
+
const cbi = new CBISinter('a3n8z4f-y');
|
|
17
|
+
expect(cbi.value).toBe('A3N8Z4FY');
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test('Deve validar um CIB com substituições (I/L -> 1, O -> 0)', () => {
|
|
21
|
+
// Base '0000001' -> DV '8' (Cálculo: 1*8 = 8 % 31 = 8)
|
|
22
|
+
// Input 'O0O0O0L-8' -> Normaliza para '00000018'
|
|
23
|
+
const cbi = new CBISinter('O0O0O0L-8');
|
|
24
|
+
expect(cbi.value).toBe('00000018');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test('Deve lançar erro para CIB com DV inválido', () => {
|
|
28
|
+
expect(() => new CBISinter('A3N8Z4F-X')).toThrow();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('Deve lançar erro para CIB com tamanho menor que o permitido', () => {
|
|
32
|
+
expect(() => new CBISinter('A3N8Z4')).toThrow();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('Deve lançar erro para CIB com tamanho maior que o permitido', () => {
|
|
36
|
+
expect(() => new CBISinter('A3N8Z4FYA')).toThrow();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('Deve lançar erro se contiver caractere proibido U', () => {
|
|
40
|
+
expect(() => new CBISinter('A3U8Z4F-Y')).toThrow();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('Deve lançar erro para valor vazio', () => {
|
|
44
|
+
expect(() => new CBISinter('')).toThrow();
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe('checksum()', () => {
|
|
49
|
+
test('Deve calcular o DV corretamente (Exemplo da documentação)', () => {
|
|
50
|
+
expect(CBISinter.checksum('A3N8Z4F')).toBe('Y');
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('Deve lançar erro se valor vazio', () => {
|
|
54
|
+
expect(() => CBISinter.checksum('')).toThrow();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('Deve lançar erro se formato inválido (tamanho incorreto)', () => {
|
|
58
|
+
expect(() => CBISinter.checksum('A3N8Z4')).toThrow();
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
describe('fake()', () => {
|
|
63
|
+
test.each([...Array(50)])('Deve gerar um CIB válido', () => {
|
|
64
|
+
const fake = CBISinter.fake();
|
|
65
|
+
|
|
66
|
+
expect(() => new CBISinter(fake.value)).not.toThrow();
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
});
|
package/test/cep.spec.ts
CHANGED
|
@@ -42,7 +42,10 @@ describe('CEP', () => {
|
|
|
42
42
|
'CEP %s deve ser exibido sem máscara',
|
|
43
43
|
(value) => {
|
|
44
44
|
expect(new CEP(value).toString()).toBe('59650000');
|
|
45
|
+
expect(new CEP(value).toString()).toHaveLength(8)
|
|
46
|
+
|
|
45
47
|
expect(new CEP(value).value).toBe('59650000');
|
|
48
|
+
expect(new CEP(value).value).toHaveLength(8)
|
|
46
49
|
}
|
|
47
50
|
);
|
|
48
51
|
});
|
|
@@ -53,6 +56,14 @@ describe('CEP', () => {
|
|
|
53
56
|
expect(cep).toBeDefined();
|
|
54
57
|
expect(cep.value).toHaveLength(8);
|
|
55
58
|
});
|
|
59
|
+
|
|
60
|
+
test.each([...Array(5)])('Gera fake válido por estado', () => {
|
|
61
|
+
const cep = CEP.fake({ uf: UF.RN });
|
|
62
|
+
expect(cep).toBeDefined();
|
|
63
|
+
expect(cep.value).toHaveLength(8);
|
|
64
|
+
expect(cep.value >= '59000000').toBeTruthy();
|
|
65
|
+
expect(cep.value <= '59999999').toBeTruthy();
|
|
66
|
+
});
|
|
56
67
|
});
|
|
57
68
|
|
|
58
69
|
describe('checksum', () => {
|
|
@@ -103,6 +114,11 @@ describe('CEP', () => {
|
|
|
103
114
|
expect(uf.value).toBe('SP');
|
|
104
115
|
}
|
|
105
116
|
);
|
|
117
|
+
|
|
118
|
+
test('Deve retornar erro para um CEP não encontrado', () => {
|
|
119
|
+
expect(() => CEP.getUFByCEP('00123456')).toThrow()
|
|
120
|
+
}
|
|
121
|
+
);
|
|
106
122
|
});
|
|
107
123
|
|
|
108
124
|
describe('getRandomByUF', () => {
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Certidao, CertidaoServico, CertidaoTipoLivro } from '../src/certidao';
|
|
2
|
+
import { InvalidChecksumException } from '../src/_exceptions/ValidationBRError';
|
|
3
|
+
|
|
4
|
+
describe('Certidao Class', () => {
|
|
5
|
+
|
|
6
|
+
test('deve normalizar o valor no construtor', () => {
|
|
7
|
+
// Gera um válido
|
|
8
|
+
const fake = Certidao.fake();
|
|
9
|
+
// Formata manualmente para testar a remoção
|
|
10
|
+
const formatted = fake.value.replace(/^(\d{6})(\d{2})(\d{2})/, '$1.$2-$3-'); // formatação parcial
|
|
11
|
+
|
|
12
|
+
const cert = new Certidao(formatted);
|
|
13
|
+
expect(cert.value).not.toContain('.');
|
|
14
|
+
expect(cert.value).not.toContain('-');
|
|
15
|
+
expect(cert.value).toBe(fake.value);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test('deve validar uma matrícula correta', () => {
|
|
19
|
+
const fake = Certidao.fake();
|
|
20
|
+
expect(fake.validate()).toBe(true);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test('deve lançar exceção para matrícula com DV errado', () => {
|
|
24
|
+
// 32 dígitos, mas final 99 provavelmente inválido para este prefixo
|
|
25
|
+
const invalid = '12345601552023100001001000000199';
|
|
26
|
+
expect(() => new Certidao(invalid)).toThrow(InvalidChecksumException);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('deve aplicar a máscara corretamente', () => {
|
|
30
|
+
// Usar um válido para não lançar erro
|
|
31
|
+
const fake = Certidao.fake();
|
|
32
|
+
const v = fake.value;
|
|
33
|
+
// Máscara: 000000 00 00 0000 0 00000 000 0000000 00
|
|
34
|
+
// 012345 67 89 0123 4 56789 012 3456789 01
|
|
35
|
+
const expected = `${v.substring(0, 6)} ${v.substring(6, 8)} ${v.substring(8, 10)} ${v.substring(10, 14)} ${v.substring(14, 15)} ${v.substring(15, 20)} ${v.substring(20, 23)} ${v.substring(23, 30)} ${v.substring(30, 32)}`;
|
|
36
|
+
|
|
37
|
+
expect(fake.mask()).toBe(expected);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test('o método fake deve respeitar os parâmetros fornecidos', () => {
|
|
41
|
+
const anoPretendido = 1995;
|
|
42
|
+
const cert = Certidao.fake({
|
|
43
|
+
ano: anoPretendido,
|
|
44
|
+
servico: CertidaoServico.RegistroImoveis
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
expect(cert.value.substring(10, 14)).toBe('1995');
|
|
48
|
+
expect(cert.value.substring(8, 10)).toBe(CertidaoServico.RegistroImoveis);
|
|
49
|
+
expect(cert.validate()).toBe(true);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('deve retornar string pura no toString()', () => {
|
|
53
|
+
const fake = Certidao.fake();
|
|
54
|
+
expect(fake.toString()).toBe(fake.value);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('checksum estático deve calcular corretamente', () => {
|
|
58
|
+
// Teste direto do método estático
|
|
59
|
+
const base30 = '123456015520231000010010000001';
|
|
60
|
+
const dv = Certidao.checksum(base30);
|
|
61
|
+
expect(dv.length).toBe(2);
|
|
62
|
+
// Validar que o DV gerado cria um par válido
|
|
63
|
+
const cert = new Certidao(base30 + dv);
|
|
64
|
+
expect(cert.validate()).toBe(true);
|
|
65
|
+
});
|
|
66
|
+
});
|
package/test/cnh.spec.ts
CHANGED
|
@@ -3,7 +3,11 @@ import * as _cnh from '../src/cnh';
|
|
|
3
3
|
|
|
4
4
|
describe('CNH', () => {
|
|
5
5
|
describe('constructor', () => {
|
|
6
|
-
test.each([
|
|
6
|
+
test.each([
|
|
7
|
+
'14490435923',
|
|
8
|
+
'97286888262',
|
|
9
|
+
'621049358-60',
|
|
10
|
+
'491872350-50'])(
|
|
7
11
|
'deve estar definido',
|
|
8
12
|
(input) => {
|
|
9
13
|
expect(new CNH(input)).toBeDefined();
|
|
@@ -64,4 +68,24 @@ describe('CNH', () => {
|
|
|
64
68
|
expect(cnh.mask()).toMatch(/^\d{9}-\d{2}$/)
|
|
65
69
|
});
|
|
66
70
|
});
|
|
71
|
+
|
|
72
|
+
describe('toString', () => {
|
|
73
|
+
test.each([
|
|
74
|
+
{ value: '14490435923', expected: '14490435923' },
|
|
75
|
+
{ value: '97286888262', expected: '97286888262' },
|
|
76
|
+
{ value: '621049358-60', expected: '62104935860' },
|
|
77
|
+
{ value: '491.872.350-50', expected: '49187235050' },
|
|
78
|
+
])('Deve ser exibido sem máscara', (input) => {
|
|
79
|
+
const cnh = new CNH(input.value);
|
|
80
|
+
|
|
81
|
+
expect(cnh.toString()).toBe(input.expected);
|
|
82
|
+
expect(cnh.toString()).toHaveLength(11);
|
|
83
|
+
|
|
84
|
+
expect(cnh.value).toBe(input.expected);
|
|
85
|
+
expect(cnh.value).toHaveLength(11);
|
|
86
|
+
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
|
|
67
91
|
});
|
package/test/cnpj.spec.ts
CHANGED
|
@@ -56,7 +56,7 @@ describe('CNPJ', () => {
|
|
|
56
56
|
expect(calcDv).toBe(item.expected);
|
|
57
57
|
expect(typeof calcDv).toBe('string');
|
|
58
58
|
});
|
|
59
|
-
|
|
59
|
+
|
|
60
60
|
test.each(['11222333000', '1122233300011', ''])(
|
|
61
61
|
'deve lançar erro de dv',
|
|
62
62
|
(item) => {
|
|
@@ -124,4 +124,30 @@ describe('CNPJ', () => {
|
|
|
124
124
|
);
|
|
125
125
|
|
|
126
126
|
});
|
|
127
|
+
|
|
128
|
+
describe('toString', () => {
|
|
129
|
+
test.each([
|
|
130
|
+
{ input: '11.222.333/0001-81', expected: '11222333000181' },
|
|
131
|
+
{ input: '73.797.980/0001-79', expected: '73797980000179' },
|
|
132
|
+
{ input: '06.946.762/0001-61', expected: '06946762000161' },
|
|
133
|
+
{ input: '96.051.576/0001-57', expected: '96051576000157' },
|
|
134
|
+
{ input: '55.585.709/0001-98', expected: '55585709000198' },
|
|
135
|
+
{ input: '99360938000180', expected: '99360938000180' },
|
|
136
|
+
{ input: '23693443000100', expected: '23693443000100' },
|
|
137
|
+
{ input: '32432147000147', expected: '32432147000147' },
|
|
138
|
+
{ input: '91951438000100', expected: '91951438000100' },
|
|
139
|
+
])('deve estar definido', (input) => {
|
|
140
|
+
const cnpj = new CNPJ(input.input);
|
|
141
|
+
expect(cnpj.toString()).toBe(input.expected);
|
|
142
|
+
expect(cnpj.toString()).toHaveLength(14);
|
|
143
|
+
|
|
144
|
+
expect(cnpj.value).toBe(input.expected);
|
|
145
|
+
expect(cnpj.value).toHaveLength(14);
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
|
|
127
150
|
});
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
|
package/test/cpf.spec.ts
CHANGED
|
@@ -37,7 +37,7 @@ describe('CPF', () => {
|
|
|
37
37
|
{ num: '15886489070', expected: '158.864.890-70' },
|
|
38
38
|
{ num: '90889477086', expected: '908.894.770-86' },
|
|
39
39
|
{ num: '00889477000', expected: '008.894.770-00' },
|
|
40
|
-
])('mask() - Testando se a máscara foi gerada corretamente', (item) => {
|
|
40
|
+
])('mask() - Testando se a máscara foi gerada corretamente', (item) => {
|
|
41
41
|
const masked = new CPF(item.num).mask();
|
|
42
42
|
|
|
43
43
|
expect(masked).toBe(item.expected);
|
|
@@ -64,7 +64,7 @@ describe('CPF', () => {
|
|
|
64
64
|
expect(typeof calcDv).toBe('string');
|
|
65
65
|
});
|
|
66
66
|
|
|
67
|
-
|
|
67
|
+
|
|
68
68
|
test.each(['74172316', '1588648900', ''])(
|
|
69
69
|
'%s deve lançar erro de dv',
|
|
70
70
|
(item) => {
|
|
@@ -73,4 +73,16 @@ describe('CPF', () => {
|
|
|
73
73
|
);
|
|
74
74
|
|
|
75
75
|
});
|
|
76
|
+
|
|
77
|
+
describe('toString', () => {
|
|
78
|
+
test('Deve exibir o valor sem os caracteres especiais', () => {
|
|
79
|
+
const cpf = new CPF('133.782.710-00');
|
|
80
|
+
|
|
81
|
+
expect(cpf.toString()).toBe('13378271000')
|
|
82
|
+
expect(cpf.toString()).toHaveLength(11)
|
|
83
|
+
|
|
84
|
+
expect(cpf.value).toBe('13378271000')
|
|
85
|
+
expect(cpf.value).toHaveLength(11)
|
|
86
|
+
});
|
|
87
|
+
});
|
|
76
88
|
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Email } from "../src/email";
|
|
2
|
+
|
|
3
|
+
describe('Email', () => {
|
|
4
|
+
describe('constructor', () => {
|
|
5
|
+
test('Deve definir um email', () => {
|
|
6
|
+
const email = new Email('klawdyo@gmail.com');
|
|
7
|
+
expect(email).toBeDefined()
|
|
8
|
+
});
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
describe('fake', () => {
|
|
12
|
+
test('Deve definir um email fake', () => {
|
|
13
|
+
const email = Email.fake();
|
|
14
|
+
|
|
15
|
+
expect(new Email(email.toString())).toBeDefined()
|
|
16
|
+
expect(new Email(email.value)).toBeDefined()
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { JudicialProcess } from '../src/judicial-process';
|
|
2
|
+
import { insertAtPosition } from '../src/_helpers/utils';
|
|
2
3
|
|
|
3
4
|
describe('JudicialProcess', () => {
|
|
4
5
|
describe('constructor', () => {
|
|
@@ -8,13 +9,13 @@ describe('JudicialProcess', () => {
|
|
|
8
9
|
'08002785520134058400',
|
|
9
10
|
'08002732820164058400',
|
|
10
11
|
])('deve estar definido', (input) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
expect(
|
|
12
|
+
const proc = new JudicialProcess(input)
|
|
13
|
+
expect(proc).toBeDefined();
|
|
14
|
+
expect(proc.processNumber).toBe(input.replace(/\D/g, '').substring(0, 7))
|
|
14
15
|
});
|
|
15
16
|
|
|
16
17
|
test.each([
|
|
17
|
-
'0110060720168200100',
|
|
18
|
+
'0110060720168200100', // caractere a menos
|
|
18
19
|
'61052838320098130023',
|
|
19
20
|
'00110060720168200102',
|
|
20
21
|
'08002785520134058401',
|
|
@@ -108,19 +109,24 @@ describe('JudicialProcess', () => {
|
|
|
108
109
|
|
|
109
110
|
describe('checksum', () => {
|
|
110
111
|
test.each([
|
|
111
|
-
{ num: '000208020125150049',
|
|
112
|
-
{ num: '610528320098130024',
|
|
113
|
-
{ num: '001100620168200100',
|
|
114
|
-
{ num: '080027820134058400',
|
|
115
|
-
{ num: '080027320164058400',
|
|
112
|
+
{ num: '000208020125150049', dv: '25' },
|
|
113
|
+
{ num: '610528320098130024', dv: '83' },
|
|
114
|
+
{ num: '001100620168200100', dv: '07' },
|
|
115
|
+
{ num: '080027820134058400', dv: '55' },
|
|
116
|
+
{ num: '080027320164058400', dv: '28' },
|
|
116
117
|
])('dv() - Verificando se o DV gerado está correto', (item) => {
|
|
117
118
|
const calcDv = JudicialProcess.checksum(item.num);
|
|
118
119
|
|
|
119
|
-
expect(calcDv).toBe(item.
|
|
120
|
+
expect(calcDv).toBe(item.dv);
|
|
120
121
|
expect(typeof calcDv).toBe('string');
|
|
122
|
+
|
|
123
|
+
// Preenche número do processo com o seu DV
|
|
124
|
+
const full = insertAtPosition(item.num, item.dv, 7)
|
|
125
|
+
expect(new JudicialProcess(full).checksum).toBe(item.dv)
|
|
126
|
+
|
|
121
127
|
});
|
|
122
128
|
|
|
123
|
-
|
|
129
|
+
|
|
124
130
|
test.each(['0002080201251500499', '00020802012515004', ''])(
|
|
125
131
|
'deve lançar erro de dv',
|
|
126
132
|
(item) => {
|
|
@@ -128,4 +134,55 @@ describe('JudicialProcess', () => {
|
|
|
128
134
|
}
|
|
129
135
|
);
|
|
130
136
|
});
|
|
137
|
+
|
|
138
|
+
describe('toString', () => {
|
|
139
|
+
test.each([
|
|
140
|
+
{ input: '6105283-83.2009.8.13.0024', expected: '61052838320098130024', },
|
|
141
|
+
{ input: '00110060720168200100', expected: '00110060720168200100', },
|
|
142
|
+
{ input: '08002785520134058400', expected: '08002785520134058400', },
|
|
143
|
+
{ input: '08002732820164058400', expected: '08002732820164058400', },
|
|
144
|
+
])('deve exibir o valor sem caracteres especiais', (input) => {
|
|
145
|
+
|
|
146
|
+
const proc = new JudicialProcess(input.input)
|
|
147
|
+
|
|
148
|
+
expect(proc.toString()).toBe(input.expected)
|
|
149
|
+
expect(proc.toString()).toHaveLength(20)
|
|
150
|
+
|
|
151
|
+
expect(proc.value).toBe(input.expected)
|
|
152
|
+
expect(proc.value).toHaveLength(20)
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
describe('getWithoutChecksum', () => {
|
|
159
|
+
test('Deve pegar o número completo do processo sem o DV', () => {
|
|
160
|
+
// expect(new JudicialProcess('00020802520125150049').)
|
|
161
|
+
expect(JudicialProcess.getWithoutChecksum('00020802520125150049')).toBe('000208020125150049')
|
|
162
|
+
expect(JudicialProcess.getWithoutChecksum('000208020125150049')).toBe('000208020125150049')
|
|
163
|
+
expect(() => JudicialProcess.getWithoutChecksum('00020802012515004')).toThrow()
|
|
164
|
+
});
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
describe('getFakeSubCourt', () => {
|
|
168
|
+
test('Deve pegar aleatoriamente uma subcorte', () => {
|
|
169
|
+
// se informar zero, use 01
|
|
170
|
+
expect(JudicialProcess.getFakeSubCourt('0')).toBe('01')
|
|
171
|
+
expect(JudicialProcess.getFakeSubCourt('00')).toBe('01')
|
|
172
|
+
// vazio calcula um aleatorio
|
|
173
|
+
expect(JudicialProcess.getFakeSubCourt('').length).toBe(2)
|
|
174
|
+
expect(JudicialProcess.getFakeSubCourt(null as any).length).toBe(2)
|
|
175
|
+
expect(JudicialProcess.getFakeSubCourt(undefined as any).length).toBe(2)
|
|
176
|
+
// se informar um válido, use ele mesmo
|
|
177
|
+
expect(JudicialProcess.getFakeSubCourt('02')).toBe('02')
|
|
178
|
+
// se informar um inválido, use 01
|
|
179
|
+
expect(JudicialProcess.getFakeSubCourt('345')).toBe('01')
|
|
180
|
+
|
|
181
|
+
const fake = JudicialProcess.getFakeSubCourt();
|
|
182
|
+
|
|
183
|
+
expect(fake.length).toBe(2);
|
|
184
|
+
expect(fake >= '01').toBeTruthy();
|
|
185
|
+
expect(fake <= '99').toBeTruthy();
|
|
186
|
+
});
|
|
187
|
+
})
|
|
131
188
|
});
|
package/test/nup17.spec.ts
CHANGED
|
@@ -76,4 +76,24 @@ describe('NUP17', () => {
|
|
|
76
76
|
}
|
|
77
77
|
);
|
|
78
78
|
});
|
|
79
|
+
|
|
80
|
+
describe('toString', () => {
|
|
81
|
+
test.each([
|
|
82
|
+
{ input: '23037001380202111', expected: '23037001380202111' },
|
|
83
|
+
{ input: '23037001434202148', expected: '23037001434202148' },
|
|
84
|
+
{ input: '23037001321202142', expected: '23037001321202142' },
|
|
85
|
+
{ input: '23037.001462/2021-65', expected: '23037001462202165' },
|
|
86
|
+
{ input: '23037.001537/2021-16', expected: '23037001537202116' },
|
|
87
|
+
{ input: '23037.001086/2021-17', expected: '23037001086202117' },
|
|
88
|
+
])('Deve exibir o valor sem o caracteres especiais', (item) => {
|
|
89
|
+
const nup = new NUP17(item.input);
|
|
90
|
+
|
|
91
|
+
expect(nup.toString()).toBe(item.expected);
|
|
92
|
+
expect(nup.toString()).toHaveLength(17);
|
|
93
|
+
|
|
94
|
+
expect(nup.value).toBe(item.expected);
|
|
95
|
+
expect(nup.value).toHaveLength(17);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
79
99
|
});
|
package/test/phone.spec.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Phone } from '../src/phone';
|
|
2
2
|
|
|
3
3
|
const cellPhones = [
|
|
4
|
-
'+
|
|
5
|
-
'+55 84 9
|
|
6
|
-
'+55 (84) 9
|
|
7
|
-
'+55 (84)
|
|
8
|
-
'84
|
|
4
|
+
'+5584999873456',
|
|
5
|
+
'+55 84 9 9987 3456',
|
|
6
|
+
'+55 (84) 9 9987-3456',
|
|
7
|
+
'+55 (84) 99987-3456',
|
|
8
|
+
'84 99987-3456',
|
|
9
9
|
];
|
|
10
10
|
const phones = [
|
|
11
11
|
'+558433311454',
|
|
@@ -19,10 +19,10 @@ describe('Phone', () => {
|
|
|
19
19
|
describe('constructor', () => {
|
|
20
20
|
test.each(cellPhones)('Celular %s deve estar definido', (value) => {
|
|
21
21
|
const obj = new Phone(value);
|
|
22
|
-
expect(obj.value).toBe('+
|
|
22
|
+
expect(obj.value).toBe('+5584999873456');
|
|
23
23
|
expect(obj.ddi).toBe('+55');
|
|
24
24
|
expect(obj.ddd).toBe('84');
|
|
25
|
-
expect(obj.phone).toBe('
|
|
25
|
+
expect(obj.phone).toBe('999873456');
|
|
26
26
|
expect(obj.isMobile).toBeTruthy();
|
|
27
27
|
});
|
|
28
28
|
|
|
@@ -34,6 +34,10 @@ describe('Phone', () => {
|
|
|
34
34
|
expect(obj.phone).toBe('33311454');
|
|
35
35
|
expect(obj.isMobile).toBeFalsy;
|
|
36
36
|
});
|
|
37
|
+
|
|
38
|
+
test.each(['12', '1234567890000', '00999870222'])('Deve lançar exceção', (value) => {
|
|
39
|
+
expect(() => new Phone(value)).toThrow();
|
|
40
|
+
});
|
|
37
41
|
});
|
|
38
42
|
|
|
39
43
|
describe('fake', () => {
|
|
@@ -48,6 +52,10 @@ describe('Phone', () => {
|
|
|
48
52
|
expect(fake.ddd).toBe('11');
|
|
49
53
|
});
|
|
50
54
|
|
|
55
|
+
test('Cria um fake com DDD inválido', () => {
|
|
56
|
+
expect(() => Phone.fake({ ddd: '10' })).toThrow();
|
|
57
|
+
});
|
|
58
|
+
|
|
51
59
|
test.each([...Array(5)])('Cria um fake com isMobile=true', () => {
|
|
52
60
|
const fake = Phone.fake({ isMobile: true });
|
|
53
61
|
expect(fake).toBeDefined();
|
|
@@ -66,12 +74,12 @@ describe('Phone', () => {
|
|
|
66
74
|
describe('mask', () => {
|
|
67
75
|
test.each(cellPhones)('Máscara de celular sem país', (input) => {
|
|
68
76
|
const phone = new Phone(input);
|
|
69
|
-
expect(phone.mask({ withCountry: false })).toBe('84
|
|
77
|
+
expect(phone.mask({ withCountry: false })).toBe('84 999873456');
|
|
70
78
|
});
|
|
71
79
|
|
|
72
80
|
test.each(cellPhones)('Máscara de celular com país', (input) => {
|
|
73
81
|
const phone = new Phone(input);
|
|
74
|
-
expect(phone.mask({ withCountry: true })).toBe('+55 84
|
|
82
|
+
expect(phone.mask({ withCountry: true })).toBe('+55 84 999873456');
|
|
75
83
|
});
|
|
76
84
|
|
|
77
85
|
test.each(phones)('Máscara de telefone fixo sem país', (input) => {
|
|
@@ -84,4 +92,22 @@ describe('Phone', () => {
|
|
|
84
92
|
expect(phone.mask({ withCountry: true })).toBe('+55 84 33311454');
|
|
85
93
|
});
|
|
86
94
|
});
|
|
95
|
+
|
|
96
|
+
describe('checksum', () => {
|
|
97
|
+
expect(() => Phone.checksum()).toThrow()
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
describe('toString', () => {
|
|
101
|
+
test.each([...phones, ...cellPhones])('Deve exibir o valor sem o caracteres especiais', (input) => {
|
|
102
|
+
const phone = new Phone(input);
|
|
103
|
+
const cleared = phone.value.replace(/[()\s-]+/g, '');
|
|
104
|
+
|
|
105
|
+
expect(phone.toString()).toBe(cleared)
|
|
106
|
+
expect(phone.toString()).toHaveLength(cleared.length)
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
expect(phone.value).toBe(cleared)
|
|
110
|
+
expect(phone.value).toHaveLength(cleared.length)
|
|
111
|
+
});
|
|
112
|
+
});
|
|
87
113
|
});
|
package/test/pis-pasep.spec.ts
CHANGED
|
@@ -70,4 +70,23 @@ describe('PIS', () => {
|
|
|
70
70
|
}
|
|
71
71
|
);
|
|
72
72
|
});
|
|
73
|
+
|
|
74
|
+
describe('toString', () => {
|
|
75
|
+
test.each([
|
|
76
|
+
{ input: '71282677380', expected: '71282677380', },
|
|
77
|
+
{ input: '23795126955', expected: '23795126955', },
|
|
78
|
+
{ input: '50012973803', expected: '50012973803', },
|
|
79
|
+
{ input: '27890141144', expected: '27890141144', },
|
|
80
|
+
{ input: '268.27649.96-0', expected: '26827649960', },
|
|
81
|
+
{ input: '613.01862.91-7', expected: '61301862917', },
|
|
82
|
+
])('Deve exibir o valor sem o caracteres especiais', (item) => {
|
|
83
|
+
const pis = new PIS(item.input);
|
|
84
|
+
|
|
85
|
+
expect(pis.toString()).toBe(item.expected);
|
|
86
|
+
expect(pis.toString()).toHaveLength(11);
|
|
87
|
+
|
|
88
|
+
expect(pis.value).toBe(item.expected);
|
|
89
|
+
expect(pis.value).toHaveLength(11);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
73
92
|
});
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// pix usado pelo 10 pila.
|
|
2
2
|
|
|
3
|
-
import { PixCopyPaste } from '../src/pix-copy-paste';
|
|
3
|
+
import { PixCopyPaste, PixPart } from '../src/pix-copy-paste';
|
|
4
4
|
|
|
5
5
|
// esse pix é um pix automatico
|
|
6
6
|
const pixStone = `00020101021226820014br.gov.bcb.pix2560pix.stone.com.br/pix/v2/b411f5c8-e97f-4a18-af0e-fc66491748d7520400005303986540510.005802BR5925DIOGO DA SILVA SANTOS LTD6014RIO DE JANEIRO622905251e3afd7926983f8ffe086cdc16304FF60`;
|
|
7
7
|
const pixManual = `00020126550014BR.GOV.BCB.PIX0123alexandrepato@gmail.com0206almoco5204000053039865406100.005802BR5914Alexandre Pato6009Ipanguacu61085950800062490511PIXJS76657250300017BR.GOV.BCB.BRCODE01051.0.0630455CF`;
|
|
8
8
|
|
|
9
9
|
const cases = [
|
|
10
|
-
pixStone,
|
|
10
|
+
pixStone,
|
|
11
11
|
pixManual
|
|
12
12
|
]
|
|
13
13
|
|
|
@@ -18,19 +18,39 @@ describe('PixCopyPaste', () => {
|
|
|
18
18
|
const pix = new PixCopyPaste(input);
|
|
19
19
|
expect(pix).toBeDefined();
|
|
20
20
|
});
|
|
21
|
-
|
|
21
|
+
|
|
22
22
|
test('deve lançar um erro ao injetar um caractere na terceira posição', () => {
|
|
23
23
|
const copyPaste = pixStone.slice(0, 4) + 'D' + pixStone.slice(4);
|
|
24
|
-
expect(()=>new PixCopyPaste(copyPaste)).toThrow()
|
|
24
|
+
expect(() => new PixCopyPaste(copyPaste)).toThrow()
|
|
25
25
|
});
|
|
26
26
|
});
|
|
27
27
|
|
|
28
|
-
describe('
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
describe('PixPart', () => {
|
|
29
|
+
describe('parse', () => {
|
|
30
|
+
test.each(cases)('testa o parse', (input) => {
|
|
31
|
+
const parse = PixPart.parse(input);
|
|
32
|
+
|
|
33
|
+
expect(parse).toBeDefined();
|
|
34
|
+
expect(Array.isArray(parse)).toBeTruthy();
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe('getPart', () => {
|
|
39
|
+
test.each([
|
|
40
|
+
'', // vazio
|
|
41
|
+
'123', // menos de 3 números
|
|
42
|
+
'acvs', // não começa com 4 números
|
|
43
|
+
|
|
44
|
+
])('deve retornar um valor padrão', (part) => {
|
|
45
|
+
const expected = { part, code: '', size: 0, value: '', rest: part, children: [] }
|
|
46
|
+
expect(PixPart.getPart(part)).toMatchObject(expected);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test.each([
|
|
50
|
+
'0002a', // a partir do quinto valor não tem o mesmo tamanho definido nas posições 3 e 4
|
|
51
|
+
])('deve retornar um erro', (part) => {
|
|
52
|
+
expect(() => PixPart.getPart(part)).toThrow();
|
|
53
|
+
});
|
|
34
54
|
});
|
|
35
55
|
});
|
|
36
56
|
});
|
package/test/pix-key.spec.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PixKey, PixKeys } from '../src/pix-key';
|
|
2
2
|
|
|
3
|
-
describe('
|
|
3
|
+
describe('PixKey', () => {
|
|
4
4
|
describe('constructor', () => {
|
|
5
5
|
test('deve estar definido do tipo e-mail', () => {
|
|
6
6
|
const key = new PixKey('klawdyo@gmail.com');
|
|
@@ -35,7 +35,41 @@ describe('Pix', () => {
|
|
|
35
35
|
test('deve falhar ao receber um telefone inválido', () => {
|
|
36
36
|
expect(() => new PixKey('+55849876')).toThrow()
|
|
37
37
|
});
|
|
38
|
+
});
|
|
38
39
|
|
|
40
|
+
describe('Máscara', () => {
|
|
41
|
+
test('Deve retornar o mesmo valor', () => {
|
|
42
|
+
const input = 'klawdyo@gmail.com';
|
|
43
|
+
// const masked =
|
|
44
|
+
expect(new PixKey(input).mask()).toBe(input);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe('Fake', () => {
|
|
49
|
+
test('Deve retornar um valor fake que é um email', () => {
|
|
50
|
+
const value = PixKey.fake({ type: PixKeys.email });
|
|
51
|
+
expect(value.type).toBe(PixKeys.email);
|
|
52
|
+
});
|
|
53
|
+
test('Deve retornar um valor fake que é um cpf', () => {
|
|
54
|
+
const value = PixKey.fake({ type: PixKeys.cpf });
|
|
55
|
+
expect(value.type).toBe(PixKeys.cpf);
|
|
56
|
+
});
|
|
57
|
+
test('Deve retornar um valor fake que é um cnpj', () => {
|
|
58
|
+
const value = PixKey.fake({ type: PixKeys.cnpj });
|
|
59
|
+
expect(value.type).toBe(PixKeys.cnpj);
|
|
60
|
+
});
|
|
61
|
+
test('Deve retornar um valor fake que é um phone', () => {
|
|
62
|
+
const value = PixKey.fake({ type: PixKeys.phone });
|
|
63
|
+
expect(value.type).toBe(PixKeys.phone);
|
|
64
|
+
});
|
|
65
|
+
test('Deve retornar um valor fake que é um evp', () => {
|
|
66
|
+
const value = PixKey.fake({ type: PixKeys.evp });
|
|
67
|
+
expect(value.type).toBe(PixKeys.evp);
|
|
68
|
+
});
|
|
39
69
|
|
|
70
|
+
test.each([...Array(100)])('Deve criar uma chave fake válida', () => {
|
|
71
|
+
const value = PixKey.fake().toString();
|
|
72
|
+
expect(new PixKey(value)).toBeDefined();
|
|
73
|
+
});
|
|
40
74
|
});
|
|
41
75
|
});
|