br_nfe 1.0.0
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.
- checksums.yaml +7 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +169 -0
- data/LICENSE +20 -0
- data/README.markdown +6 -0
- data/Rakefile +13 -0
- data/br_nfe.gemspec +28 -0
- data/lib/br_nfe/active_model_base.rb +62 -0
- data/lib/br_nfe/base.rb +168 -0
- data/lib/br_nfe/condicao_pagamento.rb +26 -0
- data/lib/br_nfe/destinatario.rb +26 -0
- data/lib/br_nfe/emitente.rb +40 -0
- data/lib/br_nfe/endereco.rb +44 -0
- data/lib/br_nfe/helper/cpf_cnpj.rb +60 -0
- data/lib/br_nfe/helper/have_address.rb +29 -0
- data/lib/br_nfe/helper/have_condicao_pagamento.rb +24 -0
- data/lib/br_nfe/helper/have_destinatario.rb +18 -0
- data/lib/br_nfe/helper/have_emitente.rb +20 -0
- data/lib/br_nfe/helper/have_intermediario.rb +24 -0
- data/lib/br_nfe/helper/have_rps.rb +27 -0
- data/lib/br_nfe/helper/string_methods.rb +21 -0
- data/lib/br_nfe/seed.rb +195 -0
- data/lib/br_nfe/servico/base.rb +35 -0
- data/lib/br_nfe/servico/betha/base.rb +74 -0
- data/lib/br_nfe/servico/betha/v1/build_response.rb +219 -0
- data/lib/br_nfe/servico/betha/v1/cancelamento_nfs.rb +52 -0
- data/lib/br_nfe/servico/betha/v1/consulta_lote_rps.rb +31 -0
- data/lib/br_nfe/servico/betha/v1/consulta_nfs_por_rps.rb +34 -0
- data/lib/br_nfe/servico/betha/v1/consulta_nfse.rb +50 -0
- data/lib/br_nfe/servico/betha/v1/consulta_situacao_lote_rps.rb +18 -0
- data/lib/br_nfe/servico/betha/v1/gateway.rb +115 -0
- data/lib/br_nfe/servico/betha/v1/recepcao_lote_rps.rb +89 -0
- data/lib/br_nfe/servico/betha/v2/cancelamento_nfs.rb +25 -0
- data/lib/br_nfe/servico/betha/v2/consulta_lote_rps.rb +27 -0
- data/lib/br_nfe/servico/betha/v2/consulta_nfse_por_rps.rb +27 -0
- data/lib/br_nfe/servico/betha/v2/envio_lote_rps_sincrono.rb +26 -0
- data/lib/br_nfe/servico/betha/v2/gateway.rb +198 -0
- data/lib/br_nfe/servico/betha/v2/gera_nfse.rb +25 -0
- data/lib/br_nfe/servico/betha/v2/recepcao_lote_rps.rb +47 -0
- data/lib/br_nfe/servico/betha/v2/response.rb +23 -0
- data/lib/br_nfe/servico/betha/v2/substituicao_nfse.rb +39 -0
- data/lib/br_nfe/servico/intermediario.rb +17 -0
- data/lib/br_nfe/servico/response/default.rb +34 -0
- data/lib/br_nfe/servico/response/nota_fiscal.rb +73 -0
- data/lib/br_nfe/servico/rps.rb +103 -0
- data/lib/br_nfe/version.rb +8 -0
- data/lib/br_nfe.rb +146 -0
- data/test/br_nfe/base_test.rb +274 -0
- data/test/br_nfe/condicao_pagamento_test.rb +23 -0
- data/test/br_nfe/destinatario_test.rb +26 -0
- data/test/br_nfe/emitente_test.rb +26 -0
- data/test/br_nfe/endereco_test.rb +50 -0
- data/test/br_nfe/helper/have_address_test.rb +62 -0
- data/test/br_nfe/helper/have_condicao_pagamento_test.rb +71 -0
- data/test/br_nfe/helper/have_destinatario_test.rb +64 -0
- data/test/br_nfe/helper/have_emitente_test.rb +63 -0
- data/test/br_nfe/helper/have_intermediario_test.rb +77 -0
- data/test/br_nfe/helper/have_rps_test.rb +59 -0
- data/test/br_nfe/servico/base_test.rb +23 -0
- data/test/br_nfe/servico/betha/base_test.rb +106 -0
- data/test/br_nfe/servico/betha/v1/build_response_test.rb +558 -0
- data/test/br_nfe/servico/betha/v1/cancelamento_nfs_test.rb +62 -0
- data/test/br_nfe/servico/betha/v1/consulta_lote_rps_test.rb +42 -0
- data/test/br_nfe/servico/betha/v1/consulta_nfs_por_rps_test.rb +68 -0
- data/test/br_nfe/servico/betha/v1/consulta_nfse_test.rb +57 -0
- data/test/br_nfe/servico/betha/v1/consulta_situacao_lote_rps_test.rb +27 -0
- data/test/br_nfe/servico/betha/v1/gateway_test.rb +174 -0
- data/test/br_nfe/servico/betha/v1/recepcao_lote_rps_test.rb +235 -0
- data/test/br_nfe/servico/response/default_test.rb +54 -0
- data/test/br_nfe/servico/response/nota_fiscal_test.rb +41 -0
- data/test/br_nfe/servico/rps_test.rb +214 -0
- data/test/certificado.rb +12 -0
- data/test/factories/base.rb +5 -0
- data/test/factories/condicao_pagamento.rb +10 -0
- data/test/factories/destinatario.rb +11 -0
- data/test/factories/emitente.rb +15 -0
- data/test/factories/endereco.rb +12 -0
- data/test/factories/servico/base.rb +5 -0
- data/test/factories/servico/betha/base.rb +5 -0
- data/test/factories/servico/betha/v1/build_response.rb +6 -0
- data/test/factories/servico/betha/v1/cancelamento_nfs.rb +7 -0
- data/test/factories/servico/betha/v1/consulta_lote_rps.rb +6 -0
- data/test/factories/servico/betha/v1/consulta_nfs_por_rps.rb +6 -0
- data/test/factories/servico/betha/v1/consulta_nfse.rb +8 -0
- data/test/factories/servico/betha/v1/consulta_situacao_lote_rps.rb +6 -0
- data/test/factories/servico/betha/v1/gateway.rb +5 -0
- data/test/factories/servico/betha/v1/recepcao_lote_rps.rb +6 -0
- data/test/factories/servico/intermediario.rb +7 -0
- data/test/factories/servico/response/default.rb +10 -0
- data/test/factories/servico/response/nota_fiscal.rb +47 -0
- data/test/factories/servico/rps.rb +44 -0
- data/test/test_helper.rb +39 -0
- metadata +263 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
require 'br_nfe/helper/have_rps'
|
|
3
|
+
|
|
4
|
+
describe BrNfe::Servico::Betha::V1::ConsultaNfsPorRps do
|
|
5
|
+
subject { FactoryGirl.build(:servico_betha_consulta_nfs_por_rps, emitente: emitente) }
|
|
6
|
+
let(:emitente) { FactoryGirl.build(:emitente) }
|
|
7
|
+
let(:rps) { subject.rps }
|
|
8
|
+
|
|
9
|
+
describe "superclass" do
|
|
10
|
+
it { subject.class.superclass.must_equal BrNfe::Servico::Betha::V1::Gateway }
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
describe "#wsdl" do
|
|
14
|
+
context "for env production" do
|
|
15
|
+
it { subject.wsdl.must_equal 'http://e-gov.betha.com.br/e-nota-contribuinte-ws/consultarNfsePorRps?wsdl' }
|
|
16
|
+
end
|
|
17
|
+
context "for env test" do
|
|
18
|
+
before do
|
|
19
|
+
subject.env = :test
|
|
20
|
+
end
|
|
21
|
+
it { subject.wsdl.must_equal 'http://e-gov.betha.com.br/e-nota-contribuinte-test-ws/consultarNfsePorRps?wsdl' }
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
describe "#method_wsdl" do
|
|
26
|
+
it { subject.method_wsdl.must_equal :consultar_nfse_por_rps }
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
describe "rps" do
|
|
30
|
+
include BrNfeTest::HelperTest::HaveRpsTest
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
describe "#xml_builder" do
|
|
34
|
+
it "deve adicionar o valor do xml_inf_pedido_cancelamento e assinar o xml" do
|
|
35
|
+
xml = subject.xml_builder.to_s
|
|
36
|
+
xml = Nokogiri::XML xml
|
|
37
|
+
|
|
38
|
+
xml.xpath('Temp/Prestador/Cnpj').first.text.must_equal emitente.cnpj
|
|
39
|
+
xml.xpath('Temp/Prestador/InscricaoMunicipal').first.text.must_equal emitente.inscricao_municipal
|
|
40
|
+
|
|
41
|
+
xml.xpath('Temp/IdentificacaoRps/Numero').first.text.must_equal rps.numero.to_s
|
|
42
|
+
xml.xpath('Temp/IdentificacaoRps/Serie').first.text.must_equal rps.serie.to_s
|
|
43
|
+
xml.xpath('Temp/IdentificacaoRps/Tipo').first.text.must_equal rps.tipo.to_s
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
describe "#set_response" do
|
|
48
|
+
let(:hash_response) { {envelope: {body: {consultar_nfse_por_rps_envio_response: 'valor_hash'} } } }
|
|
49
|
+
let(:response) { FactoryGirl.build(:response_default) }
|
|
50
|
+
let(:build_response) { FactoryGirl.build(:betha_v1_build_response) }
|
|
51
|
+
|
|
52
|
+
it "deve instanciar um objeto response pelo build_response" do
|
|
53
|
+
res = Object.new
|
|
54
|
+
res.stubs(:hash).returns( hash_response )
|
|
55
|
+
build_response.stubs(:response).returns(response)
|
|
56
|
+
|
|
57
|
+
BrNfe::Servico::Betha::V1::BuildResponse.expects(:new).
|
|
58
|
+
with({hash: 'valor_hash', nfe_method: :consultar_nfse_rps}).
|
|
59
|
+
returns(build_response)
|
|
60
|
+
|
|
61
|
+
subject.instance_variable_get(:@response).must_be_nil
|
|
62
|
+
|
|
63
|
+
subject.set_response(res).must_equal response
|
|
64
|
+
subject.instance_variable_get(:@response).must_equal response
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
describe BrNfe::Servico::Betha::V1::ConsultaNfse do
|
|
4
|
+
subject { FactoryGirl.build(:servico_betha_consulta_nfse, emitente: emitente) }
|
|
5
|
+
let(:emitente) { FactoryGirl.build(:emitente) }
|
|
6
|
+
|
|
7
|
+
describe "superclass" do
|
|
8
|
+
it { subject.class.superclass.must_equal BrNfe::Servico::Betha::V1::Gateway }
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
describe "#wsdl" do
|
|
12
|
+
context "for env production" do
|
|
13
|
+
it { subject.wsdl.must_equal 'http://e-gov.betha.com.br/e-nota-contribuinte-ws/consultarNfse?wsdl' }
|
|
14
|
+
end
|
|
15
|
+
context "for env test" do
|
|
16
|
+
before do
|
|
17
|
+
subject.env = :test
|
|
18
|
+
end
|
|
19
|
+
it { subject.wsdl.must_equal 'http://e-gov.betha.com.br/e-nota-contribuinte-test-ws/consultarNfse?wsdl' }
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
describe "#method_wsdl" do
|
|
24
|
+
it { subject.method_wsdl.must_equal :consultar_nfse }
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
describe "#xml_builder" do
|
|
28
|
+
before do
|
|
29
|
+
subject.assign_attributes(data_inicial: Date.parse('01/09/2015'), data_final: Date.parse('10/09/2015'))
|
|
30
|
+
end
|
|
31
|
+
it "estrutura com numero da nfse" do
|
|
32
|
+
xml = subject.xml_builder.to_s
|
|
33
|
+
xml = Nokogiri::XML xml
|
|
34
|
+
|
|
35
|
+
xml.xpath('Temp/Prestador/Cnpj').first.text.must_equal emitente.cnpj
|
|
36
|
+
xml.xpath('Temp/Prestador/InscricaoMunicipal').first.text.must_equal emitente.inscricao_municipal
|
|
37
|
+
|
|
38
|
+
xml.xpath('Temp/NumeroNfse').first.text.must_equal subject.numero_nfse
|
|
39
|
+
xml.xpath('Temp/PeriodoEmissao/DataInicial').first.text.must_equal '2015-09-01'
|
|
40
|
+
xml.xpath('Temp/PeriodoEmissao/DataFinal').first.text.must_equal '2015-09-10'
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it "estrutura sem numero da nfse" do
|
|
44
|
+
subject.numero_nfse = ''
|
|
45
|
+
|
|
46
|
+
xml = subject.xml_builder.to_s
|
|
47
|
+
xml = Nokogiri::XML xml
|
|
48
|
+
|
|
49
|
+
xml.xpath('Temp/Prestador/Cnpj').first.text.must_equal emitente.cnpj
|
|
50
|
+
xml.xpath('Temp/Prestador/InscricaoMunicipal').first.text.must_equal emitente.inscricao_municipal
|
|
51
|
+
|
|
52
|
+
xml.xpath('Temp/NumeroNfse').first.must_be_nil
|
|
53
|
+
xml.xpath('Temp/PeriodoEmissao/DataInicial').first.text.must_equal '2015-09-01'
|
|
54
|
+
xml.xpath('Temp/PeriodoEmissao/DataFinal').first.text.must_equal '2015-09-10'
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
describe BrNfe::Servico::Betha::V1::ConsultaSituacaoLoteRps do
|
|
4
|
+
subject { FactoryGirl.build(:servico_betha_consulta_situacao_lote_rps, emitente: emitente) }
|
|
5
|
+
let(:emitente) { FactoryGirl.build(:emitente) }
|
|
6
|
+
|
|
7
|
+
describe "superclass" do
|
|
8
|
+
it { subject.class.superclass.must_equal BrNfe::Servico::Betha::V1::ConsultaLoteRps }
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
describe "#wsdl" do
|
|
12
|
+
context "for env production" do
|
|
13
|
+
it { subject.wsdl.must_equal 'http://e-gov.betha.com.br/e-nota-contribuinte-ws/consultarSituacaoLoteRps?wsdl' }
|
|
14
|
+
end
|
|
15
|
+
context "for env test" do
|
|
16
|
+
before do
|
|
17
|
+
subject.env = :test
|
|
18
|
+
end
|
|
19
|
+
it { subject.wsdl.must_equal 'http://e-gov.betha.com.br/e-nota-contribuinte-test-ws/consultarSituacaoLoteRps?wsdl' }
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
describe "#method_wsdl" do
|
|
24
|
+
it { subject.method_wsdl.must_equal :consultar_situacao_lote_rps }
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
describe BrNfe::Servico::Betha::V1::Gateway do
|
|
4
|
+
subject { FactoryGirl.build(:br_nfe_servico_betha_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:ns1" => "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 ns1" do
|
|
21
|
+
subject.namespace_identifier.must_equal :ns1
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
describe "#version" do
|
|
26
|
+
it { subject.version.must_equal :v1 }
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
describe "#content_xml" do
|
|
30
|
+
it "canonicaliza o xml_builder e remove as tags <Temp>" do
|
|
31
|
+
subject.expects(:xml_builder).returns('<?xml version="1.0" encoding="UTF-8"?>'+"\n<Temp>\n\t <AlgumaTag>ValorXXX</AlgumaTag>\n</Temp>")
|
|
32
|
+
subject.content_xml.must_equal "<AlgumaTag>ValorXXX</AlgumaTag>"
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
describe "#tag_dados_servico" do
|
|
37
|
+
it "deve vir com a estrutura adecuada com todos os valores preenchidos" do
|
|
38
|
+
xml = Nokogiri::XML::Builder.new do |xml|
|
|
39
|
+
subject.send(:tag_dados_servico, xml, rps)
|
|
40
|
+
end.doc
|
|
41
|
+
|
|
42
|
+
xml.xpath('Servico/ItemListaServico').first.text.must_equal rps.item_lista_servico
|
|
43
|
+
xml.xpath('Servico/CodigoCnae').first.text.must_equal rps.codigo_cnae
|
|
44
|
+
xml.xpath('Servico/CodigoTributacaoMunicipio').first.text.must_equal rps.codigo_tributacao_municipio
|
|
45
|
+
xml.xpath('Servico/Discriminacao').first.text.must_equal rps.discriminacao
|
|
46
|
+
xml.xpath('Servico/CodigoMunicipio').first.text.must_equal rps.codigo_municipio
|
|
47
|
+
|
|
48
|
+
xml.xpath('Servico/Valores/ValorServicos').first.text.must_equal rps.valor_servicos.to_f.round(2).to_s
|
|
49
|
+
xml.xpath('Servico/Valores/IssRetido').first.text.must_equal '2'
|
|
50
|
+
xml.xpath('Servico/Valores/BaseCalculo').first.text.must_equal rps.base_calculo.to_f.round(2).to_s
|
|
51
|
+
xml.xpath('Servico/Valores/ValorDeducoes').first.text.must_equal rps.valor_deducoes.to_f.round(2).to_s
|
|
52
|
+
xml.xpath('Servico/Valores/ValorPis').first.text.must_equal rps.valor_pis.to_f.round(2).to_s
|
|
53
|
+
xml.xpath('Servico/Valores/ValorCofins').first.text.must_equal rps.valor_cofins.to_f.round(2).to_s
|
|
54
|
+
xml.xpath('Servico/Valores/ValorInss').first.text.must_equal rps.valor_inss.to_f.round(2).to_s
|
|
55
|
+
xml.xpath('Servico/Valores/ValorIr').first.text.must_equal rps.valor_ir.to_f.round(2).to_s
|
|
56
|
+
xml.xpath('Servico/Valores/ValorCsll').first.text.must_equal rps.valor_csll.to_f.round(2).to_s
|
|
57
|
+
xml.xpath('Servico/Valores/ValorIss').first.text.must_equal rps.valor_iss.to_f.round(2).to_s
|
|
58
|
+
xml.xpath('Servico/Valores/OutrasRetencoes').first.text.must_equal rps.outras_retencoes.to_f.round(2).to_s
|
|
59
|
+
xml.xpath('Servico/Valores/Aliquota').first.text.must_equal rps.aliquota.to_f.round(2).to_s
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it "sem os valores não obrigatórios" do
|
|
63
|
+
rps.assign_attributes({valor_deducoes: '', valor_pis: '', valor_cofins: '',
|
|
64
|
+
valor_inss: '', valor_ir: '', valor_csll: '', valor_iss: '', outras_retencoes: '',
|
|
65
|
+
aliquota: '', codigo_cnae: '', codigo_tributacao_municipio: ''
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
xml = Nokogiri::XML::Builder.new do |xml|
|
|
69
|
+
subject.send(:tag_dados_servico, xml, rps)
|
|
70
|
+
end.doc
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
xml.xpath('Servico/CodigoCnae').first.must_be_nil
|
|
74
|
+
xml.xpath('Servico/CodigoTributacaoMunicipio').first.must_be_nil
|
|
75
|
+
xml.xpath('Servico/Valores/ValorDeducoes').first.must_be_nil
|
|
76
|
+
xml.xpath('Servico/Valores/ValorPis').first.must_be_nil
|
|
77
|
+
xml.xpath('Servico/Valores/ValorCofins').first.must_be_nil
|
|
78
|
+
xml.xpath('Servico/Valores/ValorInss').first.must_be_nil
|
|
79
|
+
xml.xpath('Servico/Valores/ValorIr').first.must_be_nil
|
|
80
|
+
xml.xpath('Servico/Valores/ValorCsll').first.must_be_nil
|
|
81
|
+
xml.xpath('Servico/Valores/ValorIss').first.must_be_nil
|
|
82
|
+
xml.xpath('Servico/Valores/OutrasRetencoes').first.must_be_nil
|
|
83
|
+
xml.xpath('Servico/Valores/Aliquota').first.must_be_nil
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
context "#tag_prestador" do
|
|
88
|
+
it "estrutura com todos os atributos" do
|
|
89
|
+
xml = Nokogiri::XML::Builder.new do |xml|
|
|
90
|
+
subject.send(:tag_prestador, xml)
|
|
91
|
+
end.doc
|
|
92
|
+
|
|
93
|
+
xml.xpath('Prestador/Cnpj').first.text.must_equal emitente.cnpj
|
|
94
|
+
xml.xpath('Prestador/InscricaoMunicipal').first.text.must_equal emitente.inscricao_municipal
|
|
95
|
+
end
|
|
96
|
+
it "estrutura sem os atributos não obrigatorios" do
|
|
97
|
+
emitente.inscricao_municipal = ''
|
|
98
|
+
|
|
99
|
+
xml = Nokogiri::XML::Builder.new do |xml|
|
|
100
|
+
subject.send(:tag_prestador, xml)
|
|
101
|
+
end.doc
|
|
102
|
+
|
|
103
|
+
xml.xpath('Prestador/InscricaoMunicipal').first.must_be_nil
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
context "#tag_intermediario_servico" do
|
|
108
|
+
it "estrutura com todos os atributos" do
|
|
109
|
+
xml = Nokogiri::XML::Builder.new do |xml|
|
|
110
|
+
subject.send(:tag_intermediario_servico, xml, intermediario)
|
|
111
|
+
end.doc
|
|
112
|
+
|
|
113
|
+
xml.xpath('IntermediarioServico/RazaoSocial').first.text.must_equal intermediario.razao_social
|
|
114
|
+
xml.xpath('IntermediarioServico/CpfCnpj/Cnpj').first.text.must_equal BrNfe::Helper::CpfCnpj.new(intermediario.cpf_cnpj).sem_formatacao
|
|
115
|
+
xml.xpath('IntermediarioServico/InscricaoMunicipal').first.text.must_equal intermediario.inscricao_municipal
|
|
116
|
+
end
|
|
117
|
+
it "estrutura sem os atributos não obrigatorios" do
|
|
118
|
+
intermediario.assign_attributes({cpf_cnpj: '132.456.789-01', inscricao_municipal: ''})
|
|
119
|
+
xml = Nokogiri::XML::Builder.new do |xml|
|
|
120
|
+
subject.send(:tag_intermediario_servico, xml, intermediario)
|
|
121
|
+
end.doc
|
|
122
|
+
|
|
123
|
+
xml.xpath('IntermediarioServico/CpfCnpj/Cpf').first.text.must_equal BrNfe::Helper::CpfCnpj.new(intermediario.cpf_cnpj).sem_formatacao
|
|
124
|
+
xml.xpath('IntermediarioServico/InscricaoMunicipal').first.must_be_nil
|
|
125
|
+
end
|
|
126
|
+
it "se não tiver intermediario não monta o xml" do
|
|
127
|
+
xml = Nokogiri::XML::Builder.new do |xml|
|
|
128
|
+
subject.send(:tag_intermediario_servico, xml, nil)
|
|
129
|
+
end.doc
|
|
130
|
+
|
|
131
|
+
xml.root.to_s.must_equal ''
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
describe "#tag_condicao_pagamento" do
|
|
136
|
+
it "estrutura a prazo" do
|
|
137
|
+
xml = Nokogiri::XML::Builder.new do |xml|
|
|
138
|
+
subject.send(:tag_condicao_pagamento, xml, rps)
|
|
139
|
+
end.doc
|
|
140
|
+
|
|
141
|
+
xml.xpath('CondicaoPagamento/Condicao').first.text.must_equal rps.condicao_pagamento.condicao
|
|
142
|
+
xml.xpath('CondicaoPagamento/QtdParcela').first.text.must_equal '2'
|
|
143
|
+
|
|
144
|
+
xml.xpath('CondicaoPagamento/Parcelas/Parcela').first.text.must_equal '1'
|
|
145
|
+
xml.xpath('CondicaoPagamento/Parcelas/DataVencimento').first.text.must_equal '2015-10-15'
|
|
146
|
+
xml.xpath('CondicaoPagamento/Parcelas/Valor').first.text.must_equal '10.0'
|
|
147
|
+
|
|
148
|
+
xml.xpath('CondicaoPagamento/Parcelas/Parcela').last.text.must_equal '2'
|
|
149
|
+
xml.xpath('CondicaoPagamento/Parcelas/DataVencimento').last.text.must_equal '2015-11-15'
|
|
150
|
+
xml.xpath('CondicaoPagamento/Parcelas/Valor').last.text.must_equal '20.0'
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
it "estrutura a vista" do
|
|
154
|
+
rps.condicao_pagamento.assign_attributes(condicao: 'A_VISTA', parcelas: [])
|
|
155
|
+
xml = Nokogiri::XML::Builder.new do |xml|
|
|
156
|
+
subject.send(:tag_condicao_pagamento, xml, rps)
|
|
157
|
+
end.doc
|
|
158
|
+
|
|
159
|
+
xml.xpath('CondicaoPagamento/Condicao').first.text.must_equal 'A_VISTA'
|
|
160
|
+
xml.xpath('CondicaoPagamento/QtdParcela').first.must_be_nil
|
|
161
|
+
|
|
162
|
+
xml.xpath('CondicaoPagamento/Parcelas').first.must_be_nil
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
it "quando não tem condicao_pagamento" do
|
|
166
|
+
rps.condicao_pagamento = nil
|
|
167
|
+
xml = Nokogiri::XML::Builder.new do |xml|
|
|
168
|
+
subject.send(:tag_condicao_pagamento, xml, rps)
|
|
169
|
+
end.doc
|
|
170
|
+
xml.root.to_s.must_equal ''
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
end
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
describe BrNfe::Servico::Betha::V1::RecepcaoLoteRps do
|
|
4
|
+
subject { FactoryGirl.build(:br_nfe_servico_betha_recepcao_lote_rps, emitente: emitente) }
|
|
5
|
+
let(:emitente) { FactoryGirl.build(:emitente) }
|
|
6
|
+
let(:rps_1) { FactoryGirl.build(:br_nfe_rps, valor_pis: '', valor_cofins: nil, valor_inss: nil, valor_ir: nil, valor_csll: nil) }
|
|
7
|
+
let(:rps_2) { FactoryGirl.build(:br_nfe_rps, :completo) }
|
|
8
|
+
|
|
9
|
+
describe "superclass" do
|
|
10
|
+
it { subject.class.superclass.must_equal BrNfe::Servico::Betha::V1::Gateway }
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
describe "#wsdl" do
|
|
14
|
+
context "for env production" do
|
|
15
|
+
it { subject.wsdl.must_equal 'http://e-gov.betha.com.br/e-nota-contribuinte-ws/recepcionarLoteRps?wsdl' }
|
|
16
|
+
end
|
|
17
|
+
context "for env test" do
|
|
18
|
+
before do
|
|
19
|
+
subject.env = :test
|
|
20
|
+
end
|
|
21
|
+
it { subject.wsdl.must_equal 'http://e-gov.betha.com.br/e-nota-contribuinte-test-ws/recepcionarLoteRps?wsdl' }
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
describe "#method_wsdl" do
|
|
26
|
+
it { subject.method_wsdl.must_equal :enviar_lote_rps }
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
describe "#xml_inf_rps" do
|
|
30
|
+
it "estrutura com informações do rps parcialmente preenchidas" do
|
|
31
|
+
xml = subject.xml_inf_rps(rps_1).doc
|
|
32
|
+
|
|
33
|
+
xml.xpath('InfRps').first.attr("Id").must_equal "rps#{rps_1.numero}"
|
|
34
|
+
xml.xpath('InfRps/IdentificacaoRps/Numero').first.text.must_equal rps_1.numero.to_s
|
|
35
|
+
xml.xpath('InfRps/IdentificacaoRps/Serie').first.text.must_equal rps_1.serie
|
|
36
|
+
xml.xpath('InfRps/IdentificacaoRps/Tipo').first.text.must_equal rps_1.tipo
|
|
37
|
+
|
|
38
|
+
xml.xpath('InfRps/RpsSubstituido/Numero').first.must_be_nil
|
|
39
|
+
xml.xpath('InfRps/RpsSubstituido/Serie').first.must_be_nil
|
|
40
|
+
xml.xpath('InfRps/RpsSubstituido/Tipo').first.must_be_nil
|
|
41
|
+
|
|
42
|
+
xml.xpath('InfRps/DataEmissao').first.text.must_equal rps_1.data_emissao.to_s(:br_nfe)
|
|
43
|
+
xml.xpath('InfRps/NaturezaOperacao').first.text.must_equal emitente.natureza_operacao
|
|
44
|
+
xml.xpath('InfRps/RegimeEspecialTributacao').first.text.must_equal emitente.regime_especial_tributacao
|
|
45
|
+
xml.xpath('InfRps/OptanteSimplesNacional').first.text.must_equal emitente.optante_simples_nacional
|
|
46
|
+
xml.xpath('InfRps/IncentivadorCultural').first.text.must_equal emitente.incentivo_fiscal
|
|
47
|
+
xml.xpath('InfRps/Status').first.text.must_equal rps_1.status
|
|
48
|
+
|
|
49
|
+
# Serviço
|
|
50
|
+
xml.xpath('InfRps/Servico/ItemListaServico').first.text.must_equal rps_1.item_lista_servico
|
|
51
|
+
xml.xpath('InfRps/Servico/CodigoCnae').first.text.must_equal rps_1.codigo_cnae
|
|
52
|
+
xml.xpath('InfRps/Servico/CodigoTributacaoMunicipio').first.must_be_nil
|
|
53
|
+
xml.xpath('InfRps/Servico/Discriminacao').first.text.must_equal rps_1.discriminacao
|
|
54
|
+
xml.xpath('InfRps/Servico/CodigoMunicipio').first.text.must_equal rps_1.codigo_municipio
|
|
55
|
+
# Valores dos serviços
|
|
56
|
+
xml.xpath('InfRps/Servico/Valores/ValorServicos').first.text.must_equal rps_1.valor_servicos.to_f.round(2).to_s
|
|
57
|
+
xml.xpath('InfRps/Servico/Valores/IssRetido').first.text.must_equal '2'
|
|
58
|
+
xml.xpath('InfRps/Servico/Valores/BaseCalculo').first.text.must_equal rps_1.base_calculo.to_f.round(2).to_s
|
|
59
|
+
xml.xpath('InfRps/Servico/Valores/ValorDeducoes').first.text.must_equal rps_1.valor_deducoes.to_f.round(2).to_s
|
|
60
|
+
xml.xpath('InfRps/Servico/Valores/ValorPis').first.must_be_nil
|
|
61
|
+
xml.xpath('InfRps/Servico/Valores/ValorCofins').first.must_be_nil
|
|
62
|
+
xml.xpath('InfRps/Servico/Valores/ValorInss').first.must_be_nil
|
|
63
|
+
xml.xpath('InfRps/Servico/Valores/ValorIr').first.must_be_nil
|
|
64
|
+
xml.xpath('InfRps/Servico/Valores/ValorCsll').first.must_be_nil
|
|
65
|
+
xml.xpath('InfRps/Servico/Valores/ValorIss').first.text.must_equal rps_1.valor_iss
|
|
66
|
+
xml.xpath('InfRps/Servico/Valores/OutrasRetencoes').first.text.must_equal rps_1.outras_retencoes
|
|
67
|
+
xml.xpath('InfRps/Servico/Valores/Aliquota').first.text.must_equal rps_1.aliquota
|
|
68
|
+
|
|
69
|
+
# Prestador
|
|
70
|
+
xml.xpath('InfRps/Prestador/Cnpj').first.text.must_equal emitente.cnpj
|
|
71
|
+
xml.xpath('InfRps/Prestador/InscricaoMunicipal').first.text.must_equal emitente.inscricao_municipal
|
|
72
|
+
|
|
73
|
+
# Tomador
|
|
74
|
+
xml.xpath('InfRps/Tomador/RazaoSocial').first.text.must_equal rps_1.destinatario.razao_social
|
|
75
|
+
xml.xpath('InfRps/Tomador/IdentificacaoTomador/CpfCnpj/Cpf').first.text.must_equal BrNfe::Helper::CpfCnpj.new(rps_1.destinatario.cpf_cnpj).sem_formatacao
|
|
76
|
+
xml.xpath('InfRps/Tomador/IdentificacaoTomador/InscricaoMunicipal').first.text.must_equal rps_1.destinatario.inscricao_municipal
|
|
77
|
+
xml.xpath('InfRps/Tomador/IdentificacaoTomador/InscricaoEstadual').first.text.must_equal rps_1.destinatario.inscricao_estadual
|
|
78
|
+
xml.xpath('InfRps/Tomador/Endereco/Endereco').first.text.must_equal rps_1.destinatario.endereco.logradouro
|
|
79
|
+
xml.xpath('InfRps/Tomador/Endereco/Numero').first.text.must_equal rps_1.destinatario.endereco.numero
|
|
80
|
+
xml.xpath('InfRps/Tomador/Endereco/Complemento').first.text.must_equal rps_1.destinatario.endereco.complemento
|
|
81
|
+
xml.xpath('InfRps/Tomador/Endereco/Bairro').first.text.must_equal rps_1.destinatario.endereco.bairro
|
|
82
|
+
xml.xpath('InfRps/Tomador/Endereco/CodigoMunicipio').first.text.must_equal rps_1.destinatario.endereco.codigo_municipio
|
|
83
|
+
xml.xpath('InfRps/Tomador/Endereco/Uf').first.text.must_equal rps_1.destinatario.endereco.uf
|
|
84
|
+
xml.xpath('InfRps/Tomador/Endereco/Cep').first.text.must_equal rps_1.destinatario.endereco.cep.gsub(/[^0-9]/,'')
|
|
85
|
+
xml.xpath('InfRps/Tomador/Contato/Telefone').first.text.must_equal rps_1.destinatario.telefone
|
|
86
|
+
xml.xpath('InfRps/Tomador/Contato/Email').first.text.must_equal rps_1.destinatario.email
|
|
87
|
+
|
|
88
|
+
xml.xpath('InfRps/IntermediarioServico').first.must_be_nil
|
|
89
|
+
xml.xpath('InfRps/ConstrucaoCivil').first.must_be_nil
|
|
90
|
+
xml.xpath('InfRps/OutrasInformacoes').first.must_be_nil
|
|
91
|
+
xml.xpath('InfRps/CondicaoPagamento').first.must_be_nil
|
|
92
|
+
end
|
|
93
|
+
it "estrutura com toas informações do rps preenchidas" do
|
|
94
|
+
rps_2.destinatario.cpf_cnpj = '12345678901234'
|
|
95
|
+
xml = subject.xml_inf_rps(rps_2).doc
|
|
96
|
+
|
|
97
|
+
xml.xpath('InfRps').first.attr("Id").must_equal "rps#{rps_2.numero}"
|
|
98
|
+
xml.xpath('InfRps/IdentificacaoRps/Numero').first.text.must_equal rps_2.numero.to_s
|
|
99
|
+
xml.xpath('InfRps/IdentificacaoRps/Serie').first.text.must_equal rps_2.serie
|
|
100
|
+
xml.xpath('InfRps/IdentificacaoRps/Tipo').first.text.must_equal rps_2.tipo
|
|
101
|
+
|
|
102
|
+
xml.xpath('InfRps/RpsSubstituido/Numero').first.text.must_equal rps_2.numero_substituicao
|
|
103
|
+
xml.xpath('InfRps/RpsSubstituido/Serie').first.text.must_equal rps_2.serie_substituicao
|
|
104
|
+
xml.xpath('InfRps/RpsSubstituido/Tipo').first.text.must_equal rps_2.tipo_substituicao
|
|
105
|
+
|
|
106
|
+
xml.xpath('InfRps/DataEmissao').first.text.must_equal rps_2.data_emissao.to_s(:br_nfe)
|
|
107
|
+
xml.xpath('InfRps/NaturezaOperacao').first.text.must_equal emitente.natureza_operacao
|
|
108
|
+
xml.xpath('InfRps/RegimeEspecialTributacao').first.text.must_equal emitente.regime_especial_tributacao
|
|
109
|
+
xml.xpath('InfRps/OptanteSimplesNacional').first.text.must_equal emitente.optante_simples_nacional
|
|
110
|
+
xml.xpath('InfRps/IncentivadorCultural').first.text.must_equal emitente.incentivo_fiscal
|
|
111
|
+
xml.xpath('InfRps/Status').first.text.must_equal rps_2.status
|
|
112
|
+
|
|
113
|
+
# Serviço
|
|
114
|
+
xml.xpath('InfRps/Servico/ItemListaServico').first.text.must_equal rps_2.item_lista_servico
|
|
115
|
+
xml.xpath('InfRps/Servico/CodigoCnae').first.text.must_equal rps_2.codigo_cnae
|
|
116
|
+
xml.xpath('InfRps/Servico/CodigoTributacaoMunicipio').first.text.must_equal rps_2.codigo_tributacao_municipio
|
|
117
|
+
xml.xpath('InfRps/Servico/Discriminacao').first.text.must_equal rps_2.discriminacao
|
|
118
|
+
xml.xpath('InfRps/Servico/CodigoMunicipio').first.text.must_equal rps_2.codigo_municipio
|
|
119
|
+
# Valores dos serviços
|
|
120
|
+
xml.xpath('InfRps/Servico/Valores/ValorServicos').first.text.must_equal rps_2.valor_servicos.to_f.round(4).to_s
|
|
121
|
+
xml.xpath('InfRps/Servico/Valores/IssRetido').first.text.must_equal '2'
|
|
122
|
+
xml.xpath('InfRps/Servico/Valores/BaseCalculo').first.text.must_equal rps_2.base_calculo.to_f.round(4).to_s
|
|
123
|
+
xml.xpath('InfRps/Servico/Valores/ValorDeducoes').first.text.must_equal rps_2.valor_deducoes.to_f.round(4).to_s
|
|
124
|
+
xml.xpath('InfRps/Servico/Valores/ValorPis').first.text.must_equal rps_2.valor_pis.to_f.round(4).to_s
|
|
125
|
+
xml.xpath('InfRps/Servico/Valores/ValorCofins').first.text.must_equal rps_2.valor_cofins.to_f.round(4).to_s
|
|
126
|
+
xml.xpath('InfRps/Servico/Valores/ValorInss').first.text.must_equal rps_2.valor_inss.to_f.round(4).to_s
|
|
127
|
+
xml.xpath('InfRps/Servico/Valores/ValorIr').first.text.must_equal rps_2.valor_ir.to_f.round(4).to_s
|
|
128
|
+
xml.xpath('InfRps/Servico/Valores/ValorCsll').first.text.must_equal rps_2.valor_csll.to_f.round(4).to_s
|
|
129
|
+
xml.xpath('InfRps/Servico/Valores/ValorIss').first.text.must_equal rps_2.valor_iss.to_f.round(4).to_s
|
|
130
|
+
xml.xpath('InfRps/Servico/Valores/OutrasRetencoes').first.text.must_equal rps_2.outras_retencoes.to_f.round(4).to_s
|
|
131
|
+
xml.xpath('InfRps/Servico/Valores/Aliquota').first.text.must_equal rps_2.aliquota.to_f.round(4).to_s
|
|
132
|
+
|
|
133
|
+
# Prestador
|
|
134
|
+
xml.xpath('InfRps/Prestador/Cnpj').first.text.must_equal emitente.cnpj
|
|
135
|
+
xml.xpath('InfRps/Prestador/InscricaoMunicipal').first.text.must_equal emitente.inscricao_municipal
|
|
136
|
+
|
|
137
|
+
# Tomador
|
|
138
|
+
xml.xpath('InfRps/Tomador/RazaoSocial').first.text.must_equal rps_2.destinatario.razao_social
|
|
139
|
+
xml.xpath('InfRps/Tomador/IdentificacaoTomador/CpfCnpj/Cnpj').first.text.must_equal BrNfe::Helper::CpfCnpj.new(rps_2.destinatario.cpf_cnpj).sem_formatacao
|
|
140
|
+
xml.xpath('InfRps/Tomador/IdentificacaoTomador/InscricaoMunicipal').first.text.must_equal rps_2.destinatario.inscricao_municipal
|
|
141
|
+
xml.xpath('InfRps/Tomador/IdentificacaoTomador/InscricaoEstadual').first.text.must_equal rps_2.destinatario.inscricao_estadual
|
|
142
|
+
xml.xpath('InfRps/Tomador/Endereco/Endereco').first.text.must_equal rps_2.destinatario.endereco.logradouro
|
|
143
|
+
xml.xpath('InfRps/Tomador/Endereco/Numero').first.text.must_equal rps_2.destinatario.endereco.numero
|
|
144
|
+
xml.xpath('InfRps/Tomador/Endereco/Complemento').first.text.must_equal rps_2.destinatario.endereco.complemento
|
|
145
|
+
xml.xpath('InfRps/Tomador/Endereco/Bairro').first.text.must_equal rps_2.destinatario.endereco.bairro
|
|
146
|
+
xml.xpath('InfRps/Tomador/Endereco/CodigoMunicipio').first.text.must_equal rps_2.destinatario.endereco.codigo_municipio
|
|
147
|
+
xml.xpath('InfRps/Tomador/Endereco/Uf').first.text.must_equal rps_2.destinatario.endereco.uf
|
|
148
|
+
xml.xpath('InfRps/Tomador/Endereco/Cep').first.text.must_equal rps_2.destinatario.endereco.cep.gsub(/[^0-9]/,'')
|
|
149
|
+
xml.xpath('InfRps/Tomador/Contato/Telefone').first.text.must_equal rps_2.destinatario.telefone
|
|
150
|
+
xml.xpath('InfRps/Tomador/Contato/Email').first.text.must_equal rps_2.destinatario.email
|
|
151
|
+
|
|
152
|
+
xml.xpath('InfRps/IntermediarioServico/RazaoSocial').first.text.must_equal rps_2.intermediario.razao_social
|
|
153
|
+
xml.xpath('InfRps/IntermediarioServico/CpfCnpj/Cnpj').first.text.must_equal BrNfe::Helper::CpfCnpj.new(rps_2.intermediario.cpf_cnpj).sem_formatacao
|
|
154
|
+
xml.xpath('InfRps/IntermediarioServico/InscricaoMunicipal').first.text.must_equal rps_2.intermediario.inscricao_municipal
|
|
155
|
+
|
|
156
|
+
xml.xpath('InfRps/ConstrucaoCivil/CodigoObra').first.text.must_equal rps_2.codigo_obra
|
|
157
|
+
xml.xpath('InfRps/ConstrucaoCivil/Art').first.text.must_equal rps_2.codigo_art
|
|
158
|
+
|
|
159
|
+
xml.xpath('InfRps/OutrasInformacoes').first.text.must_equal rps_2.outras_informacoes
|
|
160
|
+
|
|
161
|
+
xml.xpath('InfRps/CondicaoPagamento/Condicao').first.text.must_equal rps_2.condicao_pagamento.condicao
|
|
162
|
+
xml.xpath('InfRps/CondicaoPagamento/QtdParcela').first.text.must_equal '2'
|
|
163
|
+
xml.xpath('InfRps/CondicaoPagamento/Parcelas').count.must_equal 2
|
|
164
|
+
|
|
165
|
+
xml.xpath('InfRps/CondicaoPagamento/Parcelas/Parcela').first.text.must_equal '1'
|
|
166
|
+
xml.xpath('InfRps/CondicaoPagamento/Parcelas/DataVencimento').first.text.must_equal Date.parse('15/10/2015').to_s(:br_nfe)
|
|
167
|
+
xml.xpath('InfRps/CondicaoPagamento/Parcelas/Valor').first.text.must_equal '10.0'
|
|
168
|
+
|
|
169
|
+
xml.xpath('InfRps/CondicaoPagamento/Parcelas/Parcela').last.text.must_equal '2'
|
|
170
|
+
xml.xpath('InfRps/CondicaoPagamento/Parcelas/DataVencimento').last.text.must_equal Date.parse('15/11/2015').to_s(:br_nfe)
|
|
171
|
+
xml.xpath('InfRps/CondicaoPagamento/Parcelas/Valor').last.text.must_equal '20.0'
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
describe "#lote_rps_xml" do
|
|
176
|
+
let(:info_rps_1) do
|
|
177
|
+
Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
|
|
178
|
+
xml.InfRps "RPS1"
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
let(:info_rps_2) do
|
|
182
|
+
Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
|
|
183
|
+
xml.InfRps "RPS2"
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
before do
|
|
188
|
+
rps_1.numero = '1'
|
|
189
|
+
rps_2.numero = '2'
|
|
190
|
+
subject.lote_rps = [rps_1, rps_2]
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
it "estrutura deve conter as informações assinadas de todos os RPSs do lote" do
|
|
194
|
+
subject.expects(:xml_inf_rps).with(rps_1).returns(info_rps_1)
|
|
195
|
+
subject.expects(:xml_inf_rps).with(rps_2).returns(info_rps_2)
|
|
196
|
+
|
|
197
|
+
subject.expects(:assinatura_xml).with(info_rps_1.doc.root.to_s, '#rps1').returns('<Signature>RPS_1</Signature>')
|
|
198
|
+
subject.expects(:assinatura_xml).with(info_rps_2.doc.root.to_s, '#rps2').returns('<Signature>RPS_2</Signature>')
|
|
199
|
+
|
|
200
|
+
xml = subject.lote_rps_xml.doc
|
|
201
|
+
|
|
202
|
+
xml.xpath('LoteRps/NumeroLote').first.text.must_equal subject.numero_lote_rps
|
|
203
|
+
xml.xpath('LoteRps/Cnpj').first.text.must_equal emitente.cnpj
|
|
204
|
+
xml.xpath('LoteRps/InscricaoMunicipal').first.text.must_equal emitente.inscricao_municipal
|
|
205
|
+
xml.xpath('LoteRps/QuantidadeRps').first.text.must_equal '2'
|
|
206
|
+
|
|
207
|
+
xml.xpath('LoteRps/ListaRps/Rps/InfRps').first.text.must_equal 'RPS1'
|
|
208
|
+
xml.xpath('LoteRps/ListaRps/Rps/Signature').first.text.must_equal 'RPS_1'
|
|
209
|
+
|
|
210
|
+
xml.xpath('LoteRps/ListaRps/Rps/InfRps').last.text.must_equal 'RPS2'
|
|
211
|
+
xml.xpath('LoteRps/ListaRps/Rps/Signature').last.text.must_equal 'RPS_2'
|
|
212
|
+
|
|
213
|
+
end
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
describe "#xml_builder" do
|
|
217
|
+
let(:xml_lote_rps) do
|
|
218
|
+
Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
|
|
219
|
+
xml.LoteRps "Valor lote rps"
|
|
220
|
+
end
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
it "estrutura" do
|
|
224
|
+
subject.numero_lote_rps = '8899'
|
|
225
|
+
subject.expects(:lote_rps_xml).returns(xml_lote_rps)
|
|
226
|
+
subject.expects(:assinatura_xml).with(xml_lote_rps.doc.root.to_s, '#lote8899').returns('<Signature>SIGN</Signature>')
|
|
227
|
+
|
|
228
|
+
xml = Nokogiri::XML(subject.xml_builder)
|
|
229
|
+
|
|
230
|
+
xml.xpath("Temp/LoteRps").first.text.must_equal "Valor lote rps"
|
|
231
|
+
xml.xpath("Temp/Signature").first.text.must_equal "SIGN"
|
|
232
|
+
end
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
describe BrNfe::Servico::Response::Default do
|
|
4
|
+
subject { FactoryGirl.build(:response_default) }
|
|
5
|
+
|
|
6
|
+
describe "#success?" do
|
|
7
|
+
it "when is true" do
|
|
8
|
+
subject.success = true
|
|
9
|
+
subject.success?.must_equal true
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "when is false" do
|
|
13
|
+
subject.success = false
|
|
14
|
+
subject.success?.must_equal false
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
describe "#notas_fiscais" do
|
|
19
|
+
it "deve inicializar como um vetor vazio" do
|
|
20
|
+
subject.class.new.notas_fiscais.must_equal []
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "posso utilizar o << para adicionar valores" do
|
|
24
|
+
new_object = subject.class.new
|
|
25
|
+
new_object.notas_fiscais << 'x'
|
|
26
|
+
new_object.notas_fiscais << 'y'
|
|
27
|
+
new_object.notas_fiscais.must_equal ['x','y']
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "sempre retorna um array" do
|
|
31
|
+
subject.notas_fiscais = {valor: '2'}
|
|
32
|
+
subject.notas_fiscais.must_equal [{valor: '2'}]
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
describe "#error_messages" do
|
|
37
|
+
it "deve inicializar como um vetor vazio" do
|
|
38
|
+
subject.class.new.error_messages.must_equal []
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "posso utilizar o << para adicionar valores" do
|
|
42
|
+
new_object = subject.class.new
|
|
43
|
+
new_object.error_messages << 'aaa'
|
|
44
|
+
new_object.error_messages << 'bbbbb'
|
|
45
|
+
new_object.error_messages.must_equal ['aaa','bbbbb']
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it "sempre retorna um array" do
|
|
49
|
+
subject.error_messages = {valor: '2'}
|
|
50
|
+
subject.error_messages.must_equal [{valor: '2'}]
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
require 'br_nfe/helper/have_emitente_test'
|
|
3
|
+
require 'br_nfe/helper/have_destinatario_test'
|
|
4
|
+
require 'br_nfe/helper/have_intermediario_test'
|
|
5
|
+
require 'br_nfe/helper/have_condicao_pagamento_test'
|
|
6
|
+
|
|
7
|
+
describe BrNfe::Servico::Response::NotaFiscal do
|
|
8
|
+
subject { FactoryGirl.build(:response_nota_fiscal, emitente: emitente) }
|
|
9
|
+
let(:emitente) { FactoryGirl.build(:emitente) }
|
|
10
|
+
let(:destinatario) { subject.destinatario }
|
|
11
|
+
let(:intermediario) { subject.intermediario }
|
|
12
|
+
let(:condicao_pagamento) { subject.condicao_pagamento }
|
|
13
|
+
|
|
14
|
+
describe "#emitente" do
|
|
15
|
+
include BrNfeTest::HelperTest::HaveEmitenteTest
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
describe "#destinatario" do
|
|
19
|
+
include BrNfeTest::HelperTest::HaveDestinatarioTest
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
describe "#intermediario" do
|
|
23
|
+
include BrNfeTest::HelperTest::HaveIntermediarioTest
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
describe "#condicao_pagamento" do
|
|
27
|
+
include BrNfeTest::HelperTest::HaveCondicaoPagamentoTest
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
describe "#substituida?" do
|
|
31
|
+
it "quando tem valor em nfe_substituidora" do
|
|
32
|
+
subject.nfe_substituidora = '666'
|
|
33
|
+
subject.substituida?.must_equal true
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "quando não tem valor na nfe_substituidora" do
|
|
37
|
+
subject.nfe_substituidora = ''
|
|
38
|
+
subject.substituida?.must_equal false
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|