require 'spec_helper' describe BrDanfe::DanfeLib::NfeLib::DetBody 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) } let(:xml_as_string) do <<~XML #{products} XML end let(:product_1) do <<~XML 1 Product 1 45678901 5401 UN 6.4545 1.03 6.65 XML end let(:product_2) do <<~XML 2 Product 2 45678901 5401 UN 6.4545 1.03 6.65 Additional information 1 - Additional information 2 - Additional information 3 XML end let(:has_issqn) { false } subject { described_class.new(pdf, xml) } describe '#render' do before do subject.render has_issqn File.delete(output_pdf) if File.exist?(output_pdf) end context 'with CSOSN' do let(:products) do <<~XML 1 Produto com CSOSN 101 - Nacional 12345678 5101 UN 2.00 1.01 2.02 0 101 2 Produto com CSOSN 102 - Estrangeiro 23456789 5101 UN 4.00 1.02 4.08 1 102 3 Produto Com Csosn 201 45678901 5401 UN 6.00 1.03 6.18 0 201 24.00 7.66 17.00 0.25 8 Produto com CSOSN 900 - Com ICMS 34567890 5201 UN 16.00 1.08 17.28 0 900 9.87 8.76 7.65 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}det_body#render-csosn.pdf").to have_same_content_of file: output_pdf end end context 'with CST' do let(:products) do <<~XML REF 04 Produto com CST 00 - Nacional - ICMS - IPI 90303329 00 5101 PC 1.00 49.23 49.23 98001921 10 0 00 3 49.23 12.00 5.90 999 50 49.23 5.00 2.46 REF 05 Produto com CST 00 - Estrangeiro - ICMS - IPI 90303329 00 5101 PC 1.00 49.23 49.23 98001921 10 1 00 3 49.23 12.00 5.90 999 50 49.23 5.00 2.46 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}det_body#render-cst.pdf").to have_same_content_of file: output_pdf end end context 'with FCI' do let(:products) do <<~XML REF 06 Produto com FCI 90303329 00 5101 PC 1.00 49.23 49.23 12232531-74B2-4FDD-87A6-CF0AD3E55386 0 00 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}det_body#render-fci.pdf").to have_same_content_of file: output_pdf end end context 'with ICMS ST' do let(:products) do <<~XML 3 Produto Com Csosn 201 - ICMS ST 45678901 5401 UN 6.00 1.03 6.18 0 201 24.00 7.66 17.00 0.25 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}det_body#render-icms_st.pdf").to have_same_content_of file: output_pdf end end context 'when the unit price of the product has a custom precision' do let(:products) do <<~XML 3 Produto Com Csosn 201 - ICMS ST 45678901 5401 UN 6.00 1.1312 6.79 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}det_body#render-unit_price_with_custom_precision.pdf").to have_same_content_of file: output_pdf end end context 'when the quantity of the product has a custom precision' do let(:products) do <<~XML 3 Produto Com Csosn 201 - ICMS ST 45678901 5401 UN 6.4545 1.03 6.65 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}det_body#render-quantity_with_custom_precision.pdf").to have_same_content_of file: output_pdf end end context 'when there is ISSQN' do let(:has_issqn) { true } let(:products) { "#{product_1}\n#{product_2}" * 10 } it 'renders xml to the pdf' do expect(File.exist?(output_pdf)).to be_falsey pdf.render_file output_pdf expect("#{base_dir}det_body#render-with_issqn.pdf").to have_same_content_of file: output_pdf end end context "when there isn't ISSQN" do let(:products) { "#{product_1}\n#{product_2}" * 10 } it 'renders xml to the pdf' do expect(File.exist?(output_pdf)).to be_falsey pdf.render_file output_pdf expect("#{base_dir}det_body#render-without_issqn.pdf").to have_same_content_of file: output_pdf end end context 'with infAdProd' do let(:products) { product_2.to_s } it 'renders xml to the pdf' do expect(File.exist?(output_pdf)).to be_falsey pdf.render_file output_pdf expect("#{base_dir}det_body#render-with_infadprod.pdf").to have_same_content_of file: output_pdf end end context 'with entrega' do let(:products) do <<~XML REF 06 Produto com FCI 90303329 00 5101 PC 1.00 49.23 49.23 0 00 3 49.23 12.00 5.90 999 50 49.23 5.00 2.46 XML end let(:xml_as_string) do <<~XML #{products} 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}det_body#render-with_entrega.pdf").to have_same_content_of file: output_pdf end end context 'when the product table occupies more than one page' do context 'when the product table occupies two pages' do let(:products) { ("#{product_1}\n#{product_2}" * 22) + "\n#{product_1}" } it 'renders xml to the pdf' do expect(File.exist?(output_pdf)).to be_falsey pdf.render_file output_pdf expect("#{base_dir}det_body#render-two_pages.pdf").to have_same_content_of file: output_pdf end end context 'when the product table occupies three pages' do let(:products) { ("#{product_1}\n#{product_2}" * 23) } it 'renders xml to the pdf' do expect(File.exist?(output_pdf)).to be_falsey pdf.render_file output_pdf expect("#{base_dir}det_body#render-three_pages.pdf").to have_same_content_of file: output_pdf end end end end end