require 'spec_helper'
describe BrDanfe::DanfeLib::NfeLib::Infadic do
let(:base_dir) { './spec/fixtures/nfe/lib/' }
let(:output_pdf) { "#{base_dir}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
let(:volumes_number) { 1 }
before do
subject.render(volumes_number)
File.delete(output_pdf) if File.exist?(output_pdf)
end
context 'when there is no information' do
let(:xml_as_string) do
<<-EOS
1
VOLUMES 1
DIVERSOS 1
1
1000.000
1100.000
2
VOLUMES 2
DIVERSOS 2
2
2000.000
2200.000
3
VOLUMES 3
DIVERSOS 3
3
3000.000
3300.000
4892.78
75394.78
EOS
end
it 'renders title with box, subtitle and fisco box on the pdf' do
expect(File.exist?(output_pdf)).to be_falsey
pdf.render_file output_pdf
expect("#{base_dir}infadic#render.pdf").to have_same_content_of file: output_pdf
end
end
context 'when has difal' do
let(:xml_as_string) do
<<-EOS
1
VOLUMES 1
DIVERSOS 1
1
1000.000
1100.000
2
VOLUMES 2
DIVERSOS 2
2
2000.000
2200.000
3
VOLUMES 3
DIVERSOS 3
3
3000.000
3300.000
4892.78
2915.78
75394.78
EOS
end
it 'renders title with box, subtitle, fisco box and difal on the pdf' do
expect(File.exist?(output_pdf)).to be_falsey
pdf.render_file output_pdf
expect("#{base_dir}infadic#render-difal.pdf").to have_same_content_of file: output_pdf
end
end
context 'when has too big address' do
let(:xml_as_string) do
<<-EOS
2011-10-29
2011-10-30
15:32:45
82743287000880
Schneider Electric Brasil Ltda
Av da Saudade
1125
Frutal
Em anexo ao super mercado maior do bairro
3552403
SUMARE
SP
13171320
1058
BRASIL
1921046300
671008375110
EOS
end
it 'renders title with box, subtitle, fisco box and address on the pdf' do
expect(File.exist?(output_pdf)).to be_falsey
pdf.render_file output_pdf
expect("#{base_dir}infadic#render-with_street_data.pdf").to have_same_content_of file: output_pdf
end
end
context 'when has complementary information' do
let(:xml_as_string) do
<<-EOS
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
1
VOLUMES 1
DIVERSOS 1
1
1000.000
1100.000
2
VOLUMES 2
DIVERSOS 2
2
2000.000
2200.000
3
VOLUMES 3
DIVERSOS 3
3
3000.000
3300.000
Uma observação
0.00
0.00
0.00
EOS
end
it 'renders title with box, subtitle, fisco box and complementary ' \
'information on the pdf' do
expect(File.exist?(output_pdf)).to be_falsey
pdf.render_file output_pdf
expect("#{base_dir}infadic#render-with_complementary_information.pdf").to have_same_content_of file: output_pdf
end
end
context 'when has additional fisco information' do
let(:xml_as_string) do
<<-EOS
Total de FCP-ST: 348,96
EOS
end
it 'renders title with box, subtitle, fisco box and additional information about fisco on the pdf' do
expect(File.exist?(output_pdf)).to be_falsey
pdf.render_file output_pdf
expect("#{base_dir}infadic#render-with_fisco_additional_information.pdf").to have_same_content_of file: output_pdf
end
end
context 'when has extra volume' do
let(:xml_as_string) do
<<-EOS
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
1
VOLUMES 1
DIVERSOS 1
1
1000.000
1100.000
2
VOLUMES 2
DIVERSOS 2
2
2000.000
2200.000
3
VOLUMES 3
DIVERSOS 3
3
3000.000
3300.000
0.00
0.00
0.00
EOS
end
let(:volumes_number) { 2 }
it 'renders title with box, subtitle, fisco box and extra volumes on the ' \
'pdf' do
expect(File.exist?(output_pdf)).to be_falsey
pdf.render_file output_pdf
expect("#{base_dir}infadic#render-extra_volume.pdf").to have_same_content_of file: output_pdf
end
end
context 'when has all the informations' do
let(:xml_as_string) do
<<-EOS
82743287000880
Schneider Electric Brasil Ltda
Av da Saudade
1125
Frutal
Em anexo ao super mercado maior do bairro
3552403
SUMARE
SP
13171320
1058
BRASIL
1921046300
671008375110
1
VOLUMES 1
DIVERSOS 1
1
1000.000
1100.000
2
VOLUMES 2
DIVERSOS 2
2
2000.000
2200.000
3
VOLUMES 3
DIVERSOS 3
3
3000.000
3300.000
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec congue in dolor sed sagittis.
Total de FCP-ST: 348,96
348.96
4892.78
2915.78
75394.78
EOS
end
let(:volumes_number) { 3 }
it 'renders title with box, subtitle, fisco box, extra volumes, ' \
'complementary information, address and difal on the pdf' do
expect(File.exist?(output_pdf)).to be_falsey
pdf.render_file output_pdf
expect("#{base_dir}infadic#render-all_the_informations.pdf").to have_same_content_of file: output_pdf
end
end
end
end