require 'spec_helper'
describe BrDanfe::DanfeLib::NfeLib::Transp 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(:xml_as_string) do
<<~XML
0
71434064000149
Nome do Transportador Ltda
964508990089
Rua do Transportador, 456
Votorantim
SP
ABC-1234
SP
123456
XML
end
before do
subject.render
File.delete(output_pdf) if File.exist?(output_pdf)
end
it 'renders xml to the pdf' do
expect(File.exist?(output_pdf)).to be_falsey
pdf.render_file output_pdf
expect("#{base_dir}transp#render.pdf").to have_same_content_of file: output_pdf
end
context 'when modFrete is 0' do
let(:xml_as_string) do
<<~XML
0
XML
end
it "renders '0-Emitente' to the pdf" do
expect(File.exist?(output_pdf)).to be_falsey
pdf.render_file output_pdf
expect("#{base_dir}transp#render-modfrete_0.pdf").to have_same_content_of file: output_pdf
end
end
context 'when modFrete is 1' do
let(:xml_as_string) do
<<~XML
1
XML
end
it "renders '1-Destinatário' to the pdf" do
expect(File.exist?(output_pdf)).to be_falsey
pdf.render_file output_pdf
expect("#{base_dir}transp#render-modfrete_1.pdf").to have_same_content_of file: output_pdf
end
end
context 'when modFrete is 2' do
let(:xml_as_string) do
<<~XML
2
XML
end
it "renders '2-Terceiros' to the pdf" do
expect(File.exist?(output_pdf)).to be_falsey
pdf.render_file output_pdf
expect("#{base_dir}transp#render-modfrete_2.pdf").to have_same_content_of file: output_pdf
end
end
context 'when modFrete is 3' do
let(:xml_as_string) do
<<~XML
3
XML
end
it "renders '3-Prop/Rem' to the pdf" do
expect(File.exist?(output_pdf)).to be_falsey
pdf.render_file output_pdf
expect("#{base_dir}transp#render-modfrete_3.pdf").to have_same_content_of file: output_pdf
end
end
context 'when modFrete is 4' do
let(:xml_as_string) do
<<~XML
4
XML
end
it "renders '4-Prop/Dest' to the pdf" do
expect(File.exist?(output_pdf)).to be_falsey
pdf.render_file output_pdf
expect("#{base_dir}transp#render-modfrete_4.pdf").to have_same_content_of file: output_pdf
end
end
context 'when modFrete is 9' do
let(:xml_as_string) do
<<~XML
9
XML
end
it "renders '9-Sem Frete' to the pdf" do
expect(File.exist?(output_pdf)).to be_falsey
pdf.render_file output_pdf
expect("#{base_dir}transp#render-modfrete_9.pdf").to have_same_content_of file: output_pdf
end
end
describe 'with entrega' do
let(:xml_as_string) do
<<~XML
0
71434064000149
Nome do Transportador Ltda
964508990089
Rua do Transportador, 456
Votorantim
SP
ABC-1234
SP
123456
82743287000880
Schneider Electric Brasil Ltda
Av da Saudade
1125
Frutal
Sala 01 e 02
3552403
SUMARE
SP
13171320
1921046300
671008375110
XML
end
it 'renders xml to the pdf' do
expect(File.exist?(output_pdf)).to be_falsey
pdf.render_file output_pdf
expect("#{base_dir}transp#render-with_entrega.pdf").to have_same_content_of file: output_pdf
end
end
end
end