diff --git a/app/jobs/send_e_invoice_job.rb b/app/jobs/send_e_invoice_job.rb index 6b5fd4bba..4ef503d59 100644 --- a/app/jobs/send_e_invoice_job.rb +++ b/app/jobs/send_e_invoice_job.rb @@ -2,6 +2,7 @@ class SendEInvoiceJob < ApplicationJob discard_on HTTPClient::TimeoutError def perform(invoice_id, payable = true) + logger.info "Started to process e-invoice for invoice_id #{invoice_id}" invoice = Invoice.find_by(id: invoice_id) return unless need_to_process_invoice?(invoice: invoice, payable: payable) @@ -14,6 +15,7 @@ class SendEInvoiceJob < ApplicationJob private def need_to_process_invoice?(invoice:, payable:) + logger.info "Checking if need to process e-invoice #{invoice}, payable: #{payable}" return false if invoice.blank? return false if invoice.do_not_send_e_invoice? && payable diff --git a/app/models/registrar.rb b/app/models/registrar.rb index 2f5cca0ad..62c824f4f 100644 --- a/app/models/registrar.rb +++ b/app/models/registrar.rb @@ -105,7 +105,7 @@ class Registrar < ApplicationRecord .deliver_later(wait: 1.minute) end - SendEInvoiceJob.perform_now(invoice.id, payable) + SendEInvoiceJob.set(wait: 1.minute).perform_now(invoice.id, payable) invoice end diff --git a/test/tasks/registrars/reload_balance_test.rb b/test/tasks/registrars/reload_balance_test.rb index d9e77a22f..0c14f95c9 100644 --- a/test/tasks/registrars/reload_balance_test.rb +++ b/test/tasks/registrars/reload_balance_test.rb @@ -19,6 +19,18 @@ class ReloadBalanceTaskTest < ActiveSupport::TestCase assert_equal reload_amount, invoice.subtotal end + def test_issues_invoice_when_auto_reload_is_enabled_and_threshold_reached + reload_amount = 100 + registrar = registrar_with_auto_reload_enabled_and_threshold_reached(reload_amount) + + assert_difference -> { registrar.invoices.count } do + capture_io { run_task } + end + + invoice = registrar.invoices.last + assert_equal Time.zone.today, invoice.e_invoice_sent_at.to_date + end + def test_skips_issuing_invoice_when_threshold_is_not_reached registrar = registrar_with_auto_reload_enabled_and_threshold_not_reached @@ -75,4 +87,4 @@ class ReloadBalanceTaskTest < ActiveSupport::TestCase def run_task Rake::Task['registrars:reload_balance'].execute end -end \ No newline at end of file +end