Skip to content

Commit

Permalink
add test; fix styles
Browse files Browse the repository at this point in the history
  • Loading branch information
annvelents committed Jan 28, 2025
1 parent 0f2d91d commit eb62c3b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
3 changes: 1 addition & 2 deletions app/services/credit_notes/generate_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ def call
def generate_pdf(credit_note)
I18n.locale = credit_note.customer.preferred_document_locale

pdf_service = Utils::PdfGenerator.new(template: , context: credit_note)
pdf_result = pdf_service.call
pdf_result = Utils::PdfGenerator.call(template: , context: credit_note)

credit_note.file.attach(
io: pdf_result.io,
Expand Down
2 changes: 1 addition & 1 deletion app/views/templates/credit_notes/credit_note.slim
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ html
meta name='viewport' content='width=device-width, initial-scale=1.0'
title Credit note
body
= SlimHelper.render('templates/credit_notes/_styles', self)
== SlimHelper.render('templates/credit_notes/_styles', self)

.wrapper
.mb-24
Expand Down
2 changes: 1 addition & 1 deletion app/views/templates/credit_notes/self_billed.slim
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ html
meta name='viewport' content='width=device-width, initial-scale=1.0'
title Self billing credit note
body
= SlimHelper.render('templates/credit_notes/_styles', self)
== SlimHelper.render('templates/credit_notes/_styles', self)

.wrapper
.mb-24
Expand Down
22 changes: 18 additions & 4 deletions spec/services/credit_notes/generate_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
let(:credit_note) { create(:credit_note, invoice:, customer:) }
let(:fee) { create(:fee, invoice:) }
let(:credit_note_item) { create(:credit_note_item, credit_note:, fee:) }
let(:pdf_generator) { instance_double(Utils::PdfGenerator) }
let(:context) { nil }

let(:pdf_content) do
Expand All @@ -25,9 +24,7 @@
before do
credit_note_item

allow(Utils::PdfGenerator).to receive(:new)
.and_return(pdf_generator)
allow(pdf_generator).to receive(:call)
allow(Utils::PdfGenerator).to receive(:call)
.and_return(pdf_response)
end

Expand All @@ -38,6 +35,23 @@
expect(result.credit_note.file).to be_present
end

it 'uses credit_note template' do
credit_note_generate_service.call

expect(Utils::PdfGenerator).to have_received(:call).with(template: 'credit_notes/credit_note', context: credit_note)
end

context "when credit note is for self billed invoice" do
let(:invoice) { create(:invoice, :self_billed, customer:, organization:) }
let(:credit_note) { create(:credit_note, invoice:, customer:) }

it 'uses self billed template' do
credit_note_generate_service.call

expect(Utils::PdfGenerator).to have_received(:call).with(template: 'credit_notes/self_billed', context: credit_note)
end
end

context 'with preferred locale' do
before { customer.update!(document_locale: 'fr') }

Expand Down

0 comments on commit eb62c3b

Please sign in to comment.