require 'spec_helper'
describe BrDanfe::DanfeLib::NfeLib::Dest do
let(:path_of_expected_pdf) { './spec/fixtures/nfe/lib/output.pdf' }
let(:pdf) { BrDanfe::DanfeLib::NfeLib::Document.new }
let(:xml) { BrDanfe::XML.new(xml_as_string) }
subject { described_class.new(pdf, xml) }
describe '#render' do
before do
File.delete(path_of_expected_pdf) if File.exist?(path_of_expected_pdf)
subject.render
end
context "when nf-e's version is 2.00" do
let(:xml_as_string) do
<<~XML
2011-10-29
2011-10-30
15:32:45
82743287000880
Schneider Electric Brasil Ltda
Av da Saudade
1125
Frutal
Sala 01 e 02
3552403
SUMARE
SP
13171320
1058
BRASIL
1921046300
671008375110
XML
end
it 'renders xml to the pdf' do
expect(File.exist?(path_of_expected_pdf)).to be false
pdf.render_file path_of_expected_pdf
expect('./spec/fixtures/nfe/lib/dest#render-v2.00.pdf').to have_same_content_of file: path_of_expected_pdf
end
end
context "when nf-e's version is 3.10" do
let(:xml_as_string) do
<<~XML
2011-09-29T13:02:59+00:00
2011-09-30T12:32:45-03:00
82743287000880
Schneider Electric Brasil Ltda
Av da Saudade
1125
Frutal
Sala 01 e 02
3552403
SUMARE
SP
13171320
1058
BRASIL
1921046300
671008375110
XML
end
it 'renders xml to the pdf' do
expect(File.exist?(path_of_expected_pdf)).to be false
pdf.render_file path_of_expected_pdf
expect('./spec/fixtures/nfe/lib/dest#render-v3.10.pdf').to have_same_content_of file: path_of_expected_pdf
end
end
context "when nf-e's version is 4.00" do
let(:xml_as_string) do
<<~XML
2018-07-30T13:30:59+00:00
2018-07-30T14:32:45-03:00
82743287000880
Schneider Electric Brasil Ltda
Av da Saudade
1125
Frutal
Sala 01 e 02
3552403
SUMARE
SP
13171320
1058
BRASIL
1921046300
671008375110
XML
end
it 'renders xml to the pdf' do
expect(File.exist?(path_of_expected_pdf)).to be false
pdf.render_file path_of_expected_pdf
expect('./spec/fixtures/nfe/lib/dest#render-v4.00.pdf').to have_same_content_of file: path_of_expected_pdf
end
end
context 'when recipient has CNPJ' do
let(:xml_as_string) do
<<~XML
71058884000183
XML
end
it 'renders xml to the pdf' do
expect(File.exist?(path_of_expected_pdf)).to be false
pdf.render_file path_of_expected_pdf
expect('./spec/fixtures/nfe/lib/dest#render-with_cnpj.pdf').to have_same_content_of file: path_of_expected_pdf
end
end
context 'when recipient has CPF' do
let(:xml_as_string) do
<<~XML
48532557457
XML
end
it 'renders xml to the pdf' do
expect(File.exist?(path_of_expected_pdf)).to be false
pdf.render_file path_of_expected_pdf
expect('./spec/fixtures/nfe/lib/dest#render-with_cpf.pdf').to have_same_content_of file: path_of_expected_pdf
end
end
context 'when recipient has IE' do
let(:xml_as_string) do
<<~XML
SP
671008375110
XML
end
it 'renders xml to the pdf' do
expect(File.exist?(path_of_expected_pdf)).to be false
pdf.render_file path_of_expected_pdf
expect('./spec/fixtures/nfe/lib/dest#render-with_ie.pdf').to have_same_content_of file: path_of_expected_pdf
end
end
context "when recipient doesn't have address complement" do
let(:xml_as_string) do
<<~XML
2011-09-29T13:02:59+00:00
2011-09-30T12:32:45-03:00
82743287000880
Schneider Electric Brasil Ltda
Av da Saudade
1125
Frutal
3552403
SUMARE
SP
13171320
1058
BRASIL
1921046300
671008375110
XML
end
it 'renders xml to the pdf' do
expect(File.exist?(path_of_expected_pdf)).to be false
pdf.render_file path_of_expected_pdf
expect('./spec/fixtures/nfe/lib/dest#render-without-address-complement.pdf')
.to have_same_content_of file: path_of_expected_pdf
end
end
context 'when recipient address (xLgr + nro + xCpl) has more than 63 characters' do
let(:xml_as_string) do
<<~XML
2011-09-29T13:02:59+00:00
2011-09-30T12:32:45-03:00
82743287000880
Schneider Electric Brasil Ltda
Rua do governo do estado
1125
Em anexo ao super mercado maior do bairro
Frutal
3552403
SUMARE
SP
13171320
1058
BRASIL
1921046300
671008375110
XML
end
it 'renders xml to pdf discarding the address of after 63 characters' do
expect(File.exist?(path_of_expected_pdf)).to be false
pdf.render_file path_of_expected_pdf
expect('./spec/fixtures/nfe/lib/dest#render-with-address-bigger.pdf')
.to have_same_content_of file: path_of_expected_pdf
end
end
end
end