qqlib-node-boleto 1.0.11

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.
Files changed (47) hide show
  1. package/.editorconfig +11 -0
  2. package/.eslintignore +1 -0
  3. package/.eslintrc +10 -0
  4. package/.idea/encodings.xml +4 -0
  5. package/.idea/modules.xml +8 -0
  6. package/.idea/node-boleto.git_master.iml +8 -0
  7. package/.idea/vcs.xml +7 -0
  8. package/LICENSE +20 -0
  9. package/README.md +92 -0
  10. package/assets/layout.ejs +433 -0
  11. package/banks/banco do brasil/index.js +172 -0
  12. package/banks/bradesco/index.js +154 -0
  13. package/banks/caixa/index.js +66 -0
  14. package/banks/santander/helper.js +3 -0
  15. package/banks/santander/index.js +145 -0
  16. package/examples/bradesco-edi.js +6 -0
  17. package/examples/bradesco-emission.js +35 -0
  18. package/examples/retorno.txt +8 -0
  19. package/examples/santander-edi.js +6 -0
  20. package/examples/santander-emission.js +32 -0
  21. package/index.js +12 -0
  22. package/lib/barcode.js +93 -0
  23. package/lib/boleto.js +105 -0
  24. package/lib/edi-helper.js +13 -0
  25. package/lib/edi-parser.js +7 -0
  26. package/lib/formatters.js +109 -0
  27. package/package.json +30 -0
  28. package/public/images/b.png +0 -0
  29. package/public/images/bb.png +0 -0
  30. package/public/images/bradesco.jpg +0 -0
  31. package/public/images/santander.png +0 -0
  32. package/public/images/w.png +0 -0
  33. package/readme.will.md +11 -0
  34. package/sonar-project.properties +9 -0
  35. package/test/e2e/boleto-output.js +420 -0
  36. package/test/e2e/boleto-render.spec.js +104 -0
  37. package/test/integration/bradesco/boleto.spec.js +216 -0
  38. package/test/integration/bradesco/edi.spec.js +113 -0
  39. package/test/integration/caixa/edi.spec.js +99 -0
  40. package/test/integration/santander/boleto.spec.js +45 -0
  41. package/test/integration/santander/edi.spec.js +73 -0
  42. package/test/mocks/banks.js +13 -0
  43. package/test/mocks/boleto-2018-10-31.js +25 -0
  44. package/test/mocks/boleto-2018-11-09.js +25 -0
  45. package/test/unit/boleto-object.spec.js +134 -0
  46. package/test/unit/boleto-render.spec.js +34 -0
  47. package/test/unit/formatters.spec.js +62 -0
@@ -0,0 +1,113 @@
1
+ const chai = require('chai')
2
+ chai.use(require('chai-subset'))
3
+ chai.use(require('chai-datetime'))
4
+ const expect = chai.expect
5
+
6
+ const ediParser = require('../../../index').EdiParser
7
+
8
+ const ediFileContent = `
9
+ 02RETORNO01COBRANCA 00000000000004628596PAGAR.ME PAGAMENTOS S.A. 237BRADESCO 2005160160000000001 220514 000001
10
+ 1021872705300017400000250122900004693 000000000000000000600000000000000000000000000506200516 00000000000000000000000000000000000150034103830 000000000000000000000000000000000000100000000000020000000000003000000000000400000000000010000000000005000000000000600 210516 00000000000000 000002
11
+ 1021872705300017400000260122900004693 00000000000278613362000000000000000000000000060610041927861336 00000000000278613362090419000000000060934100262 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000071400000000001050000000000000 110419 00000000000000 152328
12
+ 9201237 000000010000000000150000000001 00000000000000000000000000500000010000000005000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000 000003`
13
+
14
+ describe('Bradesco EDI Parser', () => {
15
+ describe('when parsing a valid EDI file', () => {
16
+ let result
17
+ let boleto
18
+ let boleto2
19
+ before(() => {
20
+ result = ediParser.parse('bradesco', ediFileContent)
21
+ boleto = result.boletos[0]
22
+ boleto2 = result.boletos[1]
23
+ })
24
+
25
+ it('should have found 2 boletos', () => {
26
+ expect(result.boletos).to.have.lengthOf(2)
27
+ })
28
+
29
+ it('should parse boleto correctly', () => {
30
+ expect(boleto).to.containSubset({
31
+ codigo_ocorrencia: '06',
32
+ motivos_ocorrencia: [
33
+ '00',
34
+ '00',
35
+ '00',
36
+ '00',
37
+ '00'
38
+ ],
39
+ valor_pago: '100',
40
+ valor: '1500',
41
+ juros_operacao_em_atraso: '100',
42
+ iof_devido: '200',
43
+ abatimento_concedido: '300',
44
+ desconto_concedido: '400',
45
+ juros_mora: '500',
46
+ outros_creditos: '600',
47
+ banco_recebedor: '341',
48
+ agencia_recebedora: '3830',
49
+ paid: true,
50
+ edi_line_number: 2,
51
+ edi_line_checksum: '20c5b6ebeb167ffb24ebe64316a3433a193de0bf',
52
+ edi_line_fingerprint: '2:20c5b6ebeb167ffb24ebe64316a3433a193de0bf',
53
+ nosso_numero: '6',
54
+ raw_line: '1021872705300017400000250122900004693 000000000000000000600000000000000000000000000506200516 00000000000000000000000000000000000150034103830 000000000000000000000000000000000000100000000000020000000000003000000000000400000000000010000000000005000000000000600 210516 00000000000000 000002'
55
+ })
56
+ })
57
+
58
+ it('should parse boleto2 correctly', () => {
59
+ expect(boleto2).to.containSubset({
60
+ codigo_ocorrencia: '06',
61
+ motivos_ocorrencia: [
62
+ '00',
63
+ '00',
64
+ '00',
65
+ '00',
66
+ '00'
67
+ ],
68
+ valor_pago: '714',
69
+ valor: '609',
70
+ juros_operacao_em_atraso: '',
71
+ iof_devido: '',
72
+ abatimento_concedido: '',
73
+ desconto_concedido: '',
74
+ juros_mora: '105',
75
+ outros_creditos: '',
76
+ banco_recebedor: '341',
77
+ agencia_recebedora: '262',
78
+ paid: true,
79
+ edi_line_number: 3,
80
+ edi_line_checksum: '686bf39b5d6533b49466e78391d1eeb593cb0db4',
81
+ edi_line_fingerprint: '3:686bf39b5d6533b49466e78391d1eeb593cb0db4',
82
+ nosso_numero: '27861336',
83
+ raw_line: '1021872705300017400000260122900004693 00000000000278613362000000000000000000000000060610041927861336 00000000000278613362090419000000000060934100262 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000071400000000001050000000000000 110419 00000000000000 152328'
84
+ })
85
+ })
86
+
87
+ it('should parse boleto data_ocorrencia correctly', () => {
88
+ expect(boleto.data_ocorrencia).to.equalDate(new Date(2016, 4, 20))
89
+ })
90
+
91
+ it('should parse boleto data_credito correctly', () => {
92
+ expect(boleto.data_credito).to.equalDate(new Date(2016, 4, 21))
93
+ })
94
+
95
+ it('should parse boleto vencimento correctly', () => {
96
+ expect(boleto.vencimento).to.equalDate(new Date(2016, 4, 20))
97
+ })
98
+
99
+ it('should parse EDI properties correctly', () => {
100
+ expect(result).to.containSubset({
101
+ razao_social: 'PAGAR.ME PAGAMENTOS S.A. ',
102
+ cnpj: '18727053000174',
103
+ carteira: '26',
104
+ agencia_cedente: '1229',
105
+ conta_cedente: '4693'
106
+ })
107
+
108
+ it('should parse EDI dates correctly', () => {
109
+ expect(result.data_arquivo).to.equalDate(new Date(2016, 4, 20))
110
+ })
111
+ })
112
+ })
113
+ })
@@ -0,0 +1,99 @@
1
+ const chai = require('chai')
2
+ chai.use(require('chai-subset'))
3
+ chai.use(require('chai-datetime'))
4
+ const expect = chai.expect
5
+
6
+ const ediParser = require('../../../index').EdiParser
7
+
8
+ const ediFileContent = `
9
+ 02RETORNO01COBRANCA 33371103388 PAGAR.ME PAGAMENTOS S.A. 104C ECON FEDERAL 010221 007 00035000001
10
+ 10218727053000174 110338820 73110483 14000000073110483 012101022173110483 080221000000000011310408575090000000000115004101020221 0000000000000000000000000000000000000000000000000113000000000000000000000000001020221 000002
11
+ 10218727053000174 110338820 14000000073110483 010101022173110483 080221000000000011310400235090000000000000000000010221 0000000000000000000000000000000000000000000000000000000000000000000000000000001000000 000003
12
+ 10000000000000000 110338800 00000000000000000 0234010221 000000000000000000010400000090000000000000000000010221 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000 000004
13
+ 9201104 000005`
14
+
15
+ describe('Caixa EDI Parser', () => {
16
+ describe('when parsing a valid EDI file', () => {
17
+ let result
18
+ let boleto
19
+ let boleto2
20
+ before(() => {
21
+ result = ediParser.parse('caixa', ediFileContent)
22
+ boleto = result.boletos[0]
23
+ boleto2 = result.boletos[1]
24
+ })
25
+
26
+ it('should have found 2 boletos', () => {
27
+ expect(result.boletos).to.have.lengthOf(2)
28
+ })
29
+
30
+ it('should parse boleto correctly', () => {
31
+ expect(boleto).to.containSubset({
32
+ codigo_ocorrencia: '21',
33
+ motivos_ocorrencia: '',
34
+ valor_pago: '113',
35
+ valor: '113',
36
+ iof_devido: '',
37
+ abatimento_concedido: '',
38
+ desconto_concedido: '',
39
+ juros_mora: '',
40
+ outros_creditos: '',
41
+ banco_recebedor: '104',
42
+ agencia_recebedora: '8575',
43
+ paid: true,
44
+ edi_line_number: 2,
45
+ edi_line_checksum: '63b840504d94be3e264437f18a90ed7cd79ce4ed',
46
+ edi_line_fingerprint: '2:63b840504d94be3e264437f18a90ed7cd79ce4ed',
47
+ nosso_numero: '73110483',
48
+ raw_line: '10218727053000174 110338820 73110483 14000000073110483 012101022173110483 080221000000000011310408575090000000000115004101020221 0000000000000000000000000000000000000000000000000113000000000000000000000000001020221 000002'
49
+ })
50
+ })
51
+
52
+ it('should parse boleto2 correctly', () => {
53
+ expect(boleto2).to.containSubset({
54
+ codigo_ocorrencia: '01',
55
+ motivos_ocorrencia: '',
56
+ valor_pago: '',
57
+ valor: '113',
58
+ iof_devido: '',
59
+ abatimento_concedido: '',
60
+ desconto_concedido: '',
61
+ juros_mora: '',
62
+ outros_creditos: '',
63
+ banco_recebedor: '104',
64
+ agencia_recebedora: '235',
65
+ paid: false,
66
+ edi_line_number: 3,
67
+ edi_line_checksum: '1cab47fa2079068396aa5a3b1c4ccec59d1880be',
68
+ edi_line_fingerprint: '3:1cab47fa2079068396aa5a3b1c4ccec59d1880be',
69
+ nosso_numero: '73110483',
70
+ raw_line: '10218727053000174 110338820 14000000073110483 010101022173110483 080221000000000011310400235090000000000000000000010221 0000000000000000000000000000000000000000000000000000000000000000000000000000001000000 000003'
71
+ })
72
+ })
73
+
74
+ it('should parse boleto data_ocorrencia correctly', () => {
75
+ expect(boleto.data_ocorrencia).to.equalDate(new Date(2021, 1, 1))
76
+ })
77
+
78
+ it('should parse boleto data_credito correctly', () => {
79
+ expect(boleto.data_credito).to.equalDate(new Date(2021, 1, 2))
80
+ })
81
+
82
+ it('should parse boleto vencimento correctly', () => {
83
+ expect(boleto.vencimento).to.equalDate(new Date(2021, 1, 8))
84
+ })
85
+
86
+ it('should parse EDI properties correctly', () => {
87
+ expect(result).to.containSubset({
88
+ razao_social: 'PAGAR.ME PAGAMENTOS S.A. ',
89
+ cnpj: '18727053000174',
90
+ carteira: '1',
91
+ conta_cedente: '103388'
92
+ })
93
+
94
+ it('should parse EDI dates correctly', () => {
95
+ expect(result.data_arquivo).to.equalDate(new Date(2021, 1, 1))
96
+ })
97
+ })
98
+ })
99
+ })
@@ -0,0 +1,45 @@
1
+ const Boleto = require('../../../index').Boleto
2
+ const moment = require('moment')
3
+ const expect = require('chai').expect
4
+
5
+ describe('Santander Boleto', () => {
6
+ describe('when creating a valid boleto', () => {
7
+ let boleto
8
+ before(() => {
9
+ boleto = new Boleto({
10
+ 'banco': 'santander',
11
+ 'data_emissao': moment('2017-01-01T00:00:00Z'),
12
+ 'data_vencimento': moment('2017-01-05'),
13
+ 'valor': 1500,
14
+ 'nosso_numero': '6',
15
+ 'numero_documento': '1',
16
+ 'cedente': 'Pagar.me Pagamentos S/A',
17
+ 'cedente_cnpj': '18727053000174',
18
+ 'agencia': '1229',
19
+ 'codigo_cedente': '469',
20
+ 'carteira': '25',
21
+ 'pagador': 'Nome do pagador\nCPF: 000.000.000-00',
22
+ 'local_de_pagamento': 'PAGÁVEL EM QUALQUER BANCO ATÉ O VENCIMENTO.',
23
+ 'instrucoes': 'Sr. Caixa, aceitar o pagamento e não cobrar juros após o vencimento.'
24
+ })
25
+ })
26
+
27
+ it('contains correct bank options', () => {
28
+ expect(boleto.bank.options).to.have.property('logoURL').that.contains('santander.png')
29
+ expect(boleto.bank.options).to.have.property('codigo', '033')
30
+ })
31
+
32
+ it('contains correct codigo_banco', () => {
33
+ expect(boleto.codigo_banco).to.equal('033-7')
34
+ })
35
+
36
+ it('contains correct barcode_data', () => {
37
+ expect(boleto.barcode_data).to.equal('0339670300000001500900004690000000000060025')
38
+ })
39
+
40
+ it('contains correct linha_digitavel', () => {
41
+ expect(boleto.linha_digitavel).to.equal('03399.00003 46900.000004 00006.00254 6 70300000001500')
42
+ })
43
+ })
44
+ })
45
+
@@ -0,0 +1,73 @@
1
+ const chai = require('chai')
2
+ chai.use(require('chai-subset'))
3
+ chai.use(require('chai-datetime'))
4
+ const expect = chai.expect
5
+
6
+ const ediParser = require('../../../index').EdiParser
7
+
8
+ const ediFileContent = `
9
+ 03300000 2018727053000174397800130035168 006404154 PAGAR.ME PAGAMENTOS S/A BANCO SANTANDER (BRASIL) S/A 206032014 000003040
10
+ 03376751T01 040 2018727053000174006404154 397800130035168 PAGAR.ME PAGAMENTOS S/A 0000000306032014
11
+ 0337675300001T 17397800130035168 00000000002211 0603201400000000000030034103830 002000000000000000 01300351680000000000003000400000000
12
+ 0337675300002U 170000000000000000000000000000000000000000000000000000000000000000000000003000000000000003000000000000000000000000000000000603201407032014000000000000000000000000000 000
13
+ 0337675300003T 17397800130035168 00000000002301 0603201400000000000035034103830 002000000000000000 01300351680000000000003000400000000
14
+ 0337675300004U 170000000000000000000000000000000000000000000250000000000000000000000000003250000000000003250000000000000000000000000000000603201407032014000000000000000000000000000 000
15
+ 03376755 0000040000010000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000001
16
+ 03376759 000001000008
17
+ `
18
+
19
+ describe('Santander EDI Parser', () => {
20
+ describe('when parsing a valid EDI file', () => {
21
+ let result
22
+ before(() => {
23
+ result = ediParser.parse('santander', ediFileContent)
24
+ })
25
+
26
+ it('should yield correct EDI file properties', () => {
27
+ expect(result).to.containSubset({
28
+ cnpj: '018727053000174',
29
+ razao_social: 'PAGAR.ME PAGAMENTOS S/A ',
30
+ agencia_cedente: '3978',
31
+ conta_cedente: '0130035168'
32
+ })
33
+ })
34
+
35
+ it('should parse EDI dates correctly', () => {
36
+ expect(result.data_arquivo).to.equalDate(new Date(2014, 2, 6))
37
+ })
38
+
39
+ it('should parse boletos correctly', () => {
40
+ expect(result.boletos).to.containSubset({
41
+ 22: {
42
+ codigo_ocorrencia: '17',
43
+ valor: '300',
44
+ tarifa: '300',
45
+ banco_recebedor: '341',
46
+ agencia_recebedora: '3830',
47
+ valor_pago: '300',
48
+ pago: true,
49
+ edi_line_number: 4,
50
+ edi_line_checksum: 'ca06c2930a187fcf40bf5a86f0f7b0a7be334fae',
51
+ edi_line_fingerprint: '4:ca06c2930a187fcf40bf5a86f0f7b0a7be334fae'
52
+ },
53
+ 23: {
54
+ codigo_ocorrencia: '17',
55
+ valor: '350',
56
+ tarifa: '300',
57
+ banco_recebedor: '341',
58
+ agencia_recebedora: '3830',
59
+ valor_pago: '325',
60
+ pago: false,
61
+ edi_line_number: 6,
62
+ edi_line_checksum: '7b982a98589d0a51934a35a464db7a3a43ef30c6',
63
+ edi_line_fingerprint: '6:7b982a98589d0a51934a35a464db7a3a43ef30c6'
64
+ }
65
+ })
66
+ })
67
+
68
+ it('should parse boleto vencimentos correctly', () => {
69
+ expect(result.boletos['22'].vencimento).to.equalDate(new Date(2014, 2, 6))
70
+ expect(result.boletos['23'].vencimento).to.equalDate(new Date(2014, 2, 6))
71
+ })
72
+ })
73
+ })
@@ -0,0 +1,13 @@
1
+ const R = require('ramda')
2
+
3
+ module.exports = {
4
+ test: {
5
+ options: {
6
+ logoURL: 'https://pagar.me/img.png',
7
+ codigo: '123'
8
+ },
9
+ barcodeData: R.always('123'),
10
+ linhaDigitavel: R.always('123')
11
+ }
12
+ }
13
+
@@ -0,0 +1,25 @@
1
+ const moment = require('moment')
2
+ const testBanks = require('./banks')
3
+ const Boleto = require('../../lib/boleto')(testBanks)
4
+
5
+ const dataEmissao = moment(moment('2018-10-25 20:48:01.981+00').utc().format('YYYY-MM-DD')).valueOf()
6
+ const dataVencimento = moment(moment('2018-10-31 02:00:00+00').utc().format('YYYY-MM-DD')).valueOf()
7
+
8
+ const boletoOptions = {
9
+ banco: 'test',
10
+ cedente: 'SOGNI COMERCIO E SERVICO DIGITAL | Pagar.me Pagamentos S/A',
11
+ cedente_cnpj: '18727053000174',
12
+ agencia: '1229',
13
+ codigo_cedente: '469',
14
+ carteira: '26',
15
+ data_emissao: new Date(dataEmissao),
16
+ data_vencimento: new Date(dataVencimento),
17
+ valor: 1000,
18
+ nosso_numero: 20615808,
19
+ numero_documento: 20615808,
20
+ pagador: 'Abilio Cipriano',
21
+ local_de_pagamento: 'PAGÁVEL EM QUALQUER BANCO ATÉ O VENCIMENTO.',
22
+ instrucoes: 'teste'
23
+ }
24
+
25
+ module.exports = new Boleto(boletoOptions)
@@ -0,0 +1,25 @@
1
+ const moment = require('moment')
2
+ const testBanks = require('./banks')
3
+ const Boleto = require('../../lib/boleto')(testBanks)
4
+
5
+ const dataEmissao = moment(moment('2018-10-25 20:48:01.981+00').utc().format('YYYY-MM-DD')).valueOf()
6
+ const dataVencimento = moment(moment('2018-11-09 02:00:00+00').utc().format('YYYY-MM-DD')).valueOf()
7
+
8
+ const boletoOptions = {
9
+ banco: 'test',
10
+ cedente: 'SOGNI COMERCIO E SERVICO DIGITAL | Pagar.me Pagamentos S/A',
11
+ cedente_cnpj: '18727053000174',
12
+ agencia: '1229',
13
+ codigo_cedente: '469',
14
+ carteira: '26',
15
+ data_emissao: new Date(dataEmissao),
16
+ data_vencimento: new Date(dataVencimento),
17
+ valor: 1000,
18
+ nosso_numero: 20615808,
19
+ numero_documento: 20615808,
20
+ pagador: 'Abilio Cipriano',
21
+ local_de_pagamento: 'PAGÁVEL EM QUALQUER BANCO ATÉ O VENCIMENTO.',
22
+ instrucoes: 'teste'
23
+ }
24
+
25
+ module.exports = new Boleto(boletoOptions)
@@ -0,0 +1,134 @@
1
+ const R = require('ramda')
2
+ const moment = require('moment')
3
+
4
+ const chai = require('chai')
5
+ chai.use(require('chai-subset'))
6
+ chai.use(require('chai-datetime'))
7
+ const expect = chai.expect
8
+
9
+ const testBanks = require('../mocks/banks')
10
+ const Boleto = require('../../lib/boleto')(testBanks)
11
+
12
+ describe('Boleto Object', () => {
13
+ describe('when creating a boleto with no options', () => {
14
+ it('should error', () => {
15
+ expect(() => { new Boleto() }).to.throw('No options provided initializing Boleto.') // eslint-disable-line no-new
16
+ })
17
+ })
18
+
19
+ describe('when creating a boleto with invalid bank', () => {
20
+ it('should error', () => {
21
+ expect(() => { new Boleto({ banco: 'richardbank' }) }).to.throw('Invalid bank.') // eslint-disable-line no-new
22
+ })
23
+ })
24
+
25
+ describe('when creating a valid boleto with empty dates', () => {
26
+ const boletoOptions = {
27
+ 'banco': 'test',
28
+ 'valor': 1500,
29
+ 'nosso_numero': '6',
30
+ 'numero_documento': '1',
31
+ 'cedente': 'Pagar.me Pagamentos S/A',
32
+ 'cedente_cnpj': '18727053000174',
33
+ 'agencia': '1229',
34
+ 'codigo_cedente': '469',
35
+ 'carteira': '25',
36
+ 'pagador': 'Nome do pagador\nCPF: 000.000.000-00',
37
+ 'local_de_pagamento': 'PAGÁVEL EM QUALQUER BANCO ATÉ O VENCIMENTO.',
38
+ 'instrucoes': 'Sr. Caixa, aceitar o pagamento e não cobrar juros após o vencimento.\nTOP\n\nKEK'
39
+ }
40
+
41
+ let boleto
42
+ before(() => {
43
+ boleto = new Boleto(boletoOptions)
44
+ })
45
+
46
+ it('has current date as data_emissao', () => {
47
+ expect(moment(boleto.data_emissao).format()).to.be.equal(moment().utc().format())
48
+ })
49
+
50
+ it('has five days past data_emissao as data_vencimento', () => {
51
+ expect(moment(boleto.data_vencimento).format()).to.be.equal(moment().utc().add(5, 'days').format())
52
+ })
53
+ })
54
+
55
+ describe('when creating a boleto with empty payment location', () => {
56
+ const boletoOptions = {
57
+ 'banco': 'test',
58
+ 'data_emissao': new Date(),
59
+ 'data_vencimento': new Date(new Date().getTime() + 5 * 24 * 3600 * 1000),
60
+ 'valor': 1500,
61
+ 'nosso_numero': '6',
62
+ 'numero_documento': '1',
63
+ 'cedente': 'Pagar.me Pagamentos S/A',
64
+ 'cedente_cnpj': '18727053000174',
65
+ 'agencia': '1229',
66
+ 'codigo_cedente': '469',
67
+ 'carteira': '25',
68
+ 'pagador': 'Nome do pagador\nCPF: 000.000.000-00',
69
+ 'instrucoes': 'Sr. Caixa, aceitar o pagamento e não cobrar juros após o vencimento.\nTOP\n\nKEK'
70
+ }
71
+
72
+ let boleto
73
+ before(() => {
74
+ boleto = new Boleto(boletoOptions)
75
+ })
76
+
77
+ it('has default local_de_pagamento', () => {
78
+ expect(boleto.local_de_pagamento).to.equal('Até o vencimento, preferencialmente no Banco Test')
79
+ })
80
+ })
81
+
82
+ describe('when creating a valid boleto', () => {
83
+ const boletoOptions = {
84
+ 'banco': 'test',
85
+ 'data_emissao': new Date(),
86
+ 'data_vencimento': new Date(new Date().getTime() + 5 * 24 * 3600 * 1000),
87
+ 'valor': 1500,
88
+ 'nosso_numero': '6',
89
+ 'numero_documento': '1',
90
+ 'cedente': 'Pagar.me Pagamentos S/A',
91
+ 'cedente_cnpj': '18727053000174',
92
+ 'agencia': '1229',
93
+ 'codigo_cedente': '469',
94
+ 'carteira': '25',
95
+ 'pagador': 'Nome do pagador\nCPF: 000.000.000-00',
96
+ 'local_de_pagamento': 'PAGÁVEL EM QUALQUER BANCO ATÉ O VENCIMENTO.',
97
+ 'instrucoes': 'Sr. Caixa, aceitar o pagamento e não cobrar juros após o vencimento.\nTOP\n\nKEK'
98
+ }
99
+
100
+ let boleto
101
+ before(() => {
102
+ boleto = new Boleto(boletoOptions)
103
+ })
104
+
105
+ it('contains creation properties', () => {
106
+ expect(boleto).to.containSubset(R.omit(['pagador', 'instrucoes', 'data_emissao', 'data_vencimento'], boletoOptions))
107
+ })
108
+
109
+ it('contains formatted pagador', () => {
110
+ expect(boleto.pagador).to.equal('Nome do pagador<br/>CPF: 000.000.000-00')
111
+ })
112
+
113
+ it('contains formatted instrucoes', () => {
114
+ expect(boleto.instrucoes).to.equal('Sr. Caixa, aceitar o pagamento e não cobrar juros após o vencimento.<br/>TOP<br/><br/>KEK')
115
+ })
116
+
117
+ it('contains dates in options', () => {
118
+ expect(moment(boleto.data_emissao).format()).to.be.equal(moment(boletoOptions.data_emissao).format())
119
+ expect(moment(boleto.data_vencimento).format()).to.be.equal(moment(boleto.data_vencimento).format())
120
+ })
121
+
122
+ it('contains formatted nosso_numero_dv', () => {
123
+ expect(boleto.nosso_numero_dv).to.equal(0)
124
+ })
125
+
126
+ it('contains a bank object', () => {
127
+ expect(boleto).to.include.keys('bank')
128
+ })
129
+
130
+ it('contains calculated properties', () => {
131
+ expect(boleto).to.include.all.keys(['codigo_banco', 'barcode_data', 'linha_digitavel'])
132
+ })
133
+ })
134
+ })
@@ -0,0 +1,34 @@
1
+ const boletoMock20181109 = require('../mocks/boleto-2018-11-09')
2
+ const boletoMock20181031 = require('../mocks/boleto-2018-10-31')
3
+ const expect = require('chai').expect
4
+
5
+ describe('Boleto render', () => {
6
+ describe('boleto from 2018-11-09', () => {
7
+ let boletoHTML20181109, boletoHTML20181031
8
+ before(() => {
9
+ return new Promise((resolve, reject) => {
10
+ boletoMock20181109.renderHTML(function (html) {
11
+ boletoHTML20181109 = html
12
+ resolve(html)
13
+ })
14
+ })
15
+ })
16
+
17
+ before(() => {
18
+ return new Promise((resolve, reject) => {
19
+ boletoMock20181031.renderHTML(function (html) {
20
+ boletoHTML20181031 = html
21
+ resolve(html)
22
+ })
23
+ })
24
+ })
25
+
26
+ it('should have the expiration date as 09/11/2018', () => {
27
+ expect(boletoHTML20181109.includes('09/11/2018')).to.be.equal(true)
28
+ })
29
+
30
+ it('should have the expiration date as 31/10/2018', () => {
31
+ expect(boletoHTML20181031.includes('31/10/2018')).to.be.equal(true)
32
+ })
33
+ })
34
+ })
@@ -0,0 +1,62 @@
1
+ const { expect } = require('chai')
2
+
3
+ const { fatorVencimento } = require('../../lib/formatters')
4
+
5
+ describe('Formatters', () => {
6
+ describe('Fator de Vencimento', () => {
7
+ const dates = [
8
+ {
9
+ data_vencimento: '2025-01-01',
10
+ factor: '9948'
11
+ },
12
+ {
13
+ data_vencimento: '2025-01-01',
14
+ factor: '9948'
15
+ },
16
+ {
17
+ data_vencimento: '2025-02-20',
18
+ factor: '9998'
19
+ },
20
+ {
21
+ data_vencimento: '2025-02-21',
22
+ factor: '9999'
23
+ },
24
+ {
25
+ data_vencimento: '2025-02-22',
26
+ factor: '1000'
27
+ },
28
+ {
29
+ data_vencimento: '2025-02-23',
30
+ factor: '1001'
31
+ },
32
+ {
33
+ data_vencimento: '2025-12-31',
34
+ factor: '1312'
35
+ },
36
+ {
37
+ data_vencimento: '2027-11-18',
38
+ factor: '1999'
39
+ },
40
+ {
41
+ data_vencimento: '2027-11-19',
42
+ factor: '2000'
43
+ },
44
+ {
45
+ data_vencimento: '2039-04-27',
46
+ factor: '6177'
47
+ },
48
+ {
49
+ data_vencimento: '2049-10-13',
50
+ factor: '9999'
51
+ }
52
+ ]
53
+
54
+ dates.forEach((data) => {
55
+ it(`get the expected factor with the date '${data.data_vencimento}'`, () => {
56
+ const factorReceived = fatorVencimento(data.data_vencimento)
57
+
58
+ expect(factorReceived).to.be.equal(data.factor)
59
+ })
60
+ })
61
+ })
62
+ })