require 'spec_helper' describe BrDanfe::DanfeLib::NfeLib::Xprod do describe '#render' do context 'when has FCI' do let(:xml_fci) do xml = <<-eos MONITOR DE ARCO ELETRICO 12232531-74B2-4FDD-87A6-CF0AD3E55386 eos Nokogiri::XML(xml) end subject { BrDanfe::DanfeLib::NfeLib::Xprod.new(xml_fci) } it 'returns product + FCI' do expected = 'MONITOR DE ARCO ELETRICO' expected += "\n" expected += 'FCI: 12232531-74B2-4FDD-87A6-CF0AD3E55386' expect(subject.render).to eq expected end end context 'when has ST' do context 'when is Retido' do let(:vBCSTRet) { 0.00 } let(:pST) { 0.00 } let(:vICMSSTRet) { 0.00 } let(:xml) do xml = <<-eos MONITOR DE ARCO ELETRICO 0 60 #{pST} #{vBCSTRet} #{vICMSSTRet} 0.00 0.00 04 04 eos Nokogiri::XML(xml) end subject { BrDanfe::DanfeLib::NfeLib::Xprod.new(xml) } context 'when has vBCSTRet' do let(:vBCSTRet) { 50.00 } it 'returns product + ST Retido' do expected = 'MONITOR DE ARCO ELETRICO' expected += "\n" expected += 'ST Retido: Base: 50,00 * Alíq: 0,00% * Vlr: 0,00' expect(subject.render).to eq expected end end context 'when has vICMSSTRet' do let(:vICMSSTRet) { 50.00 } it 'returns product + ST Retido' do expected = 'MONITOR DE ARCO ELETRICO' expected += "\n" expected += 'ST Retido: Base: 0,00 * Alíq: 0,00% * Vlr: 50,00' expect(subject.render).to eq expected end end context 'when has pST' do let(:pST) { 50.00 } it 'returns product + ST Retido' do expected = 'MONITOR DE ARCO ELETRICO' expected += "\n" expected += 'ST Retido: Base: 0,00 * Alíq: 50,00% * Vlr: 0,00' expect(subject.render).to eq expected end end context "when doesn't have any fields" do it 'returns product' do expected = 'MONITOR DE ARCO ELETRICO' expect(subject.render).to eq expected end end end context "when isn't Retido" do let(:xml_st) do xml = <<-eos MONITOR DE ARCO ELETRICO 96.73 56.00 479.82 17.00 29.28 eos Nokogiri::XML(xml) end subject { BrDanfe::DanfeLib::NfeLib::Xprod.new(xml_st) } it 'returns product + ST' do expected = 'MONITOR DE ARCO ELETRICO' expected += "\n" expected += 'ST: MVA: 56,00% * Alíq: 17,00% * BC: 479,82 * Vlr: 29,28' expect(subject.render).to eq expected end end end context 'when has infAdProd' do let(:xml_infAdProd) do xml = <<-eos MONITOR DE ARCO ELETRICO Informações adicionais do produto eos Nokogiri::XML(xml) end subject { BrDanfe::DanfeLib::NfeLib::Xprod.new(xml_infAdProd) } it 'returns product + infAdProd' do expected = 'MONITOR DE ARCO ELETRICO' expected += "\n" expected += 'Informações adicionais do produto' expect(subject.render).to eq expected end end context 'when has FCP on ICMS00 tag' do let(:xml_fcp) do xml = <<-eos MONITOR DE ARCO ELETRICO 23.56 4.71 2.00 eos Nokogiri::XML(xml) end subject { BrDanfe::DanfeLib::NfeLib::Xprod.new(xml_fcp) } it 'returns product + FCP' do expected = 'MONITOR DE ARCO ELETRICO' expected += "\n" expected += 'FCP: Alíq: 2,00% * Vlr: 4,71' expect(subject.render).to eq expected end end context 'when has FCI + ST + infAdProd + FCP' do let(:xml_IFC_ST_infAdProd) do xml = <<-eos MONITOR DE ARCO ELETRICO 12232531-74B2-4FDD-87A6-CF0AD3E55386 96.73 56.00 479.82 17.00 29.28 4.71 2.00 Informações adicionais do produto eos Nokogiri::XML(xml) end subject { BrDanfe::DanfeLib::NfeLib::Xprod.new(xml_IFC_ST_infAdProd) } it 'returns product + FCI + ST + infAdProd' do expected = 'MONITOR DE ARCO ELETRICO' expected += "\n" expected += 'Informações adicionais do produto' expected += "\n" expected += 'FCI: 12232531-74B2-4FDD-87A6-CF0AD3E55386' expected += "\n" expected += 'ST: MVA: 56,00% * Alíq: 17,00% * BC: 479,82 * Vlr: 29,28' expected += "\n" expected += 'FCP: Alíq: 2,00% * Vlr: 4,71' expect(subject.render).to eq expected end end context 'when FCP is not in a ICMS00 tag' do let(:xml_fcp) do xml = <<-eos MONITOR DE ARCO ELETRICO 23.56 235.50 4.71 2.00 eos Nokogiri::XML(xml) end subject { BrDanfe::DanfeLib::NfeLib::Xprod.new(xml_fcp) } it 'returns product + FCP' do expected = 'MONITOR DE ARCO ELETRICO' expected += "\n" expected += 'FCP: Base: 235,50 * Alíq: 2,00% * Vlr: 4,71' expect(subject.render).to eq expected end end context 'when has FCP ST' do let(:xml_fcp) do xml = <<-eos MONITOR DE ARCO ELETRICO 23.56 235.50 0.71 2.00 eos Nokogiri::XML(xml) end subject { BrDanfe::DanfeLib::NfeLib::Xprod.new(xml_fcp) } it 'returns product + FCP' do expected = 'MONITOR DE ARCO ELETRICO' expected += "\n" expected += 'FCP ST: Base: 235,50 * Alíq: 2,00% * Vlr: 0,71' expect(subject.render).to eq expected end end end end