mirror of
https://github.com/internetee/registry.git
synced 2025-06-10 06:34:46 +02:00
Add test to check if job works
This commit is contained in:
parent
2663c550fa
commit
47e601f3cd
3 changed files with 49 additions and 8 deletions
|
@ -1,19 +1,17 @@
|
|||
class SendEInvoiceJob < Que::Job
|
||||
|
||||
def run(invoice)
|
||||
return if invoice.e_invoice_sent_at
|
||||
|
||||
e_invoice = invoice.to_e_invoice
|
||||
e_invoice.deliver
|
||||
invoice.to_e_invoice.deliver
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
invoice.update(e_invoice_sent_at: Time.zone.now)
|
||||
log_success(invoice)
|
||||
destroy
|
||||
end
|
||||
|
||||
rescue Savon::Error => e
|
||||
rescue StandardError => e
|
||||
log_error(invoice: invoice, error: e)
|
||||
raise e
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -35,5 +33,4 @@ class SendEInvoiceJob < Que::Job
|
|||
def logger
|
||||
Rails.logger
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -100,8 +100,7 @@ class Registrar < ApplicationRecord
|
|||
]
|
||||
)
|
||||
|
||||
e_invoice = invoice.to_e_invoice
|
||||
e_invoice.deliver
|
||||
SendEInvoiceJob.enqueue(invoice)
|
||||
|
||||
invoice
|
||||
end
|
||||
|
|
45
test/jobs/send_e_invoice_job_test.rb
Normal file
45
test/jobs/send_e_invoice_job_test.rb
Normal file
|
@ -0,0 +1,45 @@
|
|||
require 'test_helper'
|
||||
|
||||
class SendEInvoiceJobTest < ActiveSupport::TestCase
|
||||
|
||||
def teardown
|
||||
EInvoice.provider = EInvoice::Providers::TestProvider.new
|
||||
EInvoice::Providers::TestProvider.deliveries.clear
|
||||
end
|
||||
|
||||
def test_if_invoice_is_sended
|
||||
@invoice = invoices(:one)
|
||||
EInvoice.provider = EInvoice::Providers::TestProvider.new
|
||||
EInvoice::Providers::TestProvider.deliveries.clear
|
||||
|
||||
assert_nothing_raised do
|
||||
SendEInvoiceJob.enqueue(@invoice)
|
||||
end
|
||||
|
||||
assert_not @invoice.e_invoice_sent_at.blank?
|
||||
assert_equal 1, EInvoice::Providers::TestProvider.deliveries.count
|
||||
end
|
||||
|
||||
def test_if_invoice_sending_retries
|
||||
@invoice = invoices(:one)
|
||||
provider_config = { password: nil,
|
||||
test_mode: true }
|
||||
EInvoice.provider = EInvoice::Providers::OmnivaProvider.new(provider_config)
|
||||
stub_request(:get, "https://testfinance.post.ee/finance/erp/erpServices.wsdl").to_timeout
|
||||
|
||||
assert_raise HTTPClient::TimeoutError do
|
||||
SendEInvoiceJob.enqueue(@invoice)
|
||||
end
|
||||
assert @invoicee_invoice_sent_at.blank?
|
||||
|
||||
EInvoice.provider = EInvoice::Providers::TestProvider.new
|
||||
EInvoice::Providers::TestProvider.deliveries.clear
|
||||
|
||||
assert_nothing_raised do
|
||||
SendEInvoiceJob.enqueue(@invoice)
|
||||
end
|
||||
|
||||
assert_not @invoice.e_invoice_sent_at.blank?
|
||||
assert_equal 1, EInvoice::Providers::TestProvider.deliveries.count
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue