require "spec_helper"
describe BrDanfe::DanfeLib::DetBody do
let(:base_dir) { "./spec/fixtures/nfe/lib/" }
let(:output_pdf) { "#{base_dir}output.pdf" }
let(:pdf) { BrDanfe::DanfeLib::Document.new }
let(:xml) { BrDanfe::DanfeLib::XML.new(xml_as_string) }
let(:xml_as_string) do
<<-eos
#{products}
eos
end
let(:product_1) do
<<-eos
1
Product 1
45678901
5401
UN
6.4545
1.03
6.65
eos
end
let(:product_2) do
<<-eos
2
Product 2
45678901
5401
UN
6.4545
1.03
6.65
Additional information 1 - Additional information 2 - Additional information 3
eos
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
<<-eos
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
eos
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
<<-eos
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
eos
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
<<-eos
REF 06
Produto com FCI
90303329
00
5101
PC
1.00
49.23
49.23
12232531-74B2-4FDD-87A6-CF0AD3E55386
0
00
eos
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
<<-eos
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
eos
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
<<-eos
3
Produto Com Csosn 201 - ICMS ST
45678901
5401
UN
6.00
1.1312
6.79
eos
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
<<-eos
3
Produto Com Csosn 201 - ICMS ST
45678901
5401
UN
6.4545
1.03
6.65
eos
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}" }
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 "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