br_nfe 1.0.0 → 1.0.1

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 (68) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +4 -1
  3. data/README.markdown +263 -1
  4. data/br_nfe.gemspec +14 -5
  5. data/lib/br_nfe/base.rb +6 -1
  6. data/lib/br_nfe/helper/cpf_cnpj.rb +0 -5
  7. data/lib/br_nfe/helper/have_address.rb +1 -5
  8. data/lib/br_nfe/helper/have_rps.rb +7 -0
  9. data/lib/br_nfe/servico/betha/base.rb +52 -41
  10. data/lib/br_nfe/servico/betha/build_response.rb +141 -0
  11. data/lib/br_nfe/servico/betha/v1/build_response.rb +4 -102
  12. data/lib/br_nfe/servico/betha/v1/consulta_lote_rps.rb +3 -1
  13. data/lib/br_nfe/servico/betha/v1/consulta_nfs_por_rps.rb +5 -2
  14. data/lib/br_nfe/servico/betha/v1/consulta_nfse.rb +2 -1
  15. data/lib/br_nfe/servico/betha/v1/gateway.rb +66 -56
  16. data/lib/br_nfe/servico/betha/v1/recepcao_lote_rps.rb +16 -8
  17. data/lib/br_nfe/servico/betha/v2/build_response.rb +159 -0
  18. data/lib/br_nfe/servico/betha/v2/cancelamento_nfs.rb +8 -3
  19. data/lib/br_nfe/servico/betha/v2/consulta_lote_rps.rb +7 -4
  20. data/lib/br_nfe/servico/betha/v2/consulta_nfse_por_rps.rb +5 -5
  21. data/lib/br_nfe/servico/betha/v2/envio_lote_rps_sincrono.rb +7 -3
  22. data/lib/br_nfe/servico/betha/v2/gateway.rb +79 -56
  23. data/lib/br_nfe/servico/betha/v2/gera_nfse.rb +8 -3
  24. data/lib/br_nfe/servico/betha/v2/recepcao_lote_rps.rb +9 -4
  25. data/lib/br_nfe/servico/betha/v2/substituicao_nfse.rb +8 -4
  26. data/lib/br_nfe/servico/response/nota_fiscal.rb +13 -4
  27. data/lib/br_nfe/servico/rps.rb +2 -2
  28. data/lib/br_nfe/version.rb +1 -1
  29. data/lib/br_nfe.rb +2 -1
  30. data/test/br_nfe/base_test.rb +55 -1
  31. data/test/br_nfe/destinatario_test.rb +19 -0
  32. data/test/br_nfe/emitente_test.rb +20 -0
  33. data/test/br_nfe/endereco_test.rb +9 -0
  34. data/test/br_nfe/helper/cpf_cnpj_test.rb +61 -0
  35. data/test/br_nfe/servico/base_test.rb +28 -0
  36. data/test/br_nfe/servico/betha/base_test.rb +61 -32
  37. data/test/br_nfe/servico/betha/v1/build_response_test.rb +6 -7
  38. data/test/br_nfe/servico/betha/v1/cancelamento_nfs_test.rb +6 -0
  39. data/test/br_nfe/servico/betha/v1/consulta_lote_rps_test.rb +4 -0
  40. data/test/br_nfe/servico/betha/v1/consulta_nfse_test.rb +17 -0
  41. data/test/br_nfe/servico/betha/v1/gateway_test.rb +17 -40
  42. data/test/br_nfe/servico/betha/v1/recepcao_lote_rps_test.rb +12 -2
  43. data/test/br_nfe/servico/betha/v2/cancelamento_nfs_test.rb +40 -0
  44. data/test/br_nfe/servico/betha/v2/consulta_lote_rps_test.rb +38 -0
  45. data/test/br_nfe/servico/betha/v2/consulta_nfse_por_rps_test.rb +36 -0
  46. data/test/br_nfe/servico/betha/v2/envio_lote_rps_sincrono_test.rb +46 -0
  47. data/test/br_nfe/servico/betha/v2/gateway_test.rb +372 -0
  48. data/test/br_nfe/servico/betha/v2/gera_nfse_test.rb +58 -0
  49. data/test/br_nfe/servico/betha/v2/recepcao_lote_rps_test.rb +103 -0
  50. data/test/br_nfe/servico/betha/v2/substituicao_nfse_test.rb +80 -0
  51. data/test/br_nfe/servico/intermediario_test.rb +16 -0
  52. data/test/br_nfe/servico/rps_test.rb +141 -0
  53. data/test/factories/servico/betha/v1/gateway.rb +1 -1
  54. data/test/factories/servico/betha/v2/cancelamento_nfs.rb +7 -0
  55. data/test/factories/servico/betha/v2/consulta_lote_rps.rb +6 -0
  56. data/test/factories/servico/betha/v2/consulta_nfse_por_rps.rb +6 -0
  57. data/test/factories/servico/betha/v2/envio_lote_rps_sincrono.rb +5 -0
  58. data/test/factories/servico/betha/v2/gateway.rb +5 -0
  59. data/test/factories/servico/betha/v2/gera_nfse.rb +6 -0
  60. data/test/factories/servico/betha/v2/recepcao_lote_rps.rb +5 -0
  61. data/test/factories/servico/betha/v2/substituicao_nfse.rb +8 -0
  62. metadata +50 -17
  63. data/Gemfile +0 -15
  64. data/Rakefile +0 -13
  65. data/lib/br_nfe/seed.rb +0 -195
  66. data/lib/br_nfe/servico/betha/v2/response.rb +0 -23
  67. data/test/certificado.rb +0 -12
  68. data/test/test_helper.rb +0 -39
@@ -0,0 +1,372 @@
1
+ require 'test_helper'
2
+
3
+ describe BrNfe::Servico::Betha::V2::Gateway do
4
+ subject { FactoryGirl.build(:br_nfe_servico_betha_v2_gateway, 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::Base }
11
+ end
12
+
13
+ describe "#namespaces" do
14
+ it "deve ter um valor" do
15
+ subject.namespaces.must_equal({"xmlns:e" => "http://www.betha.com.br/e-nota-contribuinte-ws"})
16
+ end
17
+ end
18
+
19
+ describe "#namespace_identifier" do
20
+ it "deve ter o valor e" do
21
+ subject.namespace_identifier.must_equal :e
22
+ end
23
+ end
24
+
25
+ describe "#version" do
26
+ it { subject.version.must_equal :v2 }
27
+ end
28
+
29
+ describe "#wsdl" do
30
+ it "quando o env for test" do
31
+ subject.env = :test
32
+ subject.wsdl.must_equal 'http://e-gov.betha.com.br/e-nota-contribuinte-test-ws/nfseWS?wsdl'
33
+ end
34
+ it "quando o env não for" do
35
+ subject.env = :production
36
+ subject.wsdl.must_equal 'http://e-gov.betha.com.br/e-nota-contribuinte-ws/nfseWS?wsdl'
37
+ end
38
+ end
39
+
40
+ describe "#cabecalho" do
41
+ it { subject.cabecalho.must_equal "<nfseCabecMsg><![CDATA[<cabecalho xmlns=\"http://www.betha.com.br/e-nota-contribuinte-ws\" versao=\"2.02\"> <versaoDados>2.02</versaoDados></cabecalho>]]></nfseCabecMsg>" }
42
+ end
43
+
44
+ describe "#content_xml" do
45
+ it do
46
+ subject.expects(:canonical_xml_builder).returns("<xmlBuilder>value</xmlBuilder>")
47
+ subject.content_xml.must_equal "<nfseDadosMsg><![CDATA[<xmlBuilder>value</xmlBuilder>]]></nfseDadosMsg>"
48
+ end
49
+ end
50
+
51
+ describe "#canonical_xml_builder" do
52
+ it "deve canonicalizar o valor do metodo xml_builder" do
53
+ xml = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |new_xml|
54
+ new_xml.Principal{
55
+ new_xml.Valor 1
56
+ }
57
+ end
58
+ subject.expects(:xml_builder).returns(xml)
59
+ subject.canonical_xml_builder.must_equal("<Principal><Valor>1</Valor></Principal>")
60
+ end
61
+
62
+ end
63
+
64
+ describe "#format_data_xml_for_signature" do
65
+ it "deve adicionar o attr xmlns no root do XML" do
66
+ xml = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |new_xml|
67
+ new_xml.Principal{
68
+ new_xml.Valor 1
69
+ }
70
+ end.doc.root
71
+
72
+ subject.send(:format_data_xml_for_signature, xml).must_equal "<Principal xmlns=\"http://www.betha.com.br/e-nota-contribuinte-ws\"><Valor>1</Valor></Principal>"
73
+ end
74
+ end
75
+
76
+ context "#xml_intermediario_servico" do
77
+ it "estrutura com todos os atributos" do
78
+ xml = subject.send(:xml_intermediario_servico, intermediario).doc
79
+ xml.xpath('Intermediario/RazaoSocial').first.text.must_equal intermediario.razao_social
80
+ xml.xpath('Intermediario/IdentificacaoIntermediario/CpfCnpj/Cnpj').first.text.must_equal BrNfe::Helper::CpfCnpj.new(intermediario.cpf_cnpj).sem_formatacao
81
+ xml.xpath('Intermediario/IdentificacaoIntermediario/InscricaoMunicipal').first.text.must_equal intermediario.inscricao_municipal
82
+ end
83
+ it "estrutura sem os atributos não obrigatorios" do
84
+ intermediario.assign_attributes({cpf_cnpj: '132.456.789-01', inscricao_municipal: ''})
85
+ xml = subject.send(:xml_intermediario_servico, intermediario).doc
86
+
87
+ xml.xpath('Intermediario/IdentificacaoIntermediario/CpfCnpj/Cpf').first.text.must_equal BrNfe::Helper::CpfCnpj.new(intermediario.cpf_cnpj).sem_formatacao
88
+ xml.xpath('Intermediario/IdentificacaoIntermediario/InscricaoMunicipal').first.must_be_nil
89
+ end
90
+ it "se não tiver intermediario não monta o xml" do
91
+ xml = subject.send(:xml_intermediario_servico, nil).doc
92
+ xml.root.to_s.must_equal ''
93
+ end
94
+ end
95
+
96
+ context "#xml_prestador" do
97
+ it "estrutura com todos os atributos" do
98
+ xml = subject.send(:xml_prestador).doc
99
+
100
+ xml.xpath('Prestador/CpfCnpj/Cnpj').first.text.must_equal emitente.cnpj
101
+ xml.xpath('Prestador/InscricaoMunicipal').first.text.must_equal emitente.inscricao_municipal
102
+ end
103
+ it "estrutura sem os atributos não obrigatorios" do
104
+ emitente.inscricao_municipal = ''
105
+ xml = subject.send(:xml_prestador).doc
106
+
107
+ xml.xpath('Prestador/InscricaoMunicipal').first.must_be_nil
108
+ end
109
+ it "se o env não for production não exibe a inscricao_municipal pois a base de testes da Betha está bugada" do
110
+ emitente.inscricao_municipal = '7987897'
111
+ subject.env = :test
112
+ xml = subject.send(:xml_prestador).doc
113
+
114
+ xml.xpath('Prestador/InscricaoMunicipal').first.must_be_nil
115
+ end
116
+ end
117
+
118
+ describe "#xml_dados_servico" do
119
+ before do
120
+ rps.assign_attributes({
121
+ valor_servicos: 1_003.456,
122
+ valor_deducoes: 1_003.123465132,
123
+ valor_pis: 1_003.0,
124
+ valor_cofins: 1_003.3654,
125
+ valor_inss: 1_004.456,
126
+ valor_ir: 1_005.456,
127
+ valor_csll: 1_006.456,
128
+ outras_retencoes: 1_007.456,
129
+ valor_iss: 1_008.456,
130
+ aliquota: 1_009.456,
131
+ desconto_incondicionado: 1_010.456,
132
+ desconto_condicionado: 1_011.456,
133
+ responsavel_retencao: '123',
134
+ item_lista_servico: '6.356.01',
135
+ iss_retido: true,
136
+ codigo_cnae: '65.687.5654',
137
+ discriminacao: 'áêçOÓó'.ljust(2_005, 'a'),
138
+ codigo_municipio: '1234AAA567890123',
139
+ exigibilidade_iss: '4',
140
+ codigo_pais: 'A123456',
141
+ municipio_incidencia: '1234AAA567890123',
142
+ numero_processo: '5'.rjust(50, '5'),
143
+ codigo_tributacao_municipio: '123465'.ljust(30, 'A'),
144
+ })
145
+ end
146
+ it "deve vir com a estrutura adecuada com todos os valores preenchidos" do
147
+ xml = subject.send(:xml_dados_servico, rps).doc
148
+
149
+ xml.xpath('Servico/IssRetido').first.text.must_equal "1"
150
+ xml.xpath('Servico/ResponsavelRetencao').first.text.must_equal "1"
151
+ xml.xpath('Servico/ItemListaServico').first.text.must_equal "63560"
152
+ xml.xpath('Servico/CodigoCnae').first.text.must_equal "6568756"
153
+ xml.xpath('Servico/Discriminacao').first.text.must_equal 'aecOOo'.ljust(2_000, 'a')
154
+ xml.xpath('Servico/CodigoMunicipio').first.text.must_equal "1234567"
155
+ xml.xpath('Servico/CodigoPais').first.text.must_equal "1234"
156
+ xml.xpath('Servico/ExigibilidadeISS').first.text.must_equal "4"
157
+ xml.xpath('Servico/MunicipioIncidencia').first.text.must_equal "1234567"
158
+ xml.xpath('Servico/NumeroProcesso').first.text.must_equal "5".rjust(30, '5')
159
+ xml.xpath('Servico/CodigoTributacaoMunicipio').first.text.must_equal '123465'.ljust(20, 'A')
160
+
161
+ xml.xpath('Servico/Valores/ValorServicos').first.text.must_equal "1003.46"
162
+ xml.xpath('Servico/Valores/ValorDeducoes').first.text.must_equal "1003.12"
163
+ xml.xpath('Servico/Valores/ValorPis').first.text.must_equal "1003.0"
164
+ xml.xpath('Servico/Valores/ValorCofins').first.text.must_equal "1003.37"
165
+ xml.xpath('Servico/Valores/ValorInss').first.text.must_equal "1004.46"
166
+ xml.xpath('Servico/Valores/ValorIr').first.text.must_equal "1005.46"
167
+ xml.xpath('Servico/Valores/ValorCsll').first.text.must_equal "1006.46"
168
+ xml.xpath('Servico/Valores/OutrasRetencoes').first.text.must_equal "1007.46"
169
+ xml.xpath('Servico/Valores/ValorIss').first.text.must_equal "1008.46"
170
+ xml.xpath('Servico/Valores/Aliquota').first.text.must_equal "1009.46"
171
+ xml.xpath('Servico/Valores/DescontoIncondicionado').first.text.must_equal "1010.46"
172
+ xml.xpath('Servico/Valores/DescontoCondicionado').first.text.must_equal "1011.46"
173
+ end
174
+
175
+ it "se exigibilidade_iss não for 4, então não posso mandar o codigo do pais" do
176
+ rps.exigibilidade_iss = '1'
177
+ xml = subject.send(:xml_dados_servico, rps).doc
178
+ xml.xpath('Servico/CodigoPais').first.must_be_nil
179
+ end
180
+
181
+ it "sem os valores não obrigatórios" do
182
+ rps.assign_attributes({
183
+ valor_servicos: '',
184
+ valor_deducoes: '',
185
+ valor_pis: '',
186
+ valor_cofins: '',
187
+ valor_inss: '',
188
+ valor_ir: '',
189
+ valor_csll: '',
190
+ outras_retencoes: '',
191
+ valor_iss: '',
192
+ aliquota: '',
193
+ desconto_incondicionado: '',
194
+ desconto_condicionado: '',
195
+ responsavel_retencao: '',
196
+ item_lista_servico: '',
197
+ iss_retido: '',
198
+ codigo_cnae: '',
199
+ discriminacao: '',
200
+ codigo_municipio: '',
201
+ exigibilidade_iss: '',
202
+ codigo_pais: '',
203
+ municipio_incidencia: '',
204
+ numero_processo: '',
205
+ codigo_tributacao_municipio: '',
206
+ })
207
+
208
+ xml = subject.send(:xml_dados_servico, rps).doc
209
+
210
+ xml.xpath('Servico/IssRetido').first.text.must_equal "2"
211
+ xml.xpath('Servico/ResponsavelRetencao').first.must_be_nil
212
+ xml.xpath('Servico/ItemListaServico').first.must_be_nil
213
+ xml.xpath('Servico/CodigoCnae').first.must_be_nil
214
+ xml.xpath('Servico/Discriminacao').first.text.must_equal ''
215
+ xml.xpath('Servico/CodigoMunicipio').first.text.must_equal ''
216
+ xml.xpath('Servico/CodigoPais').first.must_be_nil
217
+ xml.xpath('Servico/ExigibilidadeISS').first.text.must_equal ""
218
+ xml.xpath('Servico/MunicipioIncidencia').first.must_be_nil
219
+ xml.xpath('Servico/NumeroProcesso').first.must_be_nil
220
+ xml.xpath('Servico/CodigoTributacaoMunicipio').first.must_be_nil
221
+
222
+ xml.xpath('Servico/Valores/ValorServicos').first.text.must_equal "0.0"
223
+ xml.xpath('Servico/Valores/ValorDeducoes').first.must_be_nil
224
+ xml.xpath('Servico/Valores/ValorPis').first.must_be_nil
225
+ xml.xpath('Servico/Valores/ValorCofins').first.must_be_nil
226
+ xml.xpath('Servico/Valores/ValorInss').first.must_be_nil
227
+ xml.xpath('Servico/Valores/ValorIr').first.must_be_nil
228
+ xml.xpath('Servico/Valores/ValorCsll').first.must_be_nil
229
+ xml.xpath('Servico/Valores/OutrasRetencoes').first.must_be_nil
230
+ xml.xpath('Servico/Valores/ValorIss').first.must_be_nil
231
+ xml.xpath('Servico/Valores/Aliquota').first.must_be_nil
232
+ xml.xpath('Servico/Valores/DescontoIncondicionado').first.must_be_nil
233
+ xml.xpath('Servico/Valores/DescontoCondicionado').first.must_be_nil
234
+ end
235
+ end
236
+
237
+ describe "#xml_inf_declaracao_prestacao_servico" do
238
+ before do
239
+ rps.assign_attributes({
240
+ data_emissao: DateTime.parse('12/04/1991 03:45'),
241
+ status: '123',
242
+ competencia: DateTime.parse('05/11/2000')
243
+ })
244
+ emitente.assign_attributes({
245
+ regime_especial_tributacao: 1,
246
+ optante_simples_nacional: true,
247
+ incentivo_fiscal: false,
248
+ })
249
+ end
250
+ it do
251
+ sequence1 = sequence('sequence1')
252
+ subject.expects(:xml_identificacao_rps).with(rps).returns(Nokogiri::XML::Builder.new {|xml| xml.Doc1 1}).in_sequence(sequence1)
253
+ subject.expects(:xml_rps_substituido).with(rps).returns( Nokogiri::XML::Builder.new {|xml| xml.Doc2 2}).in_sequence(sequence1)
254
+ subject.expects(:xml_dados_servico).with(rps).returns( Nokogiri::XML::Builder.new {|xml| xml.Doc3 3}).in_sequence(sequence1)
255
+ subject.expects(:xml_prestador).returns( Nokogiri::XML::Builder.new {|xml| xml.Doc4 4}).in_sequence(sequence1)
256
+ subject.expects(:xml_dados_tomador).with(rps.destinatario).returns(Nokogiri::XML::Builder.new {|xml| xml.Doc5 5}).in_sequence(sequence1)
257
+ subject.expects(:xml_intermediario_servico).with(rps.intermediario).returns(Nokogiri::XML::Builder.new {|xml| xml.Doc6 6}).in_sequence(sequence1)
258
+ subject.expects(:xml_dados_construcao_civil).with(rps).returns(Nokogiri::XML::Builder.new {|xml| xml.Doc7 7}).in_sequence(sequence1)
259
+ xml = subject.send(:xml_inf_declaracao_prestacao_servico, rps).doc
260
+
261
+ xml.xpath('InfDeclaracaoPrestacaoServico/Rps/Doc1').first.text.must_equal '1'
262
+ xml.xpath('InfDeclaracaoPrestacaoServico/Rps/DataEmissao').first.text.must_equal '1991-04-12'
263
+ xml.xpath('InfDeclaracaoPrestacaoServico/Rps/Status').first.text.must_equal '1'
264
+ xml.xpath('InfDeclaracaoPrestacaoServico/Rps/Doc2').first.text.must_equal '2'
265
+ xml.xpath('InfDeclaracaoPrestacaoServico/Competencia').first.text.must_equal '2000-11-05'
266
+ xml.xpath('InfDeclaracaoPrestacaoServico/Doc3').first.text.must_equal '3'
267
+ xml.xpath('InfDeclaracaoPrestacaoServico/Doc4').first.text.must_equal '4'
268
+ xml.xpath('InfDeclaracaoPrestacaoServico/Doc5').first.text.must_equal '5'
269
+ xml.xpath('InfDeclaracaoPrestacaoServico/Doc6').first.text.must_equal '6'
270
+ xml.xpath('InfDeclaracaoPrestacaoServico/Doc7').first.text.must_equal '7'
271
+ xml.xpath('InfDeclaracaoPrestacaoServico/RegimeEspecialTributacao').first.text.must_equal '1'
272
+ xml.xpath('InfDeclaracaoPrestacaoServico/OptanteSimplesNacional').first.text.must_equal '1'
273
+ xml.xpath('InfDeclaracaoPrestacaoServico/IncentivoFiscal').first.text.must_equal '2'
274
+ end
275
+ end
276
+
277
+ describe "#xml_rps_assinado" do
278
+ it do
279
+ info_servico = Nokogiri::XML::Builder.new {|xml| xml.InfoServico 'valores'}
280
+ subject.expects(:xml_inf_declaracao_prestacao_servico).with(rps).returns(info_servico)
281
+ subject.expects(:assinatura_xml).with(info_servico.doc.root.to_s, "#rps#{rps.numero}").returns("<Signature>true</Signature>")
282
+ xml = subject.send(:xml_rps_assinado, rps).doc
283
+ xml.xpath('Rps/InfoServico').first.text.must_equal 'valores'
284
+ xml.xpath('Rps/Signature').first.text.must_equal 'true'
285
+ end
286
+ end
287
+
288
+ describe "#xml_pedido_cancelamento_assinado" do
289
+ it do
290
+ subject.numero_nfse = 888
291
+ xml_cancelamento = Nokogiri::XML::Builder.new {|xml| xml.XmlCancelamento 'valores'}
292
+ subject.expects(:xml_inf_pedido_cancelamento).returns(xml_cancelamento)
293
+ subject.expects(:assinatura_xml).with(xml_cancelamento.doc.root.to_s, "#nf888").returns("<Signature>true</Signature>")
294
+ xml = subject.send(:xml_pedido_cancelamento_assinado).doc
295
+ xml.xpath('Pedido/XmlCancelamento').first.text.must_equal 'valores'
296
+ xml.xpath('Pedido/Signature').first.text.must_equal 'true'
297
+ end
298
+ end
299
+
300
+ describe "#xml_inf_pedido_cancelamento" do
301
+ before do
302
+ subject.assign_attributes({
303
+ numero_nfse: '336ABC6554411233664125',
304
+ codigo_cancelamento: '1234567890',
305
+ emitente:{
306
+ cnpj: '12345678901234',
307
+ inscricao_municipal: '9996654785524865464565',
308
+ endereco: {codigo_municipio: '123456789012345'}
309
+ }
310
+ })
311
+ end
312
+
313
+ it "com env = production" do
314
+ subject.env = :production
315
+ xml = subject.send(:xml_inf_pedido_cancelamento).doc
316
+
317
+ xml.xpath('InfPedidoCancelamento').first.attr('Id').must_equal 'nf336ABC6554411233664125'
318
+ # Apenas 15 nuemros
319
+ xml.xpath('InfPedidoCancelamento/IdentificacaoNfse/Numero').first.text.must_equal '336655441123366'
320
+ xml.xpath('InfPedidoCancelamento/IdentificacaoNfse/InscricaoMunicipal').first.text.must_equal '999665478552486'
321
+ xml.xpath('InfPedidoCancelamento/IdentificacaoNfse/CodigoMunicipio').first.text.must_equal '1234567'
322
+ xml.xpath('InfPedidoCancelamento/CodigoCancelamento').first.text.must_equal '1234'
323
+ end
324
+
325
+ it "com env = test" do
326
+ subject.env = :test
327
+ xml = subject.send(:xml_inf_pedido_cancelamento).doc
328
+
329
+ xml.xpath('InfPedidoCancelamento').first.attr('Id').must_equal 'nf336ABC6554411233664125'
330
+ xml.xpath('InfPedidoCancelamento/IdentificacaoNfse/Numero').first.text.must_equal '336655441123366'
331
+ xml.xpath('InfPedidoCancelamento/IdentificacaoNfse/InscricaoMunicipal').first.must_be_nil
332
+ xml.xpath('InfPedidoCancelamento/IdentificacaoNfse/CodigoMunicipio').first.text.must_equal '1234567'
333
+ xml.xpath('InfPedidoCancelamento/CodigoCancelamento').first.text.must_equal '1234'
334
+ end
335
+ end
336
+
337
+
338
+
339
+ # describe "#xml_condicao_pagamento" do
340
+ # it "estrutura a prazo" do
341
+ # xml = subject.send(:xml_condicao_pagamento, rps).doc
342
+
343
+ # xml.xpath('CondicaoPagamento/Condicao').first.text.must_equal rps.condicao_pagamento.condicao
344
+ # xml.xpath('CondicaoPagamento/QtdParcela').first.text.must_equal '2'
345
+
346
+ # xml.xpath('CondicaoPagamento/Parcelas/Parcela').first.text.must_equal '1'
347
+ # xml.xpath('CondicaoPagamento/Parcelas/DataVencimento').first.text.must_equal '15/10/2015'
348
+ # xml.xpath('CondicaoPagamento/Parcelas/Valor').first.text.must_equal '10.0'
349
+
350
+ # xml.xpath('CondicaoPagamento/Parcelas/Parcela').last.text.must_equal '2'
351
+ # xml.xpath('CondicaoPagamento/Parcelas/DataVencimento').last.text.must_equal '15/11/2015'
352
+ # xml.xpath('CondicaoPagamento/Parcelas/Valor').last.text.must_equal '20.0'
353
+ # end
354
+
355
+ # it "estrutura a vista" do
356
+ # rps.condicao_pagamento.assign_attributes(condicao: 'A_VISTA', parcelas: [])
357
+ # xml = subject.send(:xml_condicao_pagamento, rps).doc
358
+
359
+ # xml.xpath('CondicaoPagamento/Condicao').first.text.must_equal 'A_VISTA'
360
+ # xml.xpath('CondicaoPagamento/QtdParcela').first.must_be_nil
361
+
362
+ # xml.xpath('CondicaoPagamento/Parcelas').first.must_be_nil
363
+ # end
364
+
365
+ # it "quando não tem condicao_pagamento" do
366
+ # rps.condicao_pagamento = nil
367
+ # xml = subject.send(:xml_condicao_pagamento, rps).doc
368
+ # xml.root.to_s.must_equal ''
369
+ # end
370
+ # end
371
+
372
+ end
@@ -0,0 +1,58 @@
1
+ require 'test_helper'
2
+
3
+ describe BrNfe::Servico::Betha::V2::GeraNfse do
4
+ subject { FactoryGirl.build(:br_nfe_servico_betha_v2_gera_nfse, emitente: emitente, rps: rps, certificado: certificado) }
5
+ let(:emitente) { FactoryGirl.build(:emitente) }
6
+ let(:rps) { FactoryGirl.build(:br_nfe_rps) }
7
+ let(:certificado) { Certificado.new }
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(:certificado) }
15
+
16
+ context "deve validar o rps" do
17
+ it "quando o rps for válido não deve setar nenhuma mensagem no objeto" do
18
+ rps.stubs(:errors).returns(stub(full_messages: ["Erro rps"]))
19
+ sequence_1 = sequence('sequence_1')
20
+ rps.expects(:validar_recepcao_rps=).with(true).in_sequence(sequence_1)
21
+ rps.expects(:invalid?).returns(false).in_sequence(sequence_1)
22
+ subject.valid?.must_equal true
23
+ subject.errors.full_messages.must_equal( [] )
24
+ end
25
+ it "quando o rps for inválido deve setar mensagem de erro no objeto" do
26
+ rps.stubs(:errors).returns(stub(full_messages: ["Erro rps"]))
27
+ sequence_1 = sequence('sequence_1')
28
+ rps.expects(:validar_recepcao_rps=).with(true).in_sequence(sequence_1)
29
+ rps.expects(:invalid?).returns(true).in_sequence(sequence_1)
30
+ subject.valid?.must_equal false
31
+ subject.errors.full_messages.must_equal( ["RPS: Erro rps"] )
32
+ end
33
+
34
+ end
35
+ end
36
+
37
+ describe "#method_wsdl" do
38
+ it { subject.method_wsdl.must_equal :gerar_nfse }
39
+ end
40
+
41
+ describe "#xml_builder" do
42
+ it "não ocorre erro" do
43
+ subject.stubs(:assinatura_xml).returns('<Signature>signed</Signature>')
44
+ subject.xml_builder.class.must_equal Nokogiri::XML::Builder
45
+ end
46
+ it "estrutura" do
47
+ subject.expects(:xml_rps_assinado).returns( Nokogiri::XML::Builder.new{|x| x.RpsAssinado 'valor rps assinado'} )
48
+ xml = subject.xml_builder.doc
49
+
50
+ xml.namespaces.must_equal({"xmlns"=>"http://www.betha.com.br/e-nota-contribuinte-ws"})
51
+ xml.remove_namespaces!
52
+
53
+ xml.xpath('GerarNfseEnvio/RpsAssinado').first.text.must_equal 'valor rps assinado'
54
+ end
55
+ end
56
+
57
+
58
+ end
@@ -0,0 +1,103 @@
1
+ require 'test_helper'
2
+
3
+ describe BrNfe::Servico::Betha::V2::RecepcaoLoteRps do
4
+ subject { FactoryGirl.build(:br_nfe_servico_betha_v2_recepcao_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(: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 }
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('EnviarLoteRpsEnvio/LoteRps').first.text.must_equal 'valor loterps'
41
+ xml.xpath('EnviarLoteRpsEnvio/Signature').first.text.must_equal 'signed'
42
+ end
43
+ end
44
+
45
+ describe "#lote_rps_xml" do
46
+ let(:rps1) { FactoryGirl.build(:br_nfe_rps, numero: '1') }
47
+ let(:rps2) { FactoryGirl.build(:br_nfe_rps, numero: '2') }
48
+
49
+ before do
50
+ subject.stubs(:assinatura_xml).returns('<Signature>signed</Signature>')
51
+ subject.assign_attributes({
52
+ numero_lote_rps: '5568'.ljust(50, '1'),
53
+ emitente: {
54
+ cnpj: '66.554.778/9654-12',
55
+ inscricao_municipal: '6565498713134687984313868135798'
56
+ },
57
+ lote_rps: [rps1, rps2]
58
+ })
59
+ end
60
+
61
+ it "estrutura com env = production" do
62
+ subject.env = :production
63
+ sequence1 = sequence('sequence1')
64
+ subject.expects(:xml_rps_assinado).with(rps1).in_sequence(sequence1).returns(Nokogiri::XML::Builder.new{|x| x.Rps 'valor rps1'})
65
+ subject.expects(:xml_rps_assinado).with(rps2).in_sequence(sequence1).returns(Nokogiri::XML::Builder.new{|x| x.Rps 'valor rps2'})
66
+
67
+ xml = subject.send(:lote_rps_xml).doc
68
+
69
+ xml.xpath('LoteRps').first.attr('Id').must_equal "lote#{'5568'.ljust(50, '1')}"
70
+ xml.xpath('LoteRps').first.attr('versao').must_equal '2.02'
71
+
72
+ xml.xpath('LoteRps/NumeroLote').first.text.must_equal '556811111111111'
73
+ xml.xpath('LoteRps/CpfCnpj/Cnpj').first.text.must_equal '66554778965412'
74
+ xml.xpath('LoteRps/InscricaoMunicipal').first.text.must_equal '656549871313468'
75
+ xml.xpath('LoteRps/QuantidadeRps').first.text.must_equal '2'
76
+
77
+ xml.xpath('LoteRps/ListaRps/Rps').first.text.must_equal 'valor rps1'
78
+ xml.xpath('LoteRps/ListaRps/Rps').last.text.must_equal 'valor rps2'
79
+ end
80
+
81
+ it "estrutura com env = test" do
82
+ subject.env = :test
83
+ sequence1 = sequence('sequence1')
84
+ subject.expects(:xml_rps_assinado).with(rps1).in_sequence(sequence1).returns(Nokogiri::XML::Builder.new{|x| x.Rps 'valor rps1'})
85
+ subject.expects(:xml_rps_assinado).with(rps2).in_sequence(sequence1).returns(Nokogiri::XML::Builder.new{|x| x.Rps 'valor rps2'})
86
+
87
+ xml = subject.send(:lote_rps_xml).doc
88
+
89
+ xml.xpath('LoteRps').first.attr('Id').must_equal "lote#{'5568'.ljust(50, '1')}"
90
+ xml.xpath('LoteRps').first.attr('versao').must_equal '2.02'
91
+
92
+ xml.xpath('LoteRps/NumeroLote').first.text.must_equal '556811111111111'
93
+ xml.xpath('LoteRps/CpfCnpj/Cnpj').first.text.must_equal '66554778965412'
94
+ xml.xpath('LoteRps/InscricaoMunicipal').first.must_be_nil
95
+ xml.xpath('LoteRps/QuantidadeRps').first.text.must_equal '2'
96
+
97
+ xml.xpath('LoteRps/ListaRps/Rps').first.text.must_equal 'valor rps1'
98
+ xml.xpath('LoteRps/ListaRps/Rps').last.text.must_equal 'valor rps2'
99
+ end
100
+ end
101
+
102
+
103
+ end
@@ -0,0 +1,80 @@
1
+ require 'test_helper'
2
+
3
+ describe BrNfe::Servico::Betha::V2::SubstituicaoNfse do
4
+ subject { FactoryGirl.build(:br_nfe_servico_betha_v2_substituicao_nfse, emitente: emitente, rps: rps, certificado: certificado) }
5
+ let(:emitente) { FactoryGirl.build(:emitente) }
6
+ let(:rps) { FactoryGirl.build(:br_nfe_rps) }
7
+ let(:certificado) { Certificado.new }
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(:certificado) }
15
+ it { must validate_presence_of(:numero_nfse) }
16
+ it { must validate_presence_of(:codigo_cancelamento) }
17
+
18
+ context "deve validar o rps" do
19
+ it "quando o rps for válido não deve setar nenhuma mensagem no objeto" do
20
+ rps.stubs(:errors).returns(stub(full_messages: ["Erro rps"]))
21
+ sequence_1 = sequence('sequence_1')
22
+ rps.expects(:validar_recepcao_rps=).with(true).in_sequence(sequence_1)
23
+ rps.expects(:invalid?).returns(false).in_sequence(sequence_1)
24
+ subject.valid?.must_equal true
25
+ subject.errors.full_messages.must_equal( [] )
26
+ end
27
+ it "quando o rps for inválido deve setar mensagem de erro no objeto" do
28
+ rps.stubs(:errors).returns(stub(full_messages: ["Erro rps"]))
29
+ sequence_1 = sequence('sequence_1')
30
+ rps.expects(:validar_recepcao_rps=).with(true).in_sequence(sequence_1)
31
+ rps.expects(:invalid?).returns(true).in_sequence(sequence_1)
32
+ subject.valid?.must_equal false
33
+ subject.errors.full_messages.must_equal( ["RPS: Erro rps"] )
34
+ end
35
+
36
+ end
37
+ end
38
+
39
+ describe "#method_wsdl" do
40
+ it { subject.method_wsdl.must_equal :substituir_nfse }
41
+ end
42
+
43
+ describe "#xml_builder" do
44
+ it "não ocorre erro" do
45
+ subject.stubs(:assinatura_xml).returns('<Signature>signed</Signature>')
46
+ subject.xml_builder.class.must_equal Nokogiri::XML::Builder
47
+ end
48
+ it "estrutura" do
49
+ xml_substituicao = Nokogiri::XML::Builder.new{|x| x.Substituicao 'valor subs'}
50
+ subject.expects(:xml_substituicao_nfse).returns(xml_substituicao)
51
+ subject.expects(:assinatura_xml).with(xml_substituicao.doc.root.to_s, '#substituicao').returns('<Signature>signed</Signature>')
52
+ xml = subject.xml_builder.doc
53
+
54
+ xml.namespaces.must_equal({"xmlns"=>"http://www.betha.com.br/e-nota-contribuinte-ws"})
55
+ xml.remove_namespaces!
56
+
57
+ xml.xpath('SubstituirNfseEnvio/Substituicao').first.text.must_equal 'valor subs'
58
+ xml.xpath('SubstituirNfseEnvio/Signature').first.text.must_equal 'signed'
59
+ end
60
+ end
61
+
62
+ describe "#xml_substituicao_nfse" do
63
+ it "não ocorre erro" do
64
+ subject.stubs(:assinatura_xml).returns('<Signature>signed</Signature>')
65
+ subject.xml_substituicao_nfse.class.must_equal Nokogiri::XML::Builder
66
+ end
67
+ it "estrutura" do
68
+ sequence1 = sequence('sequence1')
69
+ subject.expects(:xml_pedido_cancelamento_assinado).in_sequence(sequence1).returns(Nokogiri::XML::Builder.new{|x| x.Pedido 'valor pedido'})
70
+ subject.expects(:xml_rps_assinado).with(rps).in_sequence(sequence1).returns(Nokogiri::XML::Builder.new{|x| x.Rps 'valor rps'})
71
+ xml = subject.xml_substituicao_nfse.doc
72
+
73
+ xml.xpath('SubstituicaoNfse').first.attr('Id').must_equal 'substituicao'
74
+ xml.xpath('SubstituicaoNfse/Pedido').first.text.must_equal 'valor pedido'
75
+ xml.xpath('SubstituicaoNfse/Rps').first.text.must_equal 'valor rps'
76
+ end
77
+ end
78
+
79
+
80
+ end
@@ -0,0 +1,16 @@
1
+ require 'test_helper'
2
+
3
+ describe BrNfe::Servico::Intermediario do
4
+ subject { FactoryGirl.build(:intermediario) }
5
+ describe "validations" do
6
+ it { must validate_presence_of(:cpf_cnpj) }
7
+ it { must validate_presence_of(:razao_social) }
8
+ end
9
+
10
+ describe "#razao_social" do
11
+ it "deve retornar a string em maiusculoo e sem acentos" do
12
+ subject.razao_social = 'ó têxtú dève vìr SÉM ÀçÊnTÕ'
13
+ subject.razao_social.must_equal "O TEXTU DEVE VIR SEM ACENTO"
14
+ end
15
+ end
16
+ end