updated tests

This commit is contained in:
olegphenomenon 2022-02-10 15:03:27 +02:00
parent ef03166fee
commit d0236be063
21 changed files with 578 additions and 658 deletions

View file

@ -18,7 +18,6 @@ module EisBilling
def decoded_token def decoded_token
if auth_header if auth_header
token = auth_header.split(' ')[1] token = auth_header.split(' ')[1]
# header: { 'Authorization': 'Bearer <token>' }
begin begin
JWT.decode(token, ENV['secret_word'], true, algorithm: 'HS256') JWT.decode(token, ENV['secret_word'], true, algorithm: 'HS256')
rescue JWT::DecodeError rescue JWT::DecodeError

View file

@ -8,9 +8,6 @@ module EisBilling
sum = params[:standing_amount] sum = params[:standing_amount]
everypay_response = params everypay_response = params
logger.info 'REQUEST FROM BILLING'
logger.info params
payment_status = define_payment_status(params[:payment_state]) payment_status = define_payment_status(params[:payment_state])
invoice = Invoice.find_by(number: invoice_number) invoice = Invoice.find_by(number: invoice_number)

View file

@ -7,6 +7,7 @@ class SendEInvoiceTwoJob < ApplicationJob
return unless need_to_process_invoice?(invoice: invoice, payable: payable) return unless need_to_process_invoice?(invoice: invoice, payable: payable)
send_invoice_to_eis_billing(invoice: invoice, payable: payable) send_invoice_to_eis_billing(invoice: invoice, payable: payable)
invoice.update(e_invoice_sent_at: Time.zone.now)
rescue StandardError => e rescue StandardError => e
log_error(invoice: invoice, error: e) log_error(invoice: invoice, error: e)
raise e raise e

View file

@ -16,7 +16,7 @@ module EisBilling
uri = URI(url) uri = URI(url)
http = Net::HTTP.new(uri.host, uri.port) http = Net::HTTP.new(uri.host, uri.port)
unless Rails.env.development? unless Rails.env.development? || Rails.env.test?
http.use_ssl = true http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end end

View file

@ -237,4 +237,6 @@ nameserver_validation_timeout: '1'
eis_billing_system_base_url_dev: 'http://eis_billing_system:3000' eis_billing_system_base_url_dev: 'http://eis_billing_system:3000'
eis_billing_system_base_url_staging: 'https://st-billing.infra.tld.ee' eis_billing_system_base_url_staging: 'https://st-billing.infra.tld.ee'
secret_access_word: 'please-Give-Me-accesS'
secret_word: 'this-secret-should-be-change'
billing_system_integrated: 'true' billing_system_integrated: 'true'

View file

@ -24,38 +24,30 @@ class AdminAreaInvoicesIntegrationTest < ApplicationIntegrationTest
end end
def test_create_new_invoice def test_create_new_invoice
invoice_n = Invoice.order(number: :desc).last.number if Feature.billing_system_integrated?
invoice_n = Invoice.order(number: :desc).last.number
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator"). stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
with( to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
body: "{\"transaction_amount\":\"1200.0\",\"order_reference\":4,\"customer_name\":\"Best Names\",\"customer_email\":\"info@bestnames.test\",\"custom_field_1\":\"\",\"custom_field_2\":\"registry\",\"invoice_number\":4}",
headers: {
'Accept'=>'Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw==',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization'=>'Bearer foobar',
'Content-Type'=>'application/json',
'User-Agent'=>'Ruby'
}).
to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator"). stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
with( to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
headers: {
'Accept'=>'Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw==',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization'=>'Bearer foobar',
'Content-Type'=>'application/json',
'User-Agent'=>'Ruby'
}).
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
visit new_admin_invoice_path
assert_text 'Create new invoice' stub_request(:put, "http://registry:3000/eis_billing/e_invoice_response").
select 'Best Names', from: 'deposit_registrar_id', match: :first to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
fill_in 'Amount', with: '1000'
click_on 'Save'
assert_equal page.status_code, 200 stub_request(:post, "http://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
to_return(status: 200, body: "", headers: {})
visit new_admin_invoice_path
assert_text 'Create new invoice'
select 'Best Names', from: 'deposit_registrar_id', match: :first
fill_in 'Amount', with: '1000'
click_on 'Save'
assert_equal page.status_code, 200
end
end end
def test_visit_list_of_invoices_pages def test_visit_list_of_invoices_pages

View file

@ -6,35 +6,40 @@ class DirectoResponseTest < ApplicationIntegrationTest
@invoice = invoices(:one) @invoice = invoices(:one)
@response_xml = '<?xml version="1.0" encoding="UTF-8"?><results><Result Type="0" Desc="OK" docid="1" doctype="ARVE" submit="Invoices"/></results>' @response_xml = '<?xml version="1.0" encoding="UTF-8"?><results><Result Type="0" Desc="OK" docid="1" doctype="ARVE" submit="Invoices"/></results>'
Spy.on_instance_method(EisBilling::BaseController, :authorized).and_return(true)
end end
def test_should_created_directo_instance def test_should_created_directo_instance
directo_response_from_billing = { if Feature.billing_system_integrated?
response: 'this is response', directo_response_from_billing = {
xml_data: @response_xml, response: 'this is response',
month: true xml_data: @response_xml,
} month: true
}
assert_difference 'Directo.count', 1 do assert_difference 'Directo.count', 1 do
put eis_billing_directo_response_path, params: JSON.parse(directo_response_from_billing.to_json), put eis_billing_directo_response_path, params: JSON.parse(directo_response_from_billing.to_json),
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
end end
end end
def test_should_update_related_invoice def test_should_update_related_invoice
directo_response_from_billing = { if Feature.billing_system_integrated?
response: 'this is response', directo_response_from_billing = {
xml_data: @response_xml response: 'this is response',
} xml_data: @response_xml
}
refute @invoice.in_directo refute @invoice.in_directo
assert_difference 'Directo.count', 1 do assert_difference 'Directo.count', 1 do
put eis_billing_directo_response_path, params: JSON.parse(directo_response_from_billing.to_json), put eis_billing_directo_response_path, params: JSON.parse(directo_response_from_billing.to_json),
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
@invoice.reload
assert @invoice.in_directo
end end
@invoice.reload
assert @invoice.in_directo
end end
end end

View file

@ -4,25 +4,39 @@ class LhvConnectTransactionsIntegrationTest < ApplicationIntegrationTest
setup do setup do
@invoice = invoices(:unpaid) @invoice = invoices(:unpaid)
sign_in users(:api_bestnames) sign_in users(:api_bestnames)
Spy.on_instance_method(EisBilling::BaseController, :authorized).and_return(true)
end end
def test_should_saved_transaction_data def test_should_saved_transaction_data
test_transaction = OpenStruct.new(amount: 0.1, if Feature.billing_system_integrated?
currency: 'EUR', test_transaction_1 = OpenStruct.new(amount: 0.1,
date: Time.zone.today, currency: 'EUR',
payment_reference_number: '2199812', date: Time.zone.today,
payment_description: "description 2199812") payment_reference_number: '2199812',
payment_description: "description 2199812")
lhv_transactions = [] test_transaction_2 = OpenStruct.new(amount: 0.1,
currency: 'EUR',
date: Time.zone.today,
payment_reference_number: '2199813',
payment_description: "description 2199813")
3.times do test_transaction_3 = OpenStruct.new(amount: 0.1,
lhv_transactions << test_transaction currency: 'EUR',
end date: Time.zone.today,
payment_reference_number: '2199814',
payment_description: "description 2199814")
assert_difference 'BankStatement.count', 3 do lhv_transactions = []
assert_difference 'BankTransaction.count', 3 do lhv_transactions << test_transaction_1
post eis_billing_lhv_connect_transactions_path, params: { "_json" => JSON.parse(lhv_transactions.to_json) }, lhv_transactions << test_transaction_2
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } lhv_transactions << test_transaction_3
assert_difference 'BankStatement.count', 3 do
assert_difference 'BankTransaction.count', 3 do
post eis_billing_lhv_connect_transactions_path, params: { "_json" => JSON.parse(lhv_transactions.to_json) },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
end end
end end
end end

View file

@ -4,55 +4,60 @@ class PaymentStatusIntegrationTest < ApplicationIntegrationTest
setup do setup do
@invoice = invoices(:unpaid) @invoice = invoices(:unpaid)
sign_in users(:api_bestnames) sign_in users(:api_bestnames)
Spy.on_instance_method(EisBilling::BaseController, :authorized).and_return(true)
end end
def test_update_payment_status_should_create_succesfully_billing_instaces def test_update_payment_status_should_create_succesfully_billing_instaces
payload = { if Feature.billing_system_integrated?
"order_reference" => @invoice.number, payload = {
"transaction_time" => Time.zone.now - 2.minute, "order_reference" => @invoice.number,
"standing_amount" => @invoice.total, "transaction_time" => Time.zone.now - 2.minute,
"payment_state" => 'settled' "standing_amount" => @invoice.total,
} "payment_state" => 'settled'
}
assert_difference -> { @invoice.payment_orders.count } do assert_difference -> { @invoice.payment_orders.count } do
assert_difference -> { BankTransaction.count } do assert_difference -> { BankTransaction.count } do
put eis_billing_payment_status_path, params: payload, put eis_billing_payment_status_path, params: payload,
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
end end
bank_transaction = BankTransaction.order(created_at: :desc).first
invoice_payment_order = @invoice.payment_orders.order(created_at: :desc).first
assert_equal bank_transaction.sum, @invoice.total
assert_equal invoice_payment_order.status, "paid"
assert_equal @invoice.account_activity.activity_type, "add_credit"
assert_response :ok
end end
bank_transaction = BankTransaction.order(created_at: :desc).first
invoice_payment_order = @invoice.payment_orders.order(created_at: :desc).first
assert_equal bank_transaction.sum, @invoice.total
assert_equal invoice_payment_order.status, "paid"
assert_equal @invoice.account_activity.activity_type, "add_credit"
assert_response :ok
end end
def test_update_payment_status_should_create_failed_payment def test_update_payment_status_should_create_failed_payment
payload = { if Feature.billing_system_integrated?
"order_reference" => @invoice.number, payload = {
"transaction_time" => Time.zone.now - 2.minute, "order_reference" => @invoice.number,
"standing_amount" => @invoice.total, "transaction_time" => Time.zone.now - 2.minute,
"payment_state" => 'cancelled' "standing_amount" => @invoice.total,
} "payment_state" => 'cancelled'
}
assert_difference -> { @invoice.payment_orders.count } do assert_difference -> { @invoice.payment_orders.count } do
assert_difference -> { BankTransaction.count } do assert_difference -> { BankTransaction.count } do
put eis_billing_payment_status_path, params: payload, put eis_billing_payment_status_path, params: payload,
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
end end
bank_transaction = BankTransaction.order(created_at: :desc).first
invoice_payment_order = @invoice.payment_orders.order(created_at: :desc).first
assert_equal bank_transaction.sum, @invoice.total
assert_equal invoice_payment_order.status, "failed"
assert_equal @invoice.account_activity.activity_type, "add_credit"
assert_response :ok
end end
bank_transaction = BankTransaction.order(created_at: :desc).first
invoice_payment_order = @invoice.payment_orders.order(created_at: :desc).first
assert_equal bank_transaction.sum, @invoice.total
assert_equal invoice_payment_order.status, "failed"
assert_equal @invoice.account_activity.activity_type, "add_credit"
assert_response :ok
end end
end end

View file

@ -16,105 +16,87 @@ class BankTransactionTest < ActiveSupport::TestCase
end end
def test_binds_if_this_sum_invoice_already_present def test_binds_if_this_sum_invoice_already_present
invoice_n = Invoice.order(number: :desc).last.number if Feature.billing_system_integrated?
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator"). invoice_n = Invoice.order(number: :desc).last.number
with( stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
headers: { to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
'Accept'=>'Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw==', create_payable_invoice(number: '2222', total: 10, reference_no: '1234567')
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', another_invoice = @invoice.dup
'Authorization'=>'Bearer foobar', another_invoice.save(validate: false)
'Content-Type'=>'application/json', another_invoice.update(reference_no: '7654321', number: '2221')
'User-Agent'=>'Ruby'
}).
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
create_payable_invoice(number: '2222', total: 10, reference_no: '1234567')
another_invoice = @invoice.dup
another_invoice.save(validate: false)
another_invoice.update(reference_no: '7654321', number: '2221')
another_item = @invoice.items.first.dup another_item = @invoice.items.first.dup
another_item.invoice = another_invoice another_item.invoice = another_invoice
another_item.save another_item.save
another_invoice.reload another_invoice.reload
first_transaction = BankTransaction.new(sum: 10, first_transaction = BankTransaction.new(sum: 10,
description: 'Order nr 1 from registrar 1234567 second number 2345678') description: 'Order nr 1 from registrar 1234567 second number 2345678')
first_transaction.create_activity(another_invoice.buyer, another_invoice) first_transaction.create_activity(another_invoice.buyer, another_invoice)
transaction = BankTransaction.new(sum: 10, transaction = BankTransaction.new(sum: 10,
description: 'Order nr 1 from registrar 1234567 second number 2345678') description: 'Order nr 1 from registrar 1234567 second number 2345678')
assert_difference 'AccountActivity.count' do assert_difference 'AccountActivity.count' do
transaction.autobind_invoice transaction.autobind_invoice
end
end end
end end
def test_binds_if_this_sum_cancelled_invoice_already_present def test_binds_if_this_sum_cancelled_invoice_already_present
invoice_n = Invoice.order(number: :desc).last.number if Feature.billing_system_integrated?
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator"). invoice_n = Invoice.order(number: :desc).last.number
with( stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
headers: { to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
'Accept'=>'Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw==', create_payable_invoice(number: '2222', total: 10, reference_no: '1234567')
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', another_invoice = @invoice.dup
'Authorization'=>'Bearer foobar', another_invoice.save(validate: false)
'Content-Type'=>'application/json',
'User-Agent'=>'Ruby'
}).
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
create_payable_invoice(number: '2222', total: 10, reference_no: '1234567')
another_invoice = @invoice.dup
another_invoice.save(validate: false)
another_item = @invoice.items.first.dup another_item = @invoice.items.first.dup
another_item.invoice = another_invoice another_item.invoice = another_invoice
another_item.save another_item.save
another_invoice.reload another_invoice.reload
another_invoice.update(reference_no: '1234567', number: '2221', cancelled_at: Time.zone.now) another_invoice.update(reference_no: '1234567', number: '2221', cancelled_at: Time.zone.now)
transaction = BankTransaction.new(sum: 10, transaction = BankTransaction.new(sum: 10,
description: 'Order nr 1 from registrar 1234567 second number 2345678') description: 'Order nr 1 from registrar 1234567 second number 2345678')
assert_difference 'AccountActivity.count' do assert_difference 'AccountActivity.count' do
transaction.autobind_invoice transaction.autobind_invoice
end
end end
end end
def test_marks_the_first_one_as_paid_if_same_sum def test_marks_the_first_one_as_paid_if_same_sum
invoice_n = Invoice.order(number: :desc).last.number if Feature.billing_system_integrated?
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator"). invoice_n = Invoice.order(number: :desc).last.number
with( stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
headers: { to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
'Accept'=>'Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw==', create_payable_invoice(number: '2222', total: 10, reference_no: '1234567')
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', another_invoice = @invoice.dup
'Authorization'=>'Bearer foobar', another_invoice.save(validate: false)
'Content-Type'=>'application/json', another_invoice.update(reference_no: '7654321', number: '2221')
'User-Agent'=>'Ruby'
}).
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
create_payable_invoice(number: '2222', total: 10, reference_no: '1234567')
another_invoice = @invoice.dup
another_invoice.save(validate: false)
another_invoice.update(reference_no: '7654321', number: '2221')
another_item = @invoice.items.first.dup another_item = @invoice.items.first.dup
another_item.invoice = another_invoice another_item.invoice = another_invoice
another_item.save another_item.save
another_invoice.reload another_invoice.reload
transaction = BankTransaction.new(sum: 10, transaction = BankTransaction.new(sum: 10,
description: 'Order nr 1 from registrar 1234567 second number 2345678') description: 'Order nr 1 from registrar 1234567 second number 2345678')
assert_difference 'AccountActivity.count' do assert_difference 'AccountActivity.count' do
transaction.autobind_invoice transaction.autobind_invoice
end
@invoice.reload
another_invoice.reload
assert(@invoice.paid?)
assert_not(another_invoice.paid?)
end end
@invoice.reload
another_invoice.reload
assert(@invoice.paid?)
assert_not(another_invoice.paid?)
end end
def test_matches_against_invoice_nubmber_and_reference_number_in_description def test_matches_against_invoice_nubmber_and_reference_number_in_description

View file

@ -7,19 +7,12 @@ class ReferenceNoTest < ActiveSupport::TestCase
end end
def test_generated_reference_number_conforms_to_format def test_generated_reference_number_conforms_to_format
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/reference_number_generator"). if Feature.billing_system_integrated?
with( stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/reference_number_generator")
body: "{\"initiator\":\"registry\"}", .to_return(status: 200, body: "{\"reference_number\":\"12332\"}", headers: {})
headers: {
'Accept'=>'Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw==',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization'=>'Bearer foobar',
'Content-Type'=>'application/json',
'User-Agent'=>'Ruby'
}).
to_return(status: 200, body: "{\"reference_number\":\"12332\"}", headers: {})
reference_no = Billing::ReferenceNo.generate reference_no = Billing::ReferenceNo.generate
assert_match Billing::ReferenceNo::REGEXP, reference_no assert_match Billing::ReferenceNo::REGEXP, reference_no
end
end end
end end

View file

@ -5,6 +5,7 @@ class InvoiceTest < ActiveSupport::TestCase
setup do setup do
@invoice = invoices(:one) @invoice = invoices(:one)
Spy.on_instance_method(EisBilling::BaseController, :authorized).and_return(true)
end end
def test_fixture_is_valid def test_fixture_is_valid
@ -117,78 +118,69 @@ class InvoiceTest < ActiveSupport::TestCase
end end
def test_creates_invoice_with_bank_transaction_total def test_creates_invoice_with_bank_transaction_total
registrar = registrars(:bestnames) if Feature.billing_system_integrated?
transaction = bank_transactions(:one).dup registrar = registrars(:bestnames)
transaction.reference_no = registrar.reference_no transaction = bank_transactions(:one).dup
transaction.sum = 250 transaction.reference_no = registrar.reference_no
transaction.sum = 250
invoice_n = Invoice.order(number: :desc).last.number invoice_n = Invoice.order(number: :desc).last.number
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator") stub_request(:post, "http://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}\"}", headers: {})
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator") stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator")
.to_return(status: 200, body: "", headers: {}) .to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
invoice = Invoice.create_from_transaction!(transaction) stub_request(:put, "http://registry:3000/eis_billing/e_invoice_response").
assert_equal 250, invoice.total to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
invoice_n = Invoice.order(number: :desc).last.number stub_request(:post, "http://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator"). to_return(status: 200, body: "", headers: {})
with(
headers: {
'Accept'=>'Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw==',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization'=>'Bearer foobar',
'Content-Type'=>'application/json',
'User-Agent'=>'Ruby'
}).
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 4}\"}", headers: {})
transaction.sum = 146.88 invoice = Invoice.create_from_transaction!(transaction)
invoice = Invoice.create_from_transaction!(transaction) assert_equal 250, invoice.total
assert_equal 146.88, invoice.total
invoice_n = Invoice.order(number: :desc).last.number invoice_n = Invoice.order(number: :desc).last.number
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator"). stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
with( to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 4}\"}", headers: {})
headers: {
'Accept'=>'Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw==',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization'=>'Bearer foobar',
'Content-Type'=>'application/json',
'User-Agent'=>'Ruby'
}).
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 5}\"}", headers: {})
transaction.sum = 0.99 transaction.sum = 146.88
invoice = Invoice.create_from_transaction!(transaction) invoice = Invoice.create_from_transaction!(transaction)
assert_equal 0.99, invoice.total assert_equal 146.88, invoice.total
invoice_n = Invoice.order(number: :desc).last.number
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 5}\"}", headers: {})
transaction.sum = 0.99
invoice = Invoice.create_from_transaction!(transaction)
assert_equal 0.99, invoice.total
end
end end
def test_emails_invoice_after_creating_topup_invoice def test_emails_invoice_after_creating_topup_invoice
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator"). if Feature.billing_system_integrated?
with( invoice_n = Invoice.order(number: :desc).last.number
body: "{\"transaction_amount\":\"250.0\",\"order_reference\":4,\"customer_name\":\"Best Names\",\"customer_email\":\"info@bestnames.test\",\"custom_field_1\":\"Direct top-up via bank transfer\",\"custom_field_2\":\"registry\",\"invoice_number\":4}", stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
headers: { to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
'Accept'=>'Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw==',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization'=>'Bearer foobar',
'Content-Type'=>'application/json',
'User-Agent'=>'Ruby'
}).
to_return(status: 200, body: "", headers: {})
registrar = registrars(:bestnames) stub_request(:put, "http://registry:3000/eis_billing/e_invoice_response").
transaction = bank_transactions(:one).dup to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
transaction.reference_no = registrar.reference_no
transaction.sum = 250
invoice_n = Invoice.order(number: :desc).last.number stub_request(:post, "http://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
response = OpenStruct.new(body: "{\"invoice_number\":\"#{invoice_n + 3}\"}") to_return(status: 200, body: "", headers: {})
Spy.on(EisBilling::GetInvoiceNumber, :send_invoice).and_return(response)
assert_emails 1 do registrar = registrars(:bestnames)
Invoice.create_from_transaction!(transaction) transaction = bank_transactions(:one).dup
transaction.reference_no = registrar.reference_no
transaction.sum = 250
response = OpenStruct.new(body: "{\"invoice_number\":\"#{invoice_n + 3}\"}")
Spy.on(EisBilling::GetInvoiceNumber, :send_invoice).and_return(response)
assert_emails 1 do
Invoice.create_from_transaction!(transaction)
end
end end
end end
end end

View file

@ -6,6 +6,7 @@ class RegistrarTest < ActiveJob::TestCase
@original_default_language = Setting.default_language @original_default_language = Setting.default_language
@original_days_to_keep_invoices_active = Setting.days_to_keep_invoices_active @original_days_to_keep_invoices_active = Setting.days_to_keep_invoices_active
@old_validation_type = Truemail.configure.default_validation_type @old_validation_type = Truemail.configure.default_validation_type
Spy.on_instance_method(EisBilling::BaseController, :authorized).and_return(true)
end end
teardown do teardown do
@ -144,70 +145,55 @@ class RegistrarTest < ActiveJob::TestCase
end end
def test_issues_new_invoice def test_issues_new_invoice
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator"). if Feature.billing_system_integrated?
with( stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
body: "{\"transaction_amount\":\"120.0\",\"order_reference\":4,\"customer_name\":\"Best Names\",\"customer_email\":\"info@bestnames.test\",\"custom_field_1\":null,\"custom_field_2\":\"registry\",\"invoice_number\":4}", to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
headers: {
'Accept'=>'Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw==',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization'=>'Bearer foobar',
'Content-Type'=>'application/json',
'User-Agent'=>'Ruby'
}).
to_return(status: 200, body: "", headers: {})
invoice_n = Invoice.order(number: :desc).last.number invoice_n = Invoice.order(number: :desc).last.number
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator"). stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
with( to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
headers: {
'Accept'=>'Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw==',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization'=>'Bearer foobar',
'Content-Type'=>'application/json',
'User-Agent'=>'Ruby'
}).
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
travel_to Time.zone.parse('2010-07-05') stub_request(:put, "http://registry:3000/eis_billing/e_invoice_response").
Setting.days_to_keep_invoices_active = 10 to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
invoice = @registrar.issue_prepayment_invoice(100) stub_request(:post, "http://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
to_return(status: 200, body: "", headers: {})
assert_equal Date.parse('2010-07-05'), invoice.issue_date travel_to Time.zone.parse('2010-07-05')
assert_equal Date.parse('2010-07-15'), invoice.due_date Setting.days_to_keep_invoices_active = 10
invoice = @registrar.issue_prepayment_invoice(100)
assert_equal Date.parse('2010-07-05'), invoice.issue_date
assert_equal Date.parse('2010-07-15'), invoice.due_date
end
end end
def test_issues_e_invoice_along_with_invoice def test_issues_e_invoice_along_with_invoice
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator"). if Feature.billing_system_integrated?
with( stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
body: "{\"transaction_amount\":\"120.0\",\"order_reference\":4,\"customer_name\":\"Best Names\",\"customer_email\":\"info@bestnames.test\",\"custom_field_1\":null,\"custom_field_2\":\"registry\",\"invoice_number\":4}", to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
headers: {
'Accept'=>'Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw==',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization'=>'Bearer foobar',
'Content-Type'=>'application/json',
'User-Agent'=>'Ruby'
}).
to_return(status: 200, body: "", headers: {})
invoice_n = Invoice.order(number: :desc).last.number invoice_n = Invoice.order(number: :desc).last.number
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator"). stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
with( to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
headers: {
'Accept'=>'Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw==', stub_request(:put, "http://registry:3000/eis_billing/e_invoice_response").
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
'Authorization'=>'Bearer foobar',
'Content-Type'=>'application/json', stub_request(:post, "http://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
'User-Agent'=>'Ruby' to_return(status: 200, body: "", headers: {})
}). end
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
EInvoice::Providers::TestProvider.deliveries.clear EInvoice::Providers::TestProvider.deliveries.clear
perform_enqueued_jobs do perform_enqueued_jobs do
@registrar.issue_prepayment_invoice(100) @registrar.issue_prepayment_invoice(100)
end end
assert_equal 1, EInvoice::Providers::TestProvider.deliveries.count unless Feature.billing_system_integrated?
assert_equal 1, EInvoice::Providers::TestProvider.deliveries.count
end
end end
def test_invalid_without_address_street def test_invalid_without_address_street

View file

@ -6,6 +6,7 @@ class AdminAreaBankStatementTest < ApplicationSystemTestCase
travel_to Time.zone.parse('2010-07-05 00:30:00') travel_to Time.zone.parse('2010-07-05 00:30:00')
@invoice = invoices(:one) @invoice = invoices(:one)
Spy.on_instance_method(EisBilling::BaseController, :authorized).and_return(true)
end end
def test_update_bank_statement def test_update_bank_statement
@ -54,31 +55,39 @@ class AdminAreaBankStatementTest < ApplicationSystemTestCase
end end
def test_can_bind_statement_transactions def test_can_bind_statement_transactions
invoice_n = Invoice.order(number: :desc).last.number if Feature.billing_system_integrated?
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator") invoice_n = Invoice.order(number: :desc).last.number
.to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {}) stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator")
registrar = registrars(:bestnames) .to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
registrar = registrars(:bestnames)
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator") stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator")
.to_return(status: 200, body: "", headers: {}) .to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
registrar.issue_prepayment_invoice(500) stub_request(:put, "http://registry:3000/eis_billing/e_invoice_response")
invoice = registrar.invoices.last .to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
create_bank_statement stub_request(:post, "http://eis_billing_system:3000/api/v1/e_invoice/e_invoice")
click_link_or_button 'Add' .to_return(status: 200, body: "", headers: {})
assert_text 'Create bank transaction'
fill_in 'Description', with: "Invoice with id #{invoice.number}" registrar.issue_prepayment_invoice(500)
fill_in 'Reference number', with: invoice.reference_no invoice = registrar.invoices.last
fill_in 'Sum', with: invoice.total
fill_in 'Paid at', with: Time.zone.today.to_s
click_link_or_button 'Save'
click_link_or_button 'Back to bank statement' create_bank_statement
click_link_or_button 'Bind invoices' click_link_or_button 'Add'
assert_text 'Create bank transaction'
assert_text 'Invoices were fully binded' fill_in 'Description', with: "Invoice with id #{invoice.number}"
fill_in 'Reference number', with: invoice.reference_no
fill_in 'Sum', with: invoice.total
fill_in 'Paid at', with: Time.zone.today.to_s
click_link_or_button 'Save'
click_link_or_button 'Back to bank statement'
click_link_or_button 'Bind invoices'
assert_text 'Invoices were fully binded'
end
end end
def create_bank_statement def create_bank_statement

View file

@ -14,37 +14,30 @@ class AdminRegistrarsSystemTest < ApplicationSystemTestCase
end end
def test_creates_new_registrar def test_creates_new_registrar
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/reference_number_generator"). if Feature.billing_system_integrated?
with( stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/reference_number_generator").
body: "{\"initiator\":\"registry\"}", to_return(status: 200, body: "{\"reference_number\":\"12332\"}", headers: {})
headers: {
'Accept'=>'Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw==',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization'=>'Bearer foobar',
'Content-Type'=>'application/json',
'User-Agent'=>'Ruby'
}).
to_return(status: 200, body: "{\"reference_number\":\"12332\"}", headers: {})
assert_nil Registrar.find_by(name: 'Acme Ltd') assert_nil Registrar.find_by(name: 'Acme Ltd')
visit admin_registrars_path visit admin_registrars_path
click_on 'New registrar' click_on 'New registrar'
fill_in 'Name', with: 'Acme Ltd' fill_in 'Name', with: 'Acme Ltd'
fill_in 'Reg no', with: '1234' fill_in 'Reg no', with: '1234'
fill_in 'Contact e-mail', with: 'any@acme.test' fill_in 'Contact e-mail', with: 'any@acme.test'
fill_in 'Street', with: 'any' fill_in 'Street', with: 'any'
fill_in 'City', with: 'any' fill_in 'City', with: 'any'
fill_in 'State / Province', with: 'any' fill_in 'State / Province', with: 'any'
fill_in 'Zip', with: 'any' fill_in 'Zip', with: 'any'
select 'United States', from: 'Country' select 'United States', from: 'Country'
fill_in 'Accounting customer code', with: 'test' fill_in 'Accounting customer code', with: 'test'
fill_in 'Code', with: 'test' fill_in 'Code', with: 'test'
click_on 'Create registrar' click_on 'Create registrar'
assert_text 'Registrar has been successfully created' assert_text 'Registrar has been successfully created'
assert_text 'Acme Ltd' assert_text 'Acme Ltd'
end
end end
def test_updates_registrar def test_updates_registrar

View file

@ -11,36 +11,25 @@ class AddDepositsTest < ApplicationSystemTestCase
end end
def test_should_send_request_for_creating_invoice_to_eis_system def test_should_send_request_for_creating_invoice_to_eis_system
invoice_n = Invoice.order(number: :desc).last.number if Feature.billing_system_integrated?
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator"). invoice_n = Invoice.order(number: :desc).last.number
with( stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
body: "{\"transaction_amount\":\"120.0\",\"order_reference\":4,\"customer_name\":\"Best Names\",\"customer_email\":\"info@bestnames.test\",\"custom_field_1\":\"\",\"custom_field_2\":\"registry\",\"invoice_number\":4}", to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
headers: {
'Accept'=>'Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw==',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization'=>'Bearer foobar',
'Content-Type'=>'application/json',
'User-Agent'=>'Ruby'
}).
to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator"). stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
with( to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
headers: {
'Accept'=>'Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw==',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization'=>'Bearer foobar',
'Content-Type'=>'application/json',
'User-Agent'=>'Ruby'
}).
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
# eis_response = OpenStruct.new(body: "{\"payment_link\":\"http://link.test\"}")
# Spy.on_instance_method(EisBilling::AddDeposits, :send_invoice).and_return(eis_response)
visit new_registrar_deposit_url stub_request(:put, "http://registry:3000/eis_billing/e_invoice_response").
fill_in 'Amount', with: '100.0' to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
click_button text: 'Add'
assert_text 'Everypay link' stub_request(:post, "http://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
to_return(status: 200, body: "", headers: {})
visit new_registrar_deposit_url
fill_in 'Amount', with: '100.0'
click_button text: 'Add'
assert_text 'Everypay link'
end
end end
end end

View file

@ -7,6 +7,7 @@ class BalanceTopUpTest < ApplicationSystemTestCase
eis_response = OpenStruct.new(body: "{\"payment_link\":\"http://link.test\"}") eis_response = OpenStruct.new(body: "{\"payment_link\":\"http://link.test\"}")
Spy.on_instance_method(EisBilling::AddDeposits, :send_invoice).and_return(eis_response) Spy.on_instance_method(EisBilling::AddDeposits, :send_invoice).and_return(eis_response)
Spy.on_instance_method(EisBilling::BaseController, :authorized).and_return(true)
end end
teardown do teardown do
@ -14,31 +15,32 @@ class BalanceTopUpTest < ApplicationSystemTestCase
end end
def test_creates_new_invoice def test_creates_new_invoice
invoice_n = Invoice.order(number: :desc).last.number if Feature.billing_system_integrated?
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator"). invoice_n = Invoice.order(number: :desc).last.number
with( stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
headers: { to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
'Accept'=>'Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw==',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization'=>'Bearer foobar',
'Content-Type'=>'application/json',
'User-Agent'=>'Ruby'
}).
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
Setting.registry_vat_prc = 0.1
visit registrar_invoices_url stub_request(:put, "http://registry:3000/eis_billing/e_invoice_response")
click_link_or_button 'Add deposit' .to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
fill_in 'Amount', with: '25.5'
assert_difference 'Invoice.count' do stub_request(:post, "http://eis_billing_system:3000/api/v1/e_invoice/e_invoice")
click_link_or_button 'Add' .to_return(status: 200, body: "", headers: {})
Setting.registry_vat_prc = 0.1
visit registrar_invoices_url
click_link_or_button 'Add deposit'
fill_in 'Amount', with: '25.5'
assert_difference 'Invoice.count' do
click_link_or_button 'Add'
end
invoice = Invoice.last
assert_equal BigDecimal(10), invoice.vat_rate
assert_equal BigDecimal('28.05'), invoice.total
assert_text 'Please pay the following invoice'
end end
invoice = Invoice.last
assert_equal BigDecimal(10), invoice.vat_rate
assert_equal BigDecimal('28.05'), invoice.total
assert_text 'Please pay the following invoice'
end end
end end

View file

@ -27,46 +27,48 @@ class NewInvoicePaymentTest < ApplicationSystemTestCase
end end
def test_create_new_SEB_payment def test_create_new_SEB_payment
invoice_n = Invoice.order(number: :desc).last.number if Feature.billing_system_integrated?
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator"). invoice_n = Invoice.order(number: :desc).last.number
with( stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
headers: { to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
'Accept'=>'Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw==',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', stub_request(:put, "http://registry:3000/eis_billing/e_invoice_response").
'Authorization'=>'Bearer foobar', to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
'Content-Type'=>'application/json',
'User-Agent'=>'Ruby' stub_request(:post, "http://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
}). to_return(status: 200, body: "", headers: {})
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
create_invoice_and_visit_its_page create_invoice_and_visit_its_page
click_link_or_button 'seb' click_link_or_button 'seb'
form = page.find('form') form = page.find('form')
assert_equal('https://www.seb.ee/cgi-bin/dv.sh/ipank.r', form['action']) assert_equal('https://www.seb.ee/cgi-bin/dv.sh/ipank.r', form['action'])
assert_equal('post', form['method']) assert_equal('post', form['method'])
assert_equal('240.00', form.find_by_id('VK_AMOUNT', visible: false).value) assert_equal('240.00', form.find_by_id('VK_AMOUNT', visible: false).value)
end
end end
def test_create_new_Every_Pay_payment def test_create_new_Every_Pay_payment
invoice_n = Invoice.order(number: :desc).last.number if Feature.billing_system_integrated?
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator"). invoice_n = Invoice.order(number: :desc).last.number
with( stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
headers: { to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
'Accept'=>'Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw==',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization'=>'Bearer foobar',
'Content-Type'=>'application/json',
'User-Agent'=>'Ruby'
}).
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
create_invoice_and_visit_its_page
click_link_or_button 'every_pay'
expected_hmac_fields = 'account_id,amount,api_username,callback_url,' +
'customer_url,hmac_fields,nonce,order_reference,timestamp,transaction_type'
form = page.find('form') stub_request(:put, "http://registry:3000/eis_billing/e_invoice_response").
assert_equal('https://igw-demo.every-pay.com/transactions/', form['action']) to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
assert_equal('post', form['method'])
assert_equal(expected_hmac_fields, form.find_by_id('hmac_fields', visible: false).value) stub_request(:post, "http://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
assert_equal('240.00', form.find_by_id('amount', visible: false).value) to_return(status: 200, body: "", headers: {})
create_invoice_and_visit_its_page
click_link_or_button 'every_pay'
expected_hmac_fields = 'account_id,amount,api_username,callback_url,' +
'customer_url,hmac_fields,nonce,order_reference,timestamp,transaction_type'
form = page.find('form')
assert_equal('https://igw-demo.every-pay.com/transactions/', form['action'])
assert_equal('post', form['method'])
assert_equal(expected_hmac_fields, form.find_by_id('hmac_fields', visible: false).value)
assert_equal('240.00', form.find_by_id('amount', visible: false).value)
end
end end
end end

View file

@ -17,57 +17,59 @@ class NewInvoiceTest < ApplicationSystemTestCase
end end
def test_create_new_invoice_with_positive_amount def test_create_new_invoice_with_positive_amount
invoice_n = Invoice.order(number: :desc).last.number if Feature.billing_system_integrated?
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator"). invoice_n = Invoice.order(number: :desc).last.number
with( stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
headers: { to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
'Accept'=>'Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw==',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization'=>'Bearer foobar',
'Content-Type'=>'application/json',
'User-Agent'=>'Ruby'
}).
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
visit registrar_invoices_path
click_link_or_button 'Add deposit'
fill_in 'Amount', with: '200.00'
fill_in 'Description', with: 'My first invoice'
assert_difference 'Invoice.count', 1 do stub_request(:put, "http://registry:3000/eis_billing/e_invoice_response").
click_link_or_button 'Add' to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
stub_request(:post, "http://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
to_return(status: 200, body: "", headers: {})
visit registrar_invoices_path
click_link_or_button 'Add deposit'
fill_in 'Amount', with: '200.00'
fill_in 'Description', with: 'My first invoice'
assert_difference 'Invoice.count', 1 do
click_link_or_button 'Add'
end
assert_text 'Please pay the following invoice'
assert_text "Invoice no. #{invoice_n + 3}"
assert_text 'Subtotal 200,00 €'
assert_text 'Pay invoice'
end end
assert_text 'Please pay the following invoice'
assert_text "Invoice no. #{invoice_n + 3}"
assert_text 'Subtotal 200,00 €'
assert_text 'Pay invoice'
end end
def test_create_new_invoice_with_comma_in_number def test_create_new_invoice_with_comma_in_number
invoice_n = Invoice.order(number: :desc).last.number if Feature.billing_system_integrated?
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator"). invoice_n = Invoice.order(number: :desc).last.number
with( stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
headers: { to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
'Accept'=>'Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw==',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization'=>'Bearer foobar',
'Content-Type'=>'application/json',
'User-Agent'=>'Ruby'
}).
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
visit registrar_invoices_path
click_link_or_button 'Add deposit'
fill_in 'Amount', with: '200,00'
fill_in 'Description', with: 'My first invoice'
assert_difference 'Invoice.count', 1 do stub_request(:put, "http://registry:3000/eis_billing/e_invoice_response").
click_link_or_button 'Add' to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
stub_request(:post, "http://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
to_return(status: 200, body: "", headers: {})
visit registrar_invoices_path
click_link_or_button 'Add deposit'
fill_in 'Amount', with: '200,00'
fill_in 'Description', with: 'My first invoice'
assert_difference 'Invoice.count', 1 do
click_link_or_button 'Add'
end
assert_text 'Please pay the following invoice'
assert_text "Invoice no. #{invoice_n + 3}"
assert_text 'Subtotal 200,00 €'
assert_text 'Pay invoice'
end end
assert_text 'Please pay the following invoice'
assert_text "Invoice no. #{invoice_n + 3}"
assert_text 'Subtotal 200,00 €'
assert_text 'Pay invoice'
end end
def test_create_new_invoice_fails_when_amount_is_0 def test_create_new_invoice_fails_when_amount_is_0

View file

@ -77,39 +77,33 @@ class ProcessPaymentsTaskTest < ActiveJob::TestCase
end end
def test_if_invoice_is_overdue_than_48_hours def test_if_invoice_is_overdue_than_48_hours
invoice_n = Invoice.order(number: :desc).last.number if Feature.billing_system_integrated?
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator"). invoice_n = Invoice.order(number: :desc).last.number
with(
headers: {
'Accept'=>'Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw==',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization'=>'Bearer foobar',
'Content-Type'=>'application/json',
'User-Agent'=>'Ruby'
}).
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator"). Spy.on_instance_method(SendEInvoiceTwoJob, :perform_now).and_return(true)
with(
body: "{\"transaction_amount\":\"0.1\",\"order_reference\":5,\"customer_name\":\"Best Names\",\"customer_email\":\"info@bestnames.test\",\"custom_field_1\":\"Direct top-up via bank transfer\",\"custom_field_2\":\"registry\",\"invoice_number\":5}",
headers: {
'Accept'=>'Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw==',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization'=>'Bearer foobar',
'Content-Type'=>'application/json',
'User-Agent'=>'Ruby'
}).
to_return(status: 200, body: "", headers: {})
assert_not @invoice.paid? stub_request(:post, "http://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
to_return(status: 200, body: "", headers: {})
@account_activity.update(activity_type: "add_credit", bank_transaction: nil, created_at: Time.zone.today - 3.days, creator_str: 'AdminUser') stub_request(:put, "http://registry:3000/eis_billing/e_invoice_response").
@invoice.update(account_activity: @account_activity, total: @payment_amount) to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
assert @invoice.paid?
assert_difference 'AccountActivity.count' do stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
assert_difference 'Invoice.count' do to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
capture_io { run_task }
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
assert_not @invoice.paid?
@account_activity.update(activity_type: "add_credit", bank_transaction: nil, created_at: Time.zone.today - 3.days, creator_str: 'AdminUser')
@invoice.update(account_activity: @account_activity, total: @payment_amount)
assert @invoice.paid?
assert_difference 'AccountActivity.count' do
assert_difference 'Invoice.count' do
capture_io { run_task }
end
end end
end end
end end
@ -167,39 +161,32 @@ class ProcessPaymentsTaskTest < ActiveJob::TestCase
assert payment_order.failed? assert payment_order.failed?
end end
def test_credits_registrar_account_without_invoice_beforehand def test_credits_registrar_athout_invoice_beforehand
invoice_n = Invoice.order(number: :desc).last.number if Feature.billing_system_integrated?
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator"). invoice_n = Invoice.order(number: :desc).last.number
with( stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
headers: { to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}")
'Accept'=>'Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw==',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization'=>'Bearer foobar',
'Content-Type'=>'application/json',
'User-Agent'=>'Ruby'
}).
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator"). stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
with( to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
body: "{\"transaction_amount\":\"0.1\",\"order_reference\":5,\"customer_name\":\"Best Names\",\"customer_email\":\"info@bestnames.test\",\"custom_field_1\":\"Direct top-up via bank transfer\",\"custom_field_2\":\"registry\",\"invoice_number\":5}",
headers: {
'Accept'=>'Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw==',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization'=>'Bearer foobar',
'Content-Type'=>'application/json',
'User-Agent'=>'Ruby'
}).
to_return(status: 200, body: "", headers: {})
registrar = registrars(:bestnames) Spy.on_instance_method(SendEInvoiceTwoJob, :perform_now).and_return(true)
assert_changes -> { registrar.accounts.first.balance } do stub_request(:post, "http://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
run_task to_return(status: 200, body: "", headers: {})
end
assert_changes -> { registrar.invoices.count } do stub_request(:put, "http://registry:3000/eis_billing/e_invoice_response").
run_task to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
registrar = registrars(:bestnames)
assert_changes -> { registrar.accounts.first.balance } do
run_task
end
assert_changes -> { registrar.invoices.count } do
run_task
end
end end
end end
@ -211,49 +198,40 @@ class ProcessPaymentsTaskTest < ActiveJob::TestCase
end end
def test_topup_creates_invoice_and_send_it_as_paid def test_topup_creates_invoice_and_send_it_as_paid
invoice_n = Invoice.order(number: :desc).last.number if Feature.billing_system_integrated?
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator"). stub_request(:post, "http://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
with( to_return(status: 200, body: "", headers: {})
headers: {
'Accept'=>'Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw==',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization'=>'Bearer foobar',
'Content-Type'=>'application/json',
'User-Agent'=>'Ruby'
}).
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator"). invoice_n = Invoice.order(number: :desc).last.number
with( stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
body: "{\"transaction_amount\":\"0.1\",\"order_reference\":5,\"customer_name\":\"Best Names\",\"customer_email\":\"info@bestnames.test\",\"custom_field_1\":\"Direct top-up via bank transfer\",\"custom_field_2\":\"registry\",\"invoice_number\":5}", to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
headers: {
'Accept'=>'Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw==',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization'=>'Bearer foobar',
'Content-Type'=>'application/json',
'User-Agent'=>'Ruby'
}).
to_return(status: 200, body: "", headers: {})
registrar = registrars(:bestnames) stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
@invoice.payment_orders.destroy_all to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
@invoice.destroy
perform_enqueued_jobs do stub_request(:put, "http://registry:3000/eis_billing/e_invoice_response").
run_task to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
registrar = registrars(:bestnames)
@invoice.payment_orders.destroy_all
@invoice.destroy
perform_enqueued_jobs do
run_task
end
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')
email= ActionMailer::Base.deliveries.last
assert email.subject.include?('already paid')
assert_equal 0.1, registrar.invoices.last.total
end end
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')
email= ActionMailer::Base.deliveries.last
assert email.subject.include?('already paid')
assert_equal 0.1, registrar.invoices.last.total
end end
def test_output def test_output

View file

@ -5,6 +5,7 @@ class ReloadBalanceTaskTest < ActiveSupport::TestCase
setup do setup do
@registrar = registrars(:bestnames) @registrar = registrars(:bestnames)
Spy.on_instance_method(EisBilling::BaseController, :authorized).and_return(true)
end end
def test_issues_invoice_when_auto_reload_is_enabled_and_threshold_reached def test_issues_invoice_when_auto_reload_is_enabled_and_threshold_reached
@ -20,38 +21,30 @@ class ReloadBalanceTaskTest < ActiveSupport::TestCase
end end
def test_issues_invoice_when_auto_reload_is_enabled_and_threshold_reached def test_issues_invoice_when_auto_reload_is_enabled_and_threshold_reached
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator"). if Feature.billing_system_integrated?
with( stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
body: "{\"transaction_amount\":\"120.0\",\"order_reference\":4,\"customer_name\":\"Best Names\",\"customer_email\":\"info@bestnames.test\",\"custom_field_1\":null,\"custom_field_2\":\"registry\",\"invoice_number\":4}", to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
headers: {
'Accept'=>'Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw==', invoice_n = Invoice.order(number: :desc).last.number
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
'Authorization'=>'Bearer foobar', to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
'Content-Type'=>'application/json',
'User-Agent'=>'Ruby' stub_request(:put, "http://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, "http://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
to_return(status: 200, body: "", headers: {}) to_return(status: 200, body: "", headers: {})
invoice_n = Invoice.order(number: :desc).last.number reload_amount = 100
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator"). registrar = registrar_with_auto_reload_enabled_and_threshold_reached(reload_amount)
with(
headers: {
'Accept'=>'Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw==',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization'=>'Bearer foobar',
'Content-Type'=>'application/json',
'User-Agent'=>'Ruby'
}).
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
reload_amount = 100
registrar = registrar_with_auto_reload_enabled_and_threshold_reached(reload_amount)
assert_difference -> { registrar.invoices.count } do assert_difference -> { registrar.invoices.count } do
capture_io { run_task } capture_io { run_task }
end
invoice = registrar.invoices.last
assert_equal Time.zone.today, invoice.e_invoice_sent_at.to_date
end end
invoice = registrar.invoices.last
assert_equal Time.zone.today, invoice.e_invoice_sent_at.to_date
end end
def test_skips_issuing_invoice_when_threshold_is_not_reached def test_skips_issuing_invoice_when_threshold_is_not_reached
@ -73,67 +66,51 @@ class ReloadBalanceTaskTest < ActiveSupport::TestCase
end end
def test_marks_registrar_as_pending_balance_reload def test_marks_registrar_as_pending_balance_reload
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator"). if Feature.billing_system_integrated?
with( stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
body: "{\"transaction_amount\":\"120.0\",\"order_reference\":4,\"customer_name\":\"Best Names\",\"customer_email\":\"info@bestnames.test\",\"custom_field_1\":null,\"custom_field_2\":\"registry\",\"invoice_number\":4}", to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
headers: {
'Accept'=>'Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw==',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization'=>'Bearer foobar',
'Content-Type'=>'application/json',
'User-Agent'=>'Ruby'
}).
to_return(status: 200, body: "", headers: {})
invoice_n = Invoice.order(number: :desc).last.number invoice_n = Invoice.order(number: :desc).last.number
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator"). stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
with( to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
headers: {
'Accept'=>'Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw==', stub_request(:put, "http://registry:3000/eis_billing/e_invoice_response").
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
'Authorization'=>'Bearer foobar',
'Content-Type'=>'application/json', stub_request(:post, "http://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
'User-Agent'=>'Ruby' to_return(status: 200, body: "", headers: {})
}).
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
registrar = registrar_with_auto_reload_enabled_and_threshold_reached
capture_io { run_task } registrar = registrar_with_auto_reload_enabled_and_threshold_reached
registrar.reload
assert registrar.settings['balance_auto_reload']['pending'] capture_io { run_task }
registrar.reload
assert registrar.settings['balance_auto_reload']['pending']
end
end end
def test_output def test_output
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator"). if Feature.billing_system_integrated?
with( stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
body: "{\"transaction_amount\":\"120.0\",\"order_reference\":4,\"customer_name\":\"Best Names\",\"customer_email\":\"info@bestnames.test\",\"custom_field_1\":null,\"custom_field_2\":\"registry\",\"invoice_number\":4}", to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
headers: {
'Accept'=>'Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw==',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization'=>'Bearer foobar',
'Content-Type'=>'application/json',
'User-Agent'=>'Ruby'
}).
to_return(status: 200, body: "", headers: {})
invoice_n = Invoice.order(number: :desc).last.number invoice_n = Invoice.order(number: :desc).last.number
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator"). stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
with( to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
headers: {
'Accept'=>'Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw==',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization'=>'Bearer foobar',
'Content-Type'=>'application/json',
'User-Agent'=>'Ruby'
}).
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
reload_amount = 100
registrar = registrar_with_auto_reload_enabled_and_threshold_reached(reload_amount)
assert_equal 'Best Names', registrar.name
assert_output %(Registrar "Best Names" got #{number_to_currency(reload_amount, unit: 'EUR')}\nInvoiced total: 1\n) do stub_request(:put, "http://registry:3000/eis_billing/e_invoice_response").
run_task to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
stub_request(:post, "http://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)
assert_equal 'Best Names', registrar.name
assert_output %(Registrar "Best Names" got #{number_to_currency(reload_amount, unit: 'EUR')}\nInvoiced total: 1\n) do
run_task
end
end end
end end