Skip to content

Commit

Permalink
fix specs
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagovsk committed Sep 27, 2017
1 parent 579f515 commit 623c711
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions lib/br_invoices_pdf/cfe/parser.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'br_invoices_pdf/cfe/parser/access_key'
require 'br_invoices_pdf/cfe/parser/company_attributes'
require 'br_invoices_pdf/cfe/parser/cpf'
require 'br_invoices_pdf/cfe/parser/cnpj'
require 'br_invoices_pdf/cfe/parser/document_number'
require 'br_invoices_pdf/cfe/parser/fisco_obs'
require 'br_invoices_pdf/cfe/parser/payment'
Expand Down
10 changes: 5 additions & 5 deletions lib/br_invoices_pdf/cfe/renderer/header.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ def execute(pdf, data)
end

def identificator(data)
return 'CONSUMIDOR NAO IDENTIFICADO' unless data[:cpf] && data[:cnpj]
value = data[:cpf].nil? ? format_cpf(data[:cpf]) : format_cnpj(data[:cnpj])
return 'CONSUMIDOR NAO IDENTIFICADO' if data[:cpf].nil? && data[:cnpj].nil?
value = data[:cpf].nil? ? format_cnpj(data[:cnpj]) : format_cpf(data[:cpf])
'CONSUMIDOR: ' + value
end
private_class_method :cpf_vlue
private_class_method :identificator

def add_header_config(pdf, data, cpf)
def add_header_config(pdf, data, identificator)
pdf.font('Helvetica', style: :bold)
pdf.text("Extrato: #{data[:document_number]}", align: :center)
pdf.text(cpf, align: :center)
pdf.text(identificator, align: :center)
pdf.text('CUPOM FISCAL ELETRONICO - SAT', align: :center)
pdf.font('Helvetica', style: :normal, align: :center)
end
Expand Down
5 changes: 4 additions & 1 deletion spec/lib/br_invoices_pdf/cfe/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module Cfe
let(:fisco_obs_response) { double('fisco_obs') }
let(:access_key_response) { double }
let(:cpf_response) { '99999999999' }
let(:cnpj_response) { '13054202000168' }
let(:expectation) do
{
sat_params: sat_response,
Expand All @@ -24,7 +25,8 @@ module Cfe
company_attributes: company_attributes_response,
fisco_obs: fisco_obs_response,
access_key: access_key_response,
cpf: cpf_response
cpf: cpf_response,
cnpj: cnpj_response
}
end
it do
Expand All @@ -37,6 +39,7 @@ module Cfe
expect(Parser::FiscoObs).to receive(:execute).with(xml).and_return(fisco_obs_response)
expect(Parser::AccessKey).to receive(:execute).with(xml).and_return(access_key_response)
expect(Parser::Cpf).to receive(:execute).with(xml).and_return(cpf_response)
expect(Parser::Cnpj).to receive(:execute).with(xml).and_return(cnpj_response)
expect(subject).to eq(expectation)
end
end
Expand Down
10 changes: 10 additions & 0 deletions spec/lib/br_invoices_pdf/cfe/renderer/header_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@
end
end

context 'when cpf is present' do
let(:data) { { cpf: nil, cnpj: '48013766000137', document_number: document_number } }
let(:formated_cnpj) { '48.013.766/0001-37' }

it do
expect(pdf).to receive(:text).with('CONSUMIDOR: ' + formated_cnpj, align: :center)
subject
end
end

context 'when cpf not is present' do
let(:data) { { document_number: '999' } }

Expand Down

0 comments on commit 623c711

Please sign in to comment.