br_nfe 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +4 -1
- data/README.markdown +263 -1
- data/br_nfe.gemspec +14 -5
- data/lib/br_nfe/base.rb +6 -1
- data/lib/br_nfe/helper/cpf_cnpj.rb +0 -5
- data/lib/br_nfe/helper/have_address.rb +1 -5
- data/lib/br_nfe/helper/have_rps.rb +7 -0
- data/lib/br_nfe/servico/betha/base.rb +52 -41
- data/lib/br_nfe/servico/betha/build_response.rb +141 -0
- data/lib/br_nfe/servico/betha/v1/build_response.rb +4 -102
- data/lib/br_nfe/servico/betha/v1/consulta_lote_rps.rb +3 -1
- data/lib/br_nfe/servico/betha/v1/consulta_nfs_por_rps.rb +5 -2
- data/lib/br_nfe/servico/betha/v1/consulta_nfse.rb +2 -1
- data/lib/br_nfe/servico/betha/v1/gateway.rb +66 -56
- data/lib/br_nfe/servico/betha/v1/recepcao_lote_rps.rb +16 -8
- data/lib/br_nfe/servico/betha/v2/build_response.rb +159 -0
- data/lib/br_nfe/servico/betha/v2/cancelamento_nfs.rb +8 -3
- data/lib/br_nfe/servico/betha/v2/consulta_lote_rps.rb +7 -4
- data/lib/br_nfe/servico/betha/v2/consulta_nfse_por_rps.rb +5 -5
- data/lib/br_nfe/servico/betha/v2/envio_lote_rps_sincrono.rb +7 -3
- data/lib/br_nfe/servico/betha/v2/gateway.rb +79 -56
- data/lib/br_nfe/servico/betha/v2/gera_nfse.rb +8 -3
- data/lib/br_nfe/servico/betha/v2/recepcao_lote_rps.rb +9 -4
- data/lib/br_nfe/servico/betha/v2/substituicao_nfse.rb +8 -4
- data/lib/br_nfe/servico/response/nota_fiscal.rb +13 -4
- data/lib/br_nfe/servico/rps.rb +2 -2
- data/lib/br_nfe/version.rb +1 -1
- data/lib/br_nfe.rb +2 -1
- data/test/br_nfe/base_test.rb +55 -1
- data/test/br_nfe/destinatario_test.rb +19 -0
- data/test/br_nfe/emitente_test.rb +20 -0
- data/test/br_nfe/endereco_test.rb +9 -0
- data/test/br_nfe/helper/cpf_cnpj_test.rb +61 -0
- data/test/br_nfe/servico/base_test.rb +28 -0
- data/test/br_nfe/servico/betha/base_test.rb +61 -32
- data/test/br_nfe/servico/betha/v1/build_response_test.rb +6 -7
- data/test/br_nfe/servico/betha/v1/cancelamento_nfs_test.rb +6 -0
- data/test/br_nfe/servico/betha/v1/consulta_lote_rps_test.rb +4 -0
- data/test/br_nfe/servico/betha/v1/consulta_nfse_test.rb +17 -0
- data/test/br_nfe/servico/betha/v1/gateway_test.rb +17 -40
- data/test/br_nfe/servico/betha/v1/recepcao_lote_rps_test.rb +12 -2
- data/test/br_nfe/servico/betha/v2/cancelamento_nfs_test.rb +40 -0
- data/test/br_nfe/servico/betha/v2/consulta_lote_rps_test.rb +38 -0
- data/test/br_nfe/servico/betha/v2/consulta_nfse_por_rps_test.rb +36 -0
- data/test/br_nfe/servico/betha/v2/envio_lote_rps_sincrono_test.rb +46 -0
- data/test/br_nfe/servico/betha/v2/gateway_test.rb +372 -0
- data/test/br_nfe/servico/betha/v2/gera_nfse_test.rb +58 -0
- data/test/br_nfe/servico/betha/v2/recepcao_lote_rps_test.rb +103 -0
- data/test/br_nfe/servico/betha/v2/substituicao_nfse_test.rb +80 -0
- data/test/br_nfe/servico/intermediario_test.rb +16 -0
- data/test/br_nfe/servico/rps_test.rb +141 -0
- data/test/factories/servico/betha/v1/gateway.rb +1 -1
- data/test/factories/servico/betha/v2/cancelamento_nfs.rb +7 -0
- data/test/factories/servico/betha/v2/consulta_lote_rps.rb +6 -0
- data/test/factories/servico/betha/v2/consulta_nfse_por_rps.rb +6 -0
- data/test/factories/servico/betha/v2/envio_lote_rps_sincrono.rb +5 -0
- data/test/factories/servico/betha/v2/gateway.rb +5 -0
- data/test/factories/servico/betha/v2/gera_nfse.rb +6 -0
- data/test/factories/servico/betha/v2/recepcao_lote_rps.rb +5 -0
- data/test/factories/servico/betha/v2/substituicao_nfse.rb +8 -0
- metadata +50 -17
- data/Gemfile +0 -15
- data/Rakefile +0 -13
- data/lib/br_nfe/seed.rb +0 -195
- data/lib/br_nfe/servico/betha/v2/response.rb +0 -23
- data/test/certificado.rb +0 -12
- data/test/test_helper.rb +0 -39
@@ -4,12 +4,11 @@ describe BrNfe::Servico::Betha::Base do
|
|
4
4
|
subject { FactoryGirl.build(:br_nfe_servico_betha_base) }
|
5
5
|
let(:rps) { FactoryGirl.build(:br_nfe_rps) }
|
6
6
|
let(:destinatario) { FactoryGirl.build(:destinatario) }
|
7
|
+
let(:endereco) { FactoryGirl.build(:endereco) }
|
7
8
|
|
8
|
-
describe "#
|
9
|
+
describe "#xml_identificacao_rps" do
|
9
10
|
it "deve vir com a estrutura adecuada" do
|
10
|
-
xml =
|
11
|
-
subject.send(:tag_identificacao_rps, xml, rps)
|
12
|
-
end.doc
|
11
|
+
xml = subject.send(:xml_identificacao_rps, rps).doc
|
13
12
|
|
14
13
|
xml.xpath('IdentificacaoRps/Numero').first.text.must_equal "#{rps.numero}"
|
15
14
|
xml.xpath('IdentificacaoRps/Serie').first.text.must_equal "#{rps.serie}"
|
@@ -17,28 +16,73 @@ describe BrNfe::Servico::Betha::Base do
|
|
17
16
|
end
|
18
17
|
end
|
19
18
|
|
20
|
-
describe "#
|
19
|
+
describe "#xml_rps_substituido" do
|
21
20
|
before do
|
22
21
|
rps.numero_substituicao = 333
|
23
22
|
rps.serie_substituicao = 5
|
24
23
|
rps.tipo_substituicao = 9
|
25
24
|
end
|
26
25
|
it "deve vir com a estrutura adecuada" do
|
27
|
-
xml =
|
28
|
-
subject.send(:tag_rps_substituido, xml, rps)
|
29
|
-
end.doc
|
26
|
+
xml = subject.send(:xml_rps_substituido, rps).doc
|
30
27
|
|
31
28
|
xml.xpath('RpsSubstituido/Numero').first.text.must_equal "333"
|
32
29
|
xml.xpath('RpsSubstituido/Serie').first.text.must_equal "5"
|
33
30
|
xml.xpath('RpsSubstituido/Tipo').first.text.must_equal "9"
|
34
31
|
end
|
32
|
+
|
33
|
+
it "se rps contem_substituicao deve retornar um html vazio" do
|
34
|
+
rps.expects(:contem_substituicao?).returns(false)
|
35
|
+
xml = subject.send(:xml_rps_substituido, rps).doc.root.to_s.must_equal ''
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#xml_endereco" do
|
40
|
+
before do
|
41
|
+
endereco.assign_attributes({
|
42
|
+
logradouro: 'á'.rjust(130, 'á'),
|
43
|
+
numero: '2'.rjust(100, '2'),
|
44
|
+
complemento: 'õ'.rjust(100, 'õ'),
|
45
|
+
bairro: 'ê'.rjust(100, 'ê'),
|
46
|
+
codigo_municipio: '123456789'.rjust(100, 'A'),
|
47
|
+
uf: 'ABCDE',
|
48
|
+
cep: '123-4567-89-60',
|
49
|
+
codigo_pais: '123456AAAA'
|
50
|
+
})
|
51
|
+
end
|
52
|
+
it "valores padroes" do
|
53
|
+
xml = subject.send(:xml_endereco, endereco).doc
|
54
|
+
xml.xpath('Endereco/Endereco').first.text.must_equal "A".rjust(125, 'A')
|
55
|
+
xml.xpath('Endereco/Numero').first.text.must_equal "2".rjust(10, '2')
|
56
|
+
xml.xpath('Endereco/Complemento').first.text.must_equal "O".rjust(60, 'O')
|
57
|
+
xml.xpath('Endereco/Bairro').first.text.must_equal "E".rjust(60, 'E')
|
58
|
+
xml.xpath('Endereco/CodigoMunicipio').first.text.must_equal "1234567"
|
59
|
+
xml.xpath('Endereco/Uf').first.text.must_equal "AB"
|
60
|
+
xml.xpath('Endereco/Cep').first.text.must_equal '12345678'
|
61
|
+
xml.xpath('Endereco/CodigoPais').first.must_be_nil
|
62
|
+
end
|
63
|
+
|
64
|
+
it "se for versao 1 e mandar o codigo_pais como true deve ignorar" do
|
65
|
+
subject.stubs(:version).returns(:v1)
|
66
|
+
xml = subject.send(:xml_endereco, endereco, true).doc
|
67
|
+
xml.xpath('Endereco/CodigoPais').first.must_be_nil
|
68
|
+
end
|
69
|
+
|
70
|
+
it "se for versao 2 e mandar o codigo_pais como true deve trazer junto o codigo do pais" do
|
71
|
+
subject.stubs(:version).returns(:v2)
|
72
|
+
xml = subject.send(:xml_endereco, endereco, true).doc
|
73
|
+
xml.xpath('Endereco/CodigoPais').first.text.must_equal '1234'
|
74
|
+
end
|
75
|
+
|
76
|
+
it "se for versao 2 e mandar o codigo_pais como false não deve trazer o codigo do pais" do
|
77
|
+
subject.stubs(:version).returns(:v2)
|
78
|
+
xml = subject.send(:xml_endereco, endereco, false).doc
|
79
|
+
xml.xpath('Endereco/CodigoPais').first.must_be_nil
|
80
|
+
end
|
35
81
|
end
|
36
82
|
|
37
|
-
describe "#
|
83
|
+
describe "#xml_dados_tomador" do
|
38
84
|
it "Valores padrões indiferentemente da versao" do
|
39
|
-
xml =
|
40
|
-
subject.send(:tag_dados_tomador, xml, destinatario)
|
41
|
-
end.doc
|
85
|
+
xml = subject.send(:xml_dados_tomador, destinatario).doc
|
42
86
|
|
43
87
|
xml.xpath('Tomador/RazaoSocial').first.text.must_equal destinatario.razao_social
|
44
88
|
xml.xpath('Tomador/IdentificacaoTomador/CpfCnpj/Cpf').first.text.must_equal BrNfe::Helper::CpfCnpj.new(destinatario.cpf_cnpj).sem_formatacao
|
@@ -64,40 +108,25 @@ describe BrNfe::Servico::Betha::Base do
|
|
64
108
|
subject.stubs(:version).returns(:v1)
|
65
109
|
end
|
66
110
|
it "inscricao_estadual" do
|
67
|
-
xml =
|
68
|
-
subject.send(:tag_dados_tomador, xml, destinatario)
|
69
|
-
end.doc
|
111
|
+
xml = subject.send(:xml_dados_tomador, destinatario).doc
|
70
112
|
xml.xpath('Tomador/IdentificacaoTomador/InscricaoEstadual').first.text.must_equal destinatario.inscricao_estadual
|
71
113
|
end
|
72
114
|
end
|
73
|
-
|
74
115
|
end
|
75
116
|
|
76
|
-
describe "#
|
117
|
+
describe "#xml_dados_construcao_civil" do
|
77
118
|
it "quando rps não tem codigo_obra" do
|
78
119
|
rps.assign_attributes(codigo_obra: '', codigo_art: '366')
|
79
|
-
xml =
|
80
|
-
subject.send(:tag_dados_construcao_civil, xml, rps)
|
81
|
-
end.doc
|
82
|
-
xml.xpath('ConstrucaoCivil/CodigoObra').first.must_be_nil
|
83
|
-
xml.xpath('ConstrucaoCivil/Art').first.must_be_nil
|
84
|
-
xml.to_s.must_equal "<?xml version=\"1.0\"?>\n"
|
120
|
+
xml = subject.send(:xml_dados_construcao_civil, rps).doc.root.to_s.must_equal ''
|
85
121
|
end
|
86
122
|
it "quando rps não tem codigo_art" do
|
87
123
|
rps.assign_attributes(codigo_obra: '13', codigo_art: '')
|
88
|
-
xml =
|
89
|
-
subject.send(:tag_dados_construcao_civil, xml, rps)
|
90
|
-
end.doc
|
91
|
-
xml.xpath('ConstrucaoCivil/CodigoObra').first.must_be_nil
|
92
|
-
xml.xpath('ConstrucaoCivil/Art').first.must_be_nil
|
93
|
-
xml.to_s.must_equal "<?xml version=\"1.0\"?>\n"
|
124
|
+
xml = subject.send(:xml_dados_construcao_civil, rps).doc.root.to_s.must_equal ''
|
94
125
|
end
|
95
126
|
|
96
127
|
it "quando rps tem codigo_art e codigo_obra" do
|
97
128
|
rps.assign_attributes(codigo_obra: '13', codigo_art: '555')
|
98
|
-
xml =
|
99
|
-
subject.send(:tag_dados_construcao_civil, xml, rps)
|
100
|
-
end.doc
|
129
|
+
xml = subject.send(:xml_dados_construcao_civil, rps).doc
|
101
130
|
xml.xpath('ConstrucaoCivil/CodigoObra').first.text.must_equal '13'
|
102
131
|
xml.xpath('ConstrucaoCivil/Art').first.text.must_equal '555'
|
103
132
|
end
|
@@ -13,12 +13,12 @@ describe BrNfe::Servico::Betha::V1::BuildResponse do
|
|
13
13
|
|
14
14
|
describe "#success?" do
|
15
15
|
it "deve ser true quanto não tem mensagem de retorno" do
|
16
|
-
subject.stubs(:
|
16
|
+
subject.stubs(:error_messages).returns([])
|
17
17
|
subject.success?.must_equal true
|
18
18
|
end
|
19
19
|
|
20
20
|
it "deve ser false quanto tem alguma mensagem de retorno" do
|
21
|
-
subject.stubs(:
|
21
|
+
subject.stubs(:error_messages).returns([{codigo: '1'}])
|
22
22
|
subject.success?.must_equal false
|
23
23
|
end
|
24
24
|
end
|
@@ -38,11 +38,7 @@ describe BrNfe::Servico::Betha::V1::BuildResponse do
|
|
38
38
|
subject.instance_variable_set(:@error_messages, [123])
|
39
39
|
subject.error_messages.must_equal([123])
|
40
40
|
end
|
41
|
-
|
42
|
-
subject.stubs(:success?).returns(true)
|
43
|
-
subject.error_messages.must_equal([])
|
44
|
-
end
|
45
|
-
|
41
|
+
|
46
42
|
it "deve retornar um vetor com um hash com as mensagens quando houver apenas 1 mensagem em um hash" do
|
47
43
|
subject.error_messages.size.must_equal 1
|
48
44
|
subject.error_messages.class.must_equal Array
|
@@ -104,6 +100,7 @@ describe BrNfe::Servico::Betha::V1::BuildResponse do
|
|
104
100
|
nota_fiscal.data_emissao_rps.must_equal DateTime.parse("Fri, 04 Sep 2015 09:56:17 -0300")
|
105
101
|
nota_fiscal.competencia.must_equal DateTime.parse("Tue, 01 Sep 2015 00:00:00 -0300")
|
106
102
|
nota_fiscal.outras_informacoes.must_equal "http://e-gov.betha.com.br/e-nota"
|
103
|
+
nota_fiscal.url_nf.must_equal "http://e-gov.betha.com.br/e-nota"
|
107
104
|
nota_fiscal.item_lista_servico.must_equal "111"
|
108
105
|
nota_fiscal.codigo_cnae.must_equal "6202300"
|
109
106
|
nota_fiscal.discriminacao.must_equal "discriminacao"
|
@@ -186,6 +183,7 @@ describe BrNfe::Servico::Betha::V1::BuildResponse do
|
|
186
183
|
nota_fiscal_1.data_emissao_rps.must_equal DateTime.parse("Fri, 04 Sep 2015 09:56:17 -0300")
|
187
184
|
nota_fiscal_1.competencia.must_equal DateTime.parse("Tue, 01 Sep 2015 00:00:00 -0300")
|
188
185
|
nota_fiscal_1.outras_informacoes.must_equal "http://e-gov.betha.com.br/e-nota"
|
186
|
+
nota_fiscal_1.url_nf.must_equal "http://e-gov.betha.com.br/e-nota"
|
189
187
|
nota_fiscal_1.item_lista_servico.must_equal "111"
|
190
188
|
nota_fiscal_1.codigo_cnae.must_equal "6202300"
|
191
189
|
nota_fiscal_1.discriminacao.must_equal "discriminacao"
|
@@ -225,6 +223,7 @@ describe BrNfe::Servico::Betha::V1::BuildResponse do
|
|
225
223
|
nota_fiscal_2.data_emissao_rps.must_equal "NOTA2 data_emissao_rps"
|
226
224
|
nota_fiscal_2.competencia.must_equal "NOTA2 competencia"
|
227
225
|
nota_fiscal_2.outras_informacoes.must_equal "NOTA2 outras_informacoes"
|
226
|
+
nota_fiscal_2.url_nf.must_equal "NOTA2 outras_informacoes"
|
228
227
|
nota_fiscal_2.item_lista_servico.must_equal "NOTA2 item_lista_servico"
|
229
228
|
nota_fiscal_2.discriminacao.must_equal "NOTA2 discriminacao"
|
230
229
|
nota_fiscal_2.codigo_municipio.must_equal "NOTA2 codigo_municipio"
|
@@ -8,6 +8,12 @@ describe BrNfe::Servico::Betha::V1::CancelamentoNfs do
|
|
8
8
|
it { subject.class.superclass.must_equal BrNfe::Servico::Betha::V1::Gateway }
|
9
9
|
end
|
10
10
|
|
11
|
+
describe "validations" do
|
12
|
+
it { must validate_presence_of(:numero_nfse) }
|
13
|
+
it { must validate_presence_of(:codigo_cancelamento) }
|
14
|
+
it { must validate_presence_of(:certificado) }
|
15
|
+
end
|
16
|
+
|
11
17
|
describe "#wsdl" do
|
12
18
|
context "for env production" do
|
13
19
|
it { subject.wsdl.must_equal 'http://e-gov.betha.com.br/e-nota-contribuinte-ws/cancelarNfseV02?wsdl' }
|
@@ -8,6 +8,10 @@ describe BrNfe::Servico::Betha::V1::ConsultaLoteRps do
|
|
8
8
|
it { subject.class.superclass.must_equal BrNfe::Servico::Betha::V1::Gateway }
|
9
9
|
end
|
10
10
|
|
11
|
+
describe "validations" do
|
12
|
+
it { must validate_presence_of(:protocolo) }
|
13
|
+
end
|
14
|
+
|
11
15
|
describe "#wsdl" do
|
12
16
|
context "for env production" do
|
13
17
|
it { subject.wsdl.must_equal 'http://e-gov.betha.com.br/e-nota-contribuinte-ws/consultarLoteRps?wsdl' }
|
@@ -8,6 +8,23 @@ describe BrNfe::Servico::Betha::V1::ConsultaNfse do
|
|
8
8
|
it { subject.class.superclass.must_equal BrNfe::Servico::Betha::V1::Gateway }
|
9
9
|
end
|
10
10
|
|
11
|
+
describe "validations" do
|
12
|
+
it { must validate_presence_of(:data_inicial) }
|
13
|
+
it { must validate_presence_of(:data_final) }
|
14
|
+
end
|
15
|
+
|
16
|
+
context "data inicial e final sempre deve retornar uma data na formatação adequada" do
|
17
|
+
it "data_inicial" do
|
18
|
+
subject.data_inicial = '12/05/2015'
|
19
|
+
subject.data_inicial.must_equal '2015-05-12'
|
20
|
+
end
|
21
|
+
|
22
|
+
it "data_final" do
|
23
|
+
subject.data_inicial = Date.parse '12/05/2010'
|
24
|
+
subject.data_inicial.must_equal '2010-05-12'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
11
28
|
describe "#wsdl" do
|
12
29
|
context "for env production" do
|
13
30
|
it { subject.wsdl.must_equal 'http://e-gov.betha.com.br/e-nota-contribuinte-ws/consultarNfse?wsdl' }
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
describe BrNfe::Servico::Betha::V1::Gateway do
|
4
|
-
subject { FactoryGirl.build(:
|
4
|
+
subject { FactoryGirl.build(:br_nfe_servico_betha_v1_gateway, emitente: emitente) }
|
5
5
|
let(:rps) { FactoryGirl.build(:br_nfe_rps, :completo) }
|
6
6
|
let(:emitente) { FactoryGirl.build(:emitente) }
|
7
7
|
let(:intermediario) { FactoryGirl.build(:intermediario) }
|
@@ -33,11 +33,9 @@ describe BrNfe::Servico::Betha::V1::Gateway do
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
describe "#
|
36
|
+
describe "#xml_dados_servico" do
|
37
37
|
it "deve vir com a estrutura adecuada com todos os valores preenchidos" do
|
38
|
-
xml =
|
39
|
-
subject.send(:tag_dados_servico, xml, rps)
|
40
|
-
end.doc
|
38
|
+
xml = subject.send(:xml_dados_servico, rps).doc
|
41
39
|
|
42
40
|
xml.xpath('Servico/ItemListaServico').first.text.must_equal rps.item_lista_servico
|
43
41
|
xml.xpath('Servico/CodigoCnae').first.text.must_equal rps.codigo_cnae
|
@@ -65,9 +63,7 @@ describe BrNfe::Servico::Betha::V1::Gateway do
|
|
65
63
|
aliquota: '', codigo_cnae: '', codigo_tributacao_municipio: ''
|
66
64
|
})
|
67
65
|
|
68
|
-
xml =
|
69
|
-
subject.send(:tag_dados_servico, xml, rps)
|
70
|
-
end.doc
|
66
|
+
xml = subject.send(:xml_dados_servico, rps).doc
|
71
67
|
|
72
68
|
|
73
69
|
xml.xpath('Servico/CodigoCnae').first.must_be_nil
|
@@ -84,77 +80,60 @@ describe BrNfe::Servico::Betha::V1::Gateway do
|
|
84
80
|
end
|
85
81
|
end
|
86
82
|
|
87
|
-
context "#
|
83
|
+
context "#xml_prestador" do
|
88
84
|
it "estrutura com todos os atributos" do
|
89
|
-
xml =
|
90
|
-
subject.send(:tag_prestador, xml)
|
91
|
-
end.doc
|
85
|
+
xml = subject.send(:xml_prestador).doc
|
92
86
|
|
93
87
|
xml.xpath('Prestador/Cnpj').first.text.must_equal emitente.cnpj
|
94
88
|
xml.xpath('Prestador/InscricaoMunicipal').first.text.must_equal emitente.inscricao_municipal
|
95
89
|
end
|
96
90
|
it "estrutura sem os atributos não obrigatorios" do
|
97
91
|
emitente.inscricao_municipal = ''
|
98
|
-
|
99
|
-
xml = Nokogiri::XML::Builder.new do |xml|
|
100
|
-
subject.send(:tag_prestador, xml)
|
101
|
-
end.doc
|
92
|
+
xml = subject.send(:xml_prestador).doc
|
102
93
|
|
103
94
|
xml.xpath('Prestador/InscricaoMunicipal').first.must_be_nil
|
104
95
|
end
|
105
96
|
end
|
106
97
|
|
107
|
-
context "#
|
98
|
+
context "#xml_intermediario_servico" do
|
108
99
|
it "estrutura com todos os atributos" do
|
109
|
-
xml =
|
110
|
-
subject.send(:tag_intermediario_servico, xml, intermediario)
|
111
|
-
end.doc
|
112
|
-
|
100
|
+
xml = subject.send(:xml_intermediario_servico, intermediario).doc
|
113
101
|
xml.xpath('IntermediarioServico/RazaoSocial').first.text.must_equal intermediario.razao_social
|
114
102
|
xml.xpath('IntermediarioServico/CpfCnpj/Cnpj').first.text.must_equal BrNfe::Helper::CpfCnpj.new(intermediario.cpf_cnpj).sem_formatacao
|
115
103
|
xml.xpath('IntermediarioServico/InscricaoMunicipal').first.text.must_equal intermediario.inscricao_municipal
|
116
104
|
end
|
117
105
|
it "estrutura sem os atributos não obrigatorios" do
|
118
106
|
intermediario.assign_attributes({cpf_cnpj: '132.456.789-01', inscricao_municipal: ''})
|
119
|
-
xml =
|
120
|
-
subject.send(:tag_intermediario_servico, xml, intermediario)
|
121
|
-
end.doc
|
107
|
+
xml = subject.send(:xml_intermediario_servico, intermediario).doc
|
122
108
|
|
123
109
|
xml.xpath('IntermediarioServico/CpfCnpj/Cpf').first.text.must_equal BrNfe::Helper::CpfCnpj.new(intermediario.cpf_cnpj).sem_formatacao
|
124
110
|
xml.xpath('IntermediarioServico/InscricaoMunicipal').first.must_be_nil
|
125
111
|
end
|
126
112
|
it "se não tiver intermediario não monta o xml" do
|
127
|
-
xml =
|
128
|
-
subject.send(:tag_intermediario_servico, xml, nil)
|
129
|
-
end.doc
|
130
|
-
|
113
|
+
xml = subject.send(:xml_intermediario_servico, nil).doc
|
131
114
|
xml.root.to_s.must_equal ''
|
132
115
|
end
|
133
116
|
end
|
134
117
|
|
135
|
-
describe "#
|
118
|
+
describe "#xml_condicao_pagamento" do
|
136
119
|
it "estrutura a prazo" do
|
137
|
-
xml =
|
138
|
-
subject.send(:tag_condicao_pagamento, xml, rps)
|
139
|
-
end.doc
|
120
|
+
xml = subject.send(:xml_condicao_pagamento, rps).doc
|
140
121
|
|
141
122
|
xml.xpath('CondicaoPagamento/Condicao').first.text.must_equal rps.condicao_pagamento.condicao
|
142
123
|
xml.xpath('CondicaoPagamento/QtdParcela').first.text.must_equal '2'
|
143
124
|
|
144
125
|
xml.xpath('CondicaoPagamento/Parcelas/Parcela').first.text.must_equal '1'
|
145
|
-
xml.xpath('CondicaoPagamento/Parcelas/DataVencimento').first.text.must_equal '2015
|
126
|
+
xml.xpath('CondicaoPagamento/Parcelas/DataVencimento').first.text.must_equal '15/10/2015'
|
146
127
|
xml.xpath('CondicaoPagamento/Parcelas/Valor').first.text.must_equal '10.0'
|
147
128
|
|
148
129
|
xml.xpath('CondicaoPagamento/Parcelas/Parcela').last.text.must_equal '2'
|
149
|
-
xml.xpath('CondicaoPagamento/Parcelas/DataVencimento').last.text.must_equal '2015
|
130
|
+
xml.xpath('CondicaoPagamento/Parcelas/DataVencimento').last.text.must_equal '15/11/2015'
|
150
131
|
xml.xpath('CondicaoPagamento/Parcelas/Valor').last.text.must_equal '20.0'
|
151
132
|
end
|
152
133
|
|
153
134
|
it "estrutura a vista" do
|
154
135
|
rps.condicao_pagamento.assign_attributes(condicao: 'A_VISTA', parcelas: [])
|
155
|
-
xml =
|
156
|
-
subject.send(:tag_condicao_pagamento, xml, rps)
|
157
|
-
end.doc
|
136
|
+
xml = subject.send(:xml_condicao_pagamento, rps).doc
|
158
137
|
|
159
138
|
xml.xpath('CondicaoPagamento/Condicao').first.text.must_equal 'A_VISTA'
|
160
139
|
xml.xpath('CondicaoPagamento/QtdParcela').first.must_be_nil
|
@@ -164,9 +143,7 @@ describe BrNfe::Servico::Betha::V1::Gateway do
|
|
164
143
|
|
165
144
|
it "quando não tem condicao_pagamento" do
|
166
145
|
rps.condicao_pagamento = nil
|
167
|
-
xml =
|
168
|
-
subject.send(:tag_condicao_pagamento, xml, rps)
|
169
|
-
end.doc
|
146
|
+
xml = subject.send(:xml_condicao_pagamento, rps).doc
|
170
147
|
xml.root.to_s.must_equal ''
|
171
148
|
end
|
172
149
|
end
|
@@ -10,6 +10,16 @@ describe BrNfe::Servico::Betha::V1::RecepcaoLoteRps do
|
|
10
10
|
it { subject.class.superclass.must_equal BrNfe::Servico::Betha::V1::Gateway }
|
11
11
|
end
|
12
12
|
|
13
|
+
describe "validations" do
|
14
|
+
it { must validate_presence_of(:numero_lote_rps) }
|
15
|
+
it { must validate_presence_of(:certificado) }
|
16
|
+
|
17
|
+
it "deve chamar o metodo validar_lote_rps" do
|
18
|
+
subject.expects(:validar_lote_rps)
|
19
|
+
subject.valid?
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
13
23
|
describe "#wsdl" do
|
14
24
|
context "for env production" do
|
15
25
|
it { subject.wsdl.must_equal 'http://e-gov.betha.com.br/e-nota-contribuinte-ws/recepcionarLoteRps?wsdl' }
|
@@ -163,11 +173,11 @@ describe BrNfe::Servico::Betha::V1::RecepcaoLoteRps do
|
|
163
173
|
xml.xpath('InfRps/CondicaoPagamento/Parcelas').count.must_equal 2
|
164
174
|
|
165
175
|
xml.xpath('InfRps/CondicaoPagamento/Parcelas/Parcela').first.text.must_equal '1'
|
166
|
-
xml.xpath('InfRps/CondicaoPagamento/Parcelas/DataVencimento').first.text.must_equal
|
176
|
+
xml.xpath('InfRps/CondicaoPagamento/Parcelas/DataVencimento').first.text.must_equal '15/10/2015'
|
167
177
|
xml.xpath('InfRps/CondicaoPagamento/Parcelas/Valor').first.text.must_equal '10.0'
|
168
178
|
|
169
179
|
xml.xpath('InfRps/CondicaoPagamento/Parcelas/Parcela').last.text.must_equal '2'
|
170
|
-
xml.xpath('InfRps/CondicaoPagamento/Parcelas/DataVencimento').last.text.must_equal
|
180
|
+
xml.xpath('InfRps/CondicaoPagamento/Parcelas/DataVencimento').last.text.must_equal '15/11/2015'
|
171
181
|
xml.xpath('InfRps/CondicaoPagamento/Parcelas/Valor').last.text.must_equal '20.0'
|
172
182
|
end
|
173
183
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe BrNfe::Servico::Betha::V2::CancelamentoNfs do
|
4
|
+
subject { FactoryGirl.build(:br_nfe_servico_betha_v2_cancelamento_nfs, emitente: emitente) }
|
5
|
+
let(:rps) { FactoryGirl.build(:br_nfe_rps, :completo) }
|
6
|
+
let(:emitente) { FactoryGirl.build(:emitente) }
|
7
|
+
let(:intermediario) { FactoryGirl.build(:intermediario) }
|
8
|
+
|
9
|
+
describe "inheritance class" do
|
10
|
+
it { subject.class.superclass.must_equal BrNfe::Servico::Betha::V2::Gateway }
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "validations" do
|
14
|
+
it { must validate_presence_of(:numero_nfse) }
|
15
|
+
it { must validate_presence_of(:codigo_cancelamento) }
|
16
|
+
it { must validate_presence_of(:certificado) }
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#method_wsdl" do
|
20
|
+
it { subject.method_wsdl.must_equal :cancelar_nfse }
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#xml_builder" do
|
24
|
+
it "não ocorre erro" do
|
25
|
+
subject.stubs(:assinatura_xml).returns('<Signature>signed</Signature>')
|
26
|
+
subject.xml_builder.class.must_equal Nokogiri::XML::Builder
|
27
|
+
end
|
28
|
+
it "estrutura" do
|
29
|
+
subject.expects(:xml_pedido_cancelamento_assinado).returns(Nokogiri::XML::Builder.new{|x| x.Cancelamento 'ok'} )
|
30
|
+
xml = subject.xml_builder.doc
|
31
|
+
|
32
|
+
xml.namespaces.must_equal({"xmlns"=>"http://www.betha.com.br/e-nota-contribuinte-ws"})
|
33
|
+
xml.remove_namespaces!
|
34
|
+
|
35
|
+
xml.xpath('CancelarNfseEnvio/Cancelamento').first.text.must_equal 'ok'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe BrNfe::Servico::Betha::V2::ConsultaLoteRps do
|
4
|
+
subject { FactoryGirl.build(:br_nfe_servico_betha_v2_consulta_lote_rps, emitente: emitente) }
|
5
|
+
let(:emitente) { FactoryGirl.build(:emitente) }
|
6
|
+
|
7
|
+
describe "inheritance class" do
|
8
|
+
it { subject.class.superclass.must_equal BrNfe::Servico::Betha::V2::Gateway }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "validations" do
|
12
|
+
it { must validate_presence_of(:protocolo) }
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#method_wsdl" do
|
16
|
+
it { subject.method_wsdl.must_equal :consultar_lote_rps }
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#xml_builder" do
|
20
|
+
it "não ocorre erro" do
|
21
|
+
subject.stubs(:assinatura_xml).returns('<Signature>signed</Signature>')
|
22
|
+
subject.xml_builder.class.must_equal Nokogiri::XML::Builder
|
23
|
+
end
|
24
|
+
it "estrutura" do
|
25
|
+
subject.protocolo = '1'.rjust(100, '1')
|
26
|
+
subject.expects(:xml_prestador).returns(Nokogiri::XML::Builder.new{|x| x.Pestador 'ok'} )
|
27
|
+
xml = subject.xml_builder.doc
|
28
|
+
|
29
|
+
xml.namespaces.must_equal({"xmlns"=>"http://www.betha.com.br/e-nota-contribuinte-ws"})
|
30
|
+
xml.remove_namespaces!
|
31
|
+
|
32
|
+
xml.xpath('ConsultarLoteRpsEnvio/Pestador').first.text.must_equal 'ok'
|
33
|
+
xml.xpath('ConsultarLoteRpsEnvio/Protocolo').first.text.must_equal '1'.rjust(50, '1')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe BrNfe::Servico::Betha::V2::ConsultaNfsePorRps do
|
4
|
+
subject { FactoryGirl.build(:br_nfe_servico_betha_v2_consulta_nfse_por_rps, emitente: emitente, rps: rps) }
|
5
|
+
let(:emitente) { FactoryGirl.build(:emitente) }
|
6
|
+
let(:rps) { FactoryGirl.build(:br_nfe_rps) }
|
7
|
+
|
8
|
+
describe "inheritance class" do
|
9
|
+
it { subject.class.superclass.must_equal BrNfe::Servico::Betha::V2::Gateway }
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#method_wsdl" do
|
13
|
+
it { subject.method_wsdl.must_equal :consultar_nfse_por_rps }
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#xml_builder" do
|
17
|
+
it "não ocorre erro" do
|
18
|
+
subject.stubs(:assinatura_xml).returns('<Signature>signed</Signature>')
|
19
|
+
subject.xml_builder.class.must_equal Nokogiri::XML::Builder
|
20
|
+
end
|
21
|
+
it "estrutura" do
|
22
|
+
sequence_1 = sequence('sequence1')
|
23
|
+
subject.expects(:xml_identificacao_rps).with(rps).returns(Nokogiri::XML::Builder.new{|x| x.IdentificacaoRps 'valor ident rps'} ).in_sequence(sequence_1)
|
24
|
+
subject.expects(:xml_prestador).returns(Nokogiri::XML::Builder.new{|x| x.Pestador 'dados prestador'} ).in_sequence(sequence_1)
|
25
|
+
xml = subject.xml_builder.doc
|
26
|
+
|
27
|
+
xml.namespaces.must_equal({"xmlns"=>"http://www.betha.com.br/e-nota-contribuinte-ws"})
|
28
|
+
xml.remove_namespaces!
|
29
|
+
|
30
|
+
xml.xpath('ConsultarNfseRpsEnvio/IdentificacaoRps').first.text.must_equal 'valor ident rps'
|
31
|
+
xml.xpath('ConsultarNfseRpsEnvio/Pestador').first.text.must_equal 'dados prestador'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe BrNfe::Servico::Betha::V2::EnvioLoteRpsSincrono do
|
4
|
+
subject { FactoryGirl.build(:br_nfe_servico_betha_v2_envio_lote_rps_sincrono, emitente: emitente) }
|
5
|
+
let(:emitente) { FactoryGirl.build(:emitente) }
|
6
|
+
|
7
|
+
describe "inheritance class" do
|
8
|
+
it { subject.class.superclass.must_equal BrNfe::Servico::Betha::V2::RecepcaoLoteRps }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "validations" do
|
12
|
+
it { must validate_presence_of(:numero_lote_rps) }
|
13
|
+
it { must validate_presence_of(:certificado) }
|
14
|
+
|
15
|
+
it "deve chamar o metodo validar_lote_rps" do
|
16
|
+
subject.expects(:validar_lote_rps)
|
17
|
+
subject.valid?
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#method_wsdl" do
|
22
|
+
it { subject.method_wsdl.must_equal :recepcionar_lote_rps_sincrono }
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#xml_builder" do
|
26
|
+
it "não ocorre erro" do
|
27
|
+
subject.stubs(:assinatura_xml).returns('<Signature>signed</Signature>')
|
28
|
+
subject.xml_builder.class.must_equal Nokogiri::XML::Builder
|
29
|
+
end
|
30
|
+
it "estrutura" do
|
31
|
+
subject.numero_lote_rps = 88966
|
32
|
+
lote_rps_xml = Nokogiri::XML::Builder.new{|x| x.LoteRps 'valor loterps'}
|
33
|
+
subject.expects(:lote_rps_xml).returns(lote_rps_xml)
|
34
|
+
subject.expects(:assinatura_xml).with(lote_rps_xml.doc.root.to_s, '#lote88966').returns('<Signature>signed</Signature>')
|
35
|
+
xml = subject.xml_builder.doc
|
36
|
+
|
37
|
+
xml.namespaces.must_equal({"xmlns"=>"http://www.betha.com.br/e-nota-contribuinte-ws"})
|
38
|
+
xml.remove_namespaces!
|
39
|
+
|
40
|
+
xml.xpath('EnviarLoteRpsSincronoEnvio/LoteRps').first.text.must_equal 'valor loterps'
|
41
|
+
xml.xpath('EnviarLoteRpsSincronoEnvio/Signature').first.text.must_equal 'signed'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
end
|