mirror of
https://github.com/internetee/registry.git
synced 2025-07-31 06:56:23 +02:00
Merge pull request #2456 from internetee/modify-monthly-invoice-generation
Refactored monthly invoice generation job
This commit is contained in:
commit
8244066d5d
21 changed files with 383 additions and 505 deletions
|
@ -9,7 +9,7 @@ class CsyncJobTest < ActiveSupport::TestCase
|
|||
dirname = File.dirname(ENV['cdns_scanner_input_file'])
|
||||
|
||||
FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
|
||||
FileUtils.touch(ENV['cdns_scanner_input_file']) unless File.exists?(ENV['cdns_scanner_input_file'])
|
||||
FileUtils.touch(ENV['cdns_scanner_input_file']) unless File.exist?(ENV['cdns_scanner_input_file'])
|
||||
end
|
||||
|
||||
def test_generates_input_file_for_cdnskey_scanner
|
||||
|
|
|
@ -107,28 +107,28 @@ class DirectoInvoiceForwardLegacyJobTest < ActiveSupport::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_multi_year_purchases_have_duration_assigned
|
||||
activity = account_activities(:one)
|
||||
price = billing_prices(:create_one_year)
|
||||
price.update(duration: 3.years)
|
||||
activity.update(activity_type: 'create', price: price)
|
||||
# def test_multi_year_purchases_have_duration_assigned
|
||||
# activity = account_activities(:one)
|
||||
# price = billing_prices(:create_one_year)
|
||||
# price.update(duration: 3.years)
|
||||
# activity.update(activity_type: 'create', price: price)
|
||||
|
||||
response = <<-XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<results>
|
||||
<Result Type="0" Desc="OK" docid="309902" doctype="ARVE" submit="Invoices"/>
|
||||
</results>
|
||||
XML
|
||||
# response = <<-XML
|
||||
# <?xml version="1.0" encoding="UTF-8"?>
|
||||
# <results>
|
||||
# <Result Type="0" Desc="OK" docid="309902" doctype="ARVE" submit="Invoices"/>
|
||||
# </results>
|
||||
# XML
|
||||
|
||||
stub_request(:post, ENV['directo_invoice_url']).with do |request|
|
||||
body = CGI.unescape(request.body)
|
||||
(body.include? 'StartDate') && (body.include? 'EndDate')
|
||||
end.to_return(status: 200, body: response)
|
||||
# stub_request(:post, ENV['directo_invoice_url']).with do |request|
|
||||
# body = CGI.unescape(request.body)
|
||||
# (body.include? 'StartDate') && (body.include? 'EndDate')
|
||||
# end.to_return(status: 200, body: response)
|
||||
|
||||
assert_difference 'Setting.directo_monthly_number_last' do
|
||||
DirectoInvoiceForwardLegacyJob.perform_now(monthly: true, dry: false)
|
||||
end
|
||||
end
|
||||
# assert_difference 'Setting.directo_monthly_number_last' do
|
||||
# DirectoInvoiceForwardLegacyJob.perform_now(monthly: true, dry: false)
|
||||
# end
|
||||
# end
|
||||
|
||||
def test_monthly_duration_products_are_present_in_summary
|
||||
activity = account_activities(:one)
|
||||
|
@ -152,43 +152,43 @@ class DirectoInvoiceForwardLegacyJobTest < ActiveSupport::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_sends_each_monthly_invoice_separately
|
||||
WebMock.reset!
|
||||
# def test_sends_each_monthly_invoice_separately
|
||||
# WebMock.reset!
|
||||
|
||||
activity = account_activities(:one)
|
||||
price = billing_prices(:create_one_year)
|
||||
price.update(duration: 3.years)
|
||||
activity.update(activity_type: 'create', price: price)
|
||||
# activity = account_activities(:one)
|
||||
# price = billing_prices(:create_one_year)
|
||||
# price.update(duration: 3.years)
|
||||
# activity.update(activity_type: 'create', price: price)
|
||||
|
||||
# Creating account activity for second action
|
||||
another_activity = activity.dup
|
||||
another_activity.account = accounts(:two)
|
||||
# # Creating account activity for second action
|
||||
# another_activity = activity.dup
|
||||
# another_activity.account = accounts(:two)
|
||||
|
||||
AccountActivity.skip_callback(:create, :after, :update_balance)
|
||||
another_activity.created_at = Time.zone.parse('2010-07-05 10:00')
|
||||
another_activity.save
|
||||
AccountActivity.set_callback(:create, :after, :update_balance)
|
||||
# AccountActivity.skip_callback(:create, :after, :update_balance)
|
||||
# another_activity.created_at = Time.zone.parse('2010-07-05 10:00')
|
||||
# another_activity.save
|
||||
# AccountActivity.set_callback(:create, :after, :update_balance)
|
||||
|
||||
response = <<-XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<results>
|
||||
<Result Type="0" Desc="OK" docid="309902" doctype="ARVE" submit="Invoices"/>
|
||||
</results>
|
||||
XML
|
||||
# response = <<-XML
|
||||
# <?xml version="1.0" encoding="UTF-8"?>
|
||||
# <results>
|
||||
# <Result Type="0" Desc="OK" docid="309902" doctype="ARVE" submit="Invoices"/>
|
||||
# </results>
|
||||
# XML
|
||||
|
||||
first_registrar_stub = stub_request(:post, ENV['directo_invoice_url']).with do |request|
|
||||
body = CGI.unescape(request.body)
|
||||
(body.include? 'StartDate') && (body.include? 'EndDate') && (body.include? 'bestnames')
|
||||
end.to_return(status: 200, body: response)
|
||||
# first_registrar_stub = stub_request(:post, ENV['directo_invoice_url']).with do |request|
|
||||
# body = CGI.unescape(request.body)
|
||||
# (body.include? 'StartDate') && (body.include? 'EndDate') && (body.include? 'bestnames')
|
||||
# end.to_return(status: 200, body: response)
|
||||
|
||||
second_registrar_stub = stub_request(:post, ENV['directo_invoice_url']).with do |request|
|
||||
body = CGI.unescape(request.body)
|
||||
(body.include? 'StartDate') && (body.include? 'EndDate') && (body.include? 'goodnames')
|
||||
end.to_return(status: 200, body: response)
|
||||
# second_registrar_stub = stub_request(:post, ENV['directo_invoice_url']).with do |request|
|
||||
# body = CGI.unescape(request.body)
|
||||
# (body.include? 'StartDate') && (body.include? 'EndDate') && (body.include? 'goodnames')
|
||||
# end.to_return(status: 200, body: response)
|
||||
|
||||
DirectoInvoiceForwardLegacyJob.perform_now(monthly: true, dry: false)
|
||||
# DirectoInvoiceForwardLegacyJob.perform_now(monthly: true, dry: false)
|
||||
|
||||
assert_requested first_registrar_stub
|
||||
assert_requested second_registrar_stub
|
||||
end
|
||||
# assert_requested first_registrar_stub
|
||||
# assert_requested second_registrar_stub
|
||||
# end
|
||||
end
|
||||
|
|
|
@ -8,20 +8,11 @@ class SendMonthlyInvoicesJobTest < ActiveSupport::TestCase
|
|||
@date = Time.zone.parse('2010-08-06')
|
||||
travel_to @date
|
||||
ActionMailer::Base.deliveries.clear
|
||||
EInvoice.provider = EInvoice::Providers::TestProvider.new
|
||||
EInvoice::Providers::TestProvider.deliveries.clear
|
||||
|
||||
response = { message: 'sucess' }
|
||||
stub_request(:post, "https://eis_billing_system:3000/api/v1/e_invoice/e_invoice")
|
||||
.to_return(status: 200, body: response.to_json, headers: {})
|
||||
end
|
||||
|
||||
def teardown
|
||||
Setting.directo_monthly_number_min = 309_901
|
||||
Setting.directo_monthly_number_max = 309_999
|
||||
Setting.directo_monthly_number_last = 309_901
|
||||
EInvoice.provider = EInvoice::Providers::TestProvider.new
|
||||
EInvoice::Providers::TestProvider.deliveries.clear
|
||||
@response = { 'message' => 'Invoice data received' }.to_json
|
||||
@monthly_invoice_numbers_generator_url = 'https://eis_billing_system:3000/api/v1/invoice_generator/monthly_invoice_numbers_generator'
|
||||
@directo_url = 'https://eis_billing_system:3000/api/v1/directo/directo'
|
||||
@e_invoice_url = 'https://eis_billing_system:3000/api/v1/e_invoice/e_invoice'
|
||||
end
|
||||
|
||||
def test_fails_if_directo_bounds_exceedable
|
||||
|
@ -29,17 +20,13 @@ class SendMonthlyInvoicesJobTest < ActiveSupport::TestCase
|
|||
price = billing_prices(:create_one_year)
|
||||
activity.update!(activity_type: 'create', price: price)
|
||||
|
||||
Setting.directo_monthly_number_max = 30_991
|
||||
stub_request(:post, @monthly_invoice_numbers_generator_url)
|
||||
.to_return(status: :not_implemented, body: { error: 'out of range' }.to_json, headers: {})
|
||||
|
||||
assert_no_difference 'Directo.count' do
|
||||
assert_raises 'RuntimeError' do
|
||||
SendMonthlyInvoicesJob.perform_now
|
||||
end
|
||||
end
|
||||
SendMonthlyInvoicesJob.perform_now
|
||||
|
||||
assert_nil Invoice.find_by_monthly_invoice(true)
|
||||
assert_emails 0
|
||||
assert_equal 0, EInvoice::Providers::TestProvider.deliveries.count
|
||||
end
|
||||
|
||||
def test_monthly_summary_is_not_delivered_if_dry
|
||||
|
@ -48,19 +35,18 @@ class SendMonthlyInvoicesJobTest < ActiveSupport::TestCase
|
|||
activity.update!(activity_type: 'create', price: price)
|
||||
@user.update(language: 'et')
|
||||
|
||||
assert_difference 'Setting.directo_monthly_number_last' do
|
||||
assert_no_difference 'Directo.count' do
|
||||
SendMonthlyInvoicesJob.perform_now(dry: true)
|
||||
end
|
||||
end
|
||||
stub_request(:post, @monthly_invoice_numbers_generator_url)
|
||||
.to_return(status: :ok, body: { invoice_numbers: [309_902] }.to_json, headers: {})
|
||||
|
||||
invoice = Invoice.last
|
||||
SendMonthlyInvoicesJob.perform_now(dry: true)
|
||||
|
||||
invoice = Invoice.find_by_monthly_invoice(true)
|
||||
assert_equal 309_902, invoice.number
|
||||
refute invoice.sent_at
|
||||
refute invoice.in_directo
|
||||
assert invoice.e_invoice_sent_at.blank?
|
||||
|
||||
assert_emails 0
|
||||
assert_equal 0, EInvoice::Providers::TestProvider.deliveries.count
|
||||
end
|
||||
|
||||
def test_monthly_summary_is_delivered_if_invoice_already_exists
|
||||
|
@ -70,6 +56,7 @@ class SendMonthlyInvoicesJobTest < ActiveSupport::TestCase
|
|||
due_date: @date.last_month.end_of_month,
|
||||
metadata: metadata,
|
||||
in_directo: false,
|
||||
sent_at: nil,
|
||||
e_invoice_sent_at: nil)
|
||||
|
||||
activity = account_activities(:one)
|
||||
|
@ -77,41 +64,23 @@ class SendMonthlyInvoicesJobTest < ActiveSupport::TestCase
|
|||
activity.update!(activity_type: 'create', price: price)
|
||||
@user.update(language: 'et')
|
||||
|
||||
response = <<-XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<results>
|
||||
<Result Type="0" Desc="OK" docid="309902" doctype="ARVE" submit="Invoices"/>
|
||||
</results>
|
||||
XML
|
||||
|
||||
stub_request(:post, ENV['directo_invoice_url']).with do |request|
|
||||
stub_request(:post, @directo_url).with do |request|
|
||||
body = CGI.unescape(request.body)
|
||||
|
||||
(body.include? '.test registreerimine: 1 aasta(t)') &&
|
||||
(body.include? 'Domeenide ettemaks') &&
|
||||
(body.include? '309902')
|
||||
end.to_return(status: 200, body: response)
|
||||
end.to_return(status: 200, body: @response)
|
||||
|
||||
assert_no_difference 'Setting.directo_monthly_number_last' do
|
||||
assert_difference('Directo.count', 1) do
|
||||
assert_enqueued_jobs 1, only: SendEInvoiceJob do
|
||||
assert_no_difference('Invoice.count') do
|
||||
SendMonthlyInvoicesJob.perform_now
|
||||
end
|
||||
end
|
||||
@monthly_invoice.reload
|
||||
|
||||
perform_enqueued_jobs
|
||||
|
||||
invoice = Invoice.last
|
||||
assert_equal 309_902, invoice.number
|
||||
assert invoice.in_directo
|
||||
assert_not invoice.e_invoice_sent_at.blank?
|
||||
|
||||
assert_not_nil @monthly_invoice.sent_at
|
||||
assert_emails 1
|
||||
email = ActionMailer::Base.deliveries.last
|
||||
assert_equal ['billing@bestnames.test'], email.to
|
||||
assert_equal 'Invoice no. 309902 (monthly invoice)', email.subject
|
||||
assert email.attachments['invoice-309902.pdf']
|
||||
|
||||
# assert_equal 1, EInvoice::Providers::TestProvider.deliveries.count
|
||||
end
|
||||
|
||||
def test_monthly_summary_is_delivered_in_estonian
|
||||
|
@ -120,23 +89,22 @@ class SendMonthlyInvoicesJobTest < ActiveSupport::TestCase
|
|||
activity.update!(activity_type: 'create', price: price)
|
||||
@user.update(language: 'et')
|
||||
|
||||
response = <<-XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<results>
|
||||
<Result Type="0" Desc="OK" docid="309902" doctype="ARVE" submit="Invoices"/>
|
||||
</results>
|
||||
XML
|
||||
|
||||
stub_request(:post, ENV['directo_invoice_url']).with do |request|
|
||||
stub_request(:post, @directo_url).with do |request|
|
||||
body = CGI.unescape(request.body)
|
||||
|
||||
(body.include? '.test registreerimine: 3 kuu(d)') &&
|
||||
(body.include? 'Domeenide ettemaks') &&
|
||||
(body.include? '309902')
|
||||
end.to_return(status: 200, body: response)
|
||||
end.to_return(status: 200, body: @response)
|
||||
|
||||
assert_difference 'Setting.directo_monthly_number_last' do
|
||||
assert_difference('Directo.count', 1) do
|
||||
stub_request(:post, @monthly_invoice_numbers_generator_url)
|
||||
.to_return(status: :ok, body: { invoice_numbers: [309_902] }.to_json, headers: {})
|
||||
|
||||
stub_request(:post, @e_invoice_url)
|
||||
.to_return(status: 200, body: @response, headers: {})
|
||||
|
||||
assert_enqueued_jobs 1, only: SendEInvoiceJob do
|
||||
assert_difference('Invoice.count', 1) do
|
||||
SendMonthlyInvoicesJob.perform_now
|
||||
end
|
||||
end
|
||||
|
@ -145,16 +113,12 @@ class SendMonthlyInvoicesJobTest < ActiveSupport::TestCase
|
|||
|
||||
invoice = Invoice.last
|
||||
assert_equal 309_902, invoice.number
|
||||
assert invoice.in_directo
|
||||
assert_not invoice.e_invoice_sent_at.blank?
|
||||
|
||||
assert_emails 1
|
||||
email = ActionMailer::Base.deliveries.last
|
||||
assert_equal ['billing@bestnames.test'], email.to
|
||||
assert_equal 'Invoice no. 309902 (monthly invoice)', email.subject
|
||||
assert email.attachments['invoice-309902.pdf']
|
||||
|
||||
# assert_equal 1, EInvoice::Providers::TestProvider.deliveries.count
|
||||
end
|
||||
|
||||
def test_multi_year_purchases_have_duration_assigned
|
||||
|
@ -163,28 +127,27 @@ class SendMonthlyInvoicesJobTest < ActiveSupport::TestCase
|
|||
price.update(duration: 3.years)
|
||||
activity.update(activity_type: 'create', price: price)
|
||||
|
||||
response = <<-XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<results>
|
||||
<Result Type="0" Desc="OK" docid="309902" doctype="ARVE" submit="Invoices"/>
|
||||
</results>
|
||||
XML
|
||||
|
||||
stub_request(:post, ENV['directo_invoice_url']).with do |request|
|
||||
stub_request(:post, @directo_url).with do |request|
|
||||
body = CGI.unescape(request.body)
|
||||
(body.include? 'StartDate') && (body.include? 'EndDate')
|
||||
end.to_return(status: 200, body: response)
|
||||
(body.include? 'start_date') && (body.include? 'end_date')
|
||||
end.to_return(status: 200, body: @response)
|
||||
|
||||
assert_difference 'Setting.directo_monthly_number_last' do
|
||||
SendMonthlyInvoicesJob.perform_now
|
||||
stub_request(:post, @monthly_invoice_numbers_generator_url)
|
||||
.to_return(status: :ok, body: { invoice_numbers: [309_902] }.to_json, headers: {})
|
||||
|
||||
stub_request(:post, @e_invoice_url)
|
||||
.to_return(status: 200, body: @response, headers: {})
|
||||
|
||||
assert_enqueued_jobs 1, only: SendEInvoiceJob do
|
||||
assert_difference('Invoice.count', 1) do
|
||||
SendMonthlyInvoicesJob.perform_now
|
||||
end
|
||||
end
|
||||
|
||||
perform_enqueued_jobs
|
||||
|
||||
invoice = Invoice.last
|
||||
assert_equal 309_902, invoice.number
|
||||
assert invoice.in_directo
|
||||
assert_not invoice.e_invoice_sent_at.blank?
|
||||
end
|
||||
|
||||
def test_monthly_duration_products_are_present_in_summary
|
||||
|
@ -192,28 +155,27 @@ class SendMonthlyInvoicesJobTest < ActiveSupport::TestCase
|
|||
price = billing_prices(:create_one_month)
|
||||
activity.update(activity_type: 'create', price: price)
|
||||
|
||||
response = <<-XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<results>
|
||||
<Result Type="0" Desc="OK" docid="309902" doctype="ARVE" submit="Invoices"/>
|
||||
</results>
|
||||
XML
|
||||
|
||||
stub_request(:post, ENV['directo_invoice_url']).with do |request|
|
||||
stub_request(:post, @directo_url).with do |request|
|
||||
body = CGI.unescape(request.body)
|
||||
body.include? 'month(s)'
|
||||
end.to_return(status: 200, body: response)
|
||||
end.to_return(status: 200, body: @response)
|
||||
|
||||
assert_difference 'Setting.directo_monthly_number_last' do
|
||||
SendMonthlyInvoicesJob.perform_now
|
||||
stub_request(:post, @monthly_invoice_numbers_generator_url)
|
||||
.to_return(status: :ok, body: { invoice_numbers: [309_902] }.to_json, headers: {})
|
||||
|
||||
stub_request(:post, @e_invoice_url)
|
||||
.to_return(status: 200, body: @response, headers: {})
|
||||
|
||||
assert_enqueued_jobs 1, only: SendEInvoiceJob do
|
||||
assert_difference('Invoice.count', 1) do
|
||||
SendMonthlyInvoicesJob.perform_now
|
||||
end
|
||||
end
|
||||
|
||||
perform_enqueued_jobs
|
||||
|
||||
invoice = Invoice.last
|
||||
assert_equal 309_902, invoice.number
|
||||
assert invoice.in_directo
|
||||
assert_not invoice.e_invoice_sent_at.blank?
|
||||
end
|
||||
|
||||
def test_sends_each_monthly_invoice_separately
|
||||
|
@ -233,25 +195,31 @@ class SendMonthlyInvoicesJobTest < ActiveSupport::TestCase
|
|||
another_activity.save
|
||||
AccountActivity.set_callback(:create, :after, :update_balance)
|
||||
|
||||
response = <<-XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<results>
|
||||
<Result Type="0" Desc="OK" docid="309902" doctype="ARVE" submit="Invoices"/>
|
||||
</results>
|
||||
XML
|
||||
|
||||
first_registrar_stub = stub_request(:post, ENV['directo_invoice_url']).with do |request|
|
||||
first_registrar_stub = stub_request(:post, @directo_url).with do |request|
|
||||
body = CGI.unescape(request.body)
|
||||
(body.include? 'StartDate') && (body.include? 'EndDate') && (body.include? 'bestnames')
|
||||
end.to_return(status: 200, body: response)
|
||||
(body.include? 'start_date') && (body.include? 'end_date') && (body.include? 'bestnames')
|
||||
end.to_return(status: 200, body: @response)
|
||||
|
||||
second_registrar_stub = stub_request(:post, ENV['directo_invoice_url']).with do |request|
|
||||
second_registrar_stub = stub_request(:post, @directo_url).with do |request|
|
||||
body = CGI.unescape(request.body)
|
||||
(body.include? 'StartDate') && (body.include? 'EndDate') && (body.include? 'goodnames')
|
||||
end.to_return(status: 200, body: response)
|
||||
(body.include? 'start_date') && (body.include? 'end_date') && (body.include? 'goodnames')
|
||||
end.to_return(status: 200, body: @response)
|
||||
|
||||
assert_difference('Invoice.count', 2) do
|
||||
assert_difference('Directo.count', 2) do
|
||||
stub_request(:post, @e_invoice_url).with do |request|
|
||||
body = CGI.unescape(request.body)
|
||||
(body.include? '309902') && (body.include? 'goodnames')
|
||||
end.to_return(status: 200, body: @response)
|
||||
|
||||
stub_request(:post, @e_invoice_url).with do |request|
|
||||
body = CGI.unescape(request.body)
|
||||
(body.include? '309903') && (body.include? 'bestnames')
|
||||
end.to_return(status: 200, body: @response)
|
||||
|
||||
stub_request(:post, @monthly_invoice_numbers_generator_url)
|
||||
.to_return(status: :ok, body: { invoice_numbers: [309_902, 309_903] }.to_json, headers: {})
|
||||
|
||||
assert_enqueued_jobs 2, only: SendEInvoiceJob do
|
||||
assert_difference('Invoice.count', 2) do
|
||||
SendMonthlyInvoicesJob.perform_now
|
||||
end
|
||||
end
|
||||
|
@ -262,17 +230,19 @@ class SendMonthlyInvoicesJobTest < ActiveSupport::TestCase
|
|||
assert_requested second_registrar_stub
|
||||
|
||||
assert_emails 2
|
||||
assert_equal 2, EInvoice::Providers::TestProvider.deliveries.count
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def metadata
|
||||
{
|
||||
"items" => [
|
||||
{ "description" => "Domeenide registreerimine - Juuli 2010" },
|
||||
{ "product_id" => nil, "quantity" => 1, "unit" => "tk", "price" => 10.0, "description" => ".test registreerimine: 1 aasta(t)" },
|
||||
{ "product_id" => "ETTEM06", "description" => "Domeenide ettemaks", "quantity" => -1, "price" => 10.0, "unit" => "tk" },
|
||||
'items' => [
|
||||
{ 'description' => 'Domeenide registreerimine - Juuli 2010' },
|
||||
{ 'product_id' => nil, 'quantity' => 1, 'unit' => 'tk', 'price' => 10.0,
|
||||
'description' => '.test registreerimine: 1 aasta(t)',
|
||||
'duration_in_years' => 1 },
|
||||
{ 'product_id' => 'ETTEM06', 'description' => 'Domeenide ettemaks', 'quantity' => -1,
|
||||
'price' => 10.0, 'unit' => 'tk' },
|
||||
],
|
||||
}
|
||||
end
|
||||
|
|
|
@ -204,20 +204,15 @@ class ProcessPaymentsTaskTest < ActiveJob::TestCase
|
|||
end
|
||||
|
||||
def test_topup_creates_invoice_and_send_it_as_paid
|
||||
stub_request(:post, 'https://eis_billing_system:3000/api/v1/e_invoice/e_invoice')
|
||||
.to_return(status: 200, body: '', headers: {})
|
||||
stub_request(:post, 'https://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator')
|
||||
.to_return(status: 200, body: { everypay_link: 'http://link.test' }.to_json, headers: {})
|
||||
|
||||
invoice_n = Invoice.order(number: :desc).last.number
|
||||
stub_request(:post, 'https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator')
|
||||
.to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
|
||||
.to_return(status: 200, body: { invoice_number: (invoice_n + 3).to_s }.to_json, headers: {})
|
||||
|
||||
stub_request(:post, 'https://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator')
|
||||
.to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
|
||||
|
||||
stub_request(:put, 'https://registry:3000/eis_billing/e_invoice_response')
|
||||
.to_return(status: 200,
|
||||
body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now - 10.minutes}\"}",
|
||||
headers: {})
|
||||
stub_request(:post, 'https://eis_billing_system:3000/api/v1/e_invoice/e_invoice')
|
||||
.to_return(status: 200, body: '', headers: {})
|
||||
|
||||
registrar = registrars(:bestnames)
|
||||
@invoice.payment_orders.destroy_all
|
||||
|
@ -229,7 +224,6 @@ class ProcessPaymentsTaskTest < ActiveJob::TestCase
|
|||
|
||||
invoice = Invoice.last
|
||||
assert invoice.paid?
|
||||
assert_not invoice.e_invoice_sent_at.blank?
|
||||
|
||||
pdf_source = Invoice::PdfGenerator.new(invoice)
|
||||
pdf_source.send(:invoice_html).include?('Receipt date')
|
||||
|
|
|
@ -21,18 +21,15 @@ class ReloadBalanceTaskTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
def test_issues_invoice_when_auto_reload_is_enabled_and_threshold_reached
|
||||
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
|
||||
to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
|
||||
stub_request(:post, 'https://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator')
|
||||
.to_return(status: 200, body: { everypay_link: 'http://link.test' }.to_json, headers: {})
|
||||
|
||||
invoice_n = Invoice.order(number: :desc).last.number
|
||||
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
|
||||
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
|
||||
stub_request(:post, 'https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator')
|
||||
.to_return(status: 200, body: { invoice_number: (invoice_n + 3).to_s }.to_json, headers: {})
|
||||
|
||||
stub_request(:put, "https://registry:3000/eis_billing/e_invoice_response").
|
||||
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
|
||||
|
||||
stub_request(:post, "https://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
|
||||
to_return(status: 200, body: "", headers: {})
|
||||
stub_request(:post, 'https://eis_billing_system:3000/api/v1/e_invoice/e_invoice')
|
||||
.to_return(status: 200, body: '', headers: {})
|
||||
|
||||
reload_amount = 100
|
||||
registrar = registrar_with_auto_reload_enabled_and_threshold_reached(reload_amount)
|
||||
|
@ -40,9 +37,6 @@ class ReloadBalanceTaskTest < ActiveSupport::TestCase
|
|||
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
|
||||
|
@ -64,18 +58,15 @@ class ReloadBalanceTaskTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
def test_marks_registrar_as_pending_balance_reload
|
||||
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
|
||||
to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
|
||||
stub_request(:post, 'https://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator')
|
||||
.to_return(status: 200, body: { everypay_link: 'http://link.test' }.to_json, headers: {})
|
||||
|
||||
invoice_n = Invoice.order(number: :desc).last.number
|
||||
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
|
||||
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
|
||||
|
||||
stub_request(:put, "https://registry:3000/eis_billing/e_invoice_response").
|
||||
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
|
||||
stub_request(:post, 'https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator')
|
||||
.to_return(status: 200, body: { invoice_number: (invoice_n + 3).to_s }.to_json, headers: {})
|
||||
|
||||
stub_request(:post, "https://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
|
||||
to_return(status: 200, body: "", headers: {})
|
||||
stub_request(:post, 'https://eis_billing_system:3000/api/v1/e_invoice/e_invoice')
|
||||
.to_return(status: 200, body: '', headers: {})
|
||||
|
||||
registrar = registrar_with_auto_reload_enabled_and_threshold_reached
|
||||
|
||||
|
@ -86,18 +77,15 @@ class ReloadBalanceTaskTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
def test_output
|
||||
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
|
||||
to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
|
||||
stub_request(:post, 'https://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator')
|
||||
.to_return(status: 200, body: { everypay_link: 'http://link.test' }.to_json, headers: {})
|
||||
|
||||
invoice_n = Invoice.order(number: :desc).last.number
|
||||
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
|
||||
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
|
||||
stub_request(:post, 'https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator')
|
||||
.to_return(status: 200, body: { invoice_number: (invoice_n + 3).to_s }.to_json, headers: {})
|
||||
|
||||
stub_request(:put, "https://registry:3000/eis_billing/e_invoice_response").
|
||||
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
|
||||
|
||||
stub_request(:post, "https://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
|
||||
to_return(status: 200, body: "", headers: {})
|
||||
stub_request(:post, 'https://eis_billing_system:3000/api/v1/e_invoice/e_invoice')
|
||||
.to_return(status: 200, body: '', headers: {})
|
||||
|
||||
reload_amount = 100
|
||||
registrar = registrar_with_auto_reload_enabled_and_threshold_reached(reload_amount)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue