Skip to content

Commit

Permalink
fix(pdf): Fix credit note generating pdf and webhook
Browse files Browse the repository at this point in the history
  • Loading branch information
ivannovosad committed Oct 4, 2024
1 parent 8ddfc76 commit 756294f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
11 changes: 5 additions & 6 deletions app/services/credit_notes/generate_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ def initialize(credit_note:, context: nil)
end

def call
return result.not_found_failure!(resource: 'credit_note') if credit_note.blank?
return result.not_found_failure!(resource: 'credit_note') unless credit_note.finalized?
return result.not_found_failure!(resource: 'credit_note') if credit_note.blank? || !credit_note.finalized?

generate_pdf(credit_note) if credit_note.file.blank?
generate_pdf(credit_note) if should_generate_pdf?

SendWebhookJob.perform_later('credit_note.generated', credit_note) if should_send_webhook?
SendWebhookJob.perform_later('credit_note.generated', credit_note)

result.credit_note = credit_note
result
Expand All @@ -40,8 +39,8 @@ def generate_pdf(credit_note)
credit_note.save!
end

def should_send_webhook?
context == 'api'
def should_generate_pdf?
context == 'admin' || credit_note.file.blank?
end
end
end
10 changes: 10 additions & 0 deletions spec/services/credit_notes/generate_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,15 @@
end.to have_enqueued_job(SendWebhookJob)
end
end

context 'when context is admin' do
let(:context) { 'admin' }

it 'calls the SendWebhook job' do
expect do
credit_note_generate_service.call
end.to have_enqueued_job(SendWebhookJob)
end
end
end
end

0 comments on commit 756294f

Please sign in to comment.