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
if auth_header
token = auth_header.split(' ')[1]
# header: { 'Authorization': 'Bearer <token>' }
begin
JWT.decode(token, ENV['secret_word'], true, algorithm: 'HS256')
rescue JWT::DecodeError

View file

@ -8,9 +8,6 @@ module EisBilling
sum = params[:standing_amount]
everypay_response = params
logger.info 'REQUEST FROM BILLING'
logger.info params
payment_status = define_payment_status(params[:payment_state])
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)
send_invoice_to_eis_billing(invoice: invoice, payable: payable)
invoice.update(e_invoice_sent_at: Time.zone.now)
rescue StandardError => e
log_error(invoice: invoice, error: e)
raise e

View file

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

View file

@ -24,30 +24,21 @@ class AdminAreaInvoicesIntegrationTest < ApplicationIntegrationTest
end
def test_create_new_invoice
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").
with(
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").
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(: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: {})
visit new_admin_invoice_path
assert_text 'Create new invoice'
@ -57,6 +48,7 @@ class AdminAreaInvoicesIntegrationTest < ApplicationIntegrationTest
assert_equal page.status_code, 200
end
end
def test_visit_list_of_invoices_pages
visit admin_invoices_path

View file

@ -6,9 +6,11 @@ class DirectoResponseTest < ApplicationIntegrationTest
@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>'
Spy.on_instance_method(EisBilling::BaseController, :authorized).and_return(true)
end
def test_should_created_directo_instance
if Feature.billing_system_integrated?
directo_response_from_billing = {
response: 'this is response',
xml_data: @response_xml,
@ -20,8 +22,10 @@ class DirectoResponseTest < ApplicationIntegrationTest
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
end
end
def test_should_update_related_invoice
if Feature.billing_system_integrated?
directo_response_from_billing = {
response: 'this is response',
xml_data: @response_xml
@ -38,3 +42,4 @@ class DirectoResponseTest < ApplicationIntegrationTest
assert @invoice.in_directo
end
end
end

View file

@ -4,20 +4,33 @@ class LhvConnectTransactionsIntegrationTest < ApplicationIntegrationTest
setup do
@invoice = invoices(:unpaid)
sign_in users(:api_bestnames)
Spy.on_instance_method(EisBilling::BaseController, :authorized).and_return(true)
end
def test_should_saved_transaction_data
test_transaction = OpenStruct.new(amount: 0.1,
if Feature.billing_system_integrated?
test_transaction_1 = OpenStruct.new(amount: 0.1,
currency: 'EUR',
date: Time.zone.today,
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
lhv_transactions << test_transaction
end
test_transaction_3 = OpenStruct.new(amount: 0.1,
currency: 'EUR',
date: Time.zone.today,
payment_reference_number: '2199814',
payment_description: "description 2199814")
lhv_transactions = []
lhv_transactions << test_transaction_1
lhv_transactions << test_transaction_2
lhv_transactions << test_transaction_3
assert_difference 'BankStatement.count', 3 do
assert_difference 'BankTransaction.count', 3 do
@ -27,3 +40,4 @@ class LhvConnectTransactionsIntegrationTest < ApplicationIntegrationTest
end
end
end
end

View file

@ -4,9 +4,11 @@ class PaymentStatusIntegrationTest < ApplicationIntegrationTest
setup do
@invoice = invoices(:unpaid)
sign_in users(:api_bestnames)
Spy.on_instance_method(EisBilling::BaseController, :authorized).and_return(true)
end
def test_update_payment_status_should_create_succesfully_billing_instaces
if Feature.billing_system_integrated?
payload = {
"order_reference" => @invoice.number,
"transaction_time" => Time.zone.now - 2.minute,
@ -30,8 +32,10 @@ class PaymentStatusIntegrationTest < ApplicationIntegrationTest
assert_response :ok
end
end
def test_update_payment_status_should_create_failed_payment
if Feature.billing_system_integrated?
payload = {
"order_reference" => @invoice.number,
"transaction_time" => Time.zone.now - 2.minute,
@ -56,3 +60,4 @@ class PaymentStatusIntegrationTest < ApplicationIntegrationTest
assert_response :ok
end
end
end

View file

@ -16,16 +16,9 @@ class BankTransactionTest < ActiveSupport::TestCase
end
def test_binds_if_this_sum_invoice_already_present
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_number_generator").
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: {})
create_payable_invoice(number: '2222', total: 10, reference_no: '1234567')
another_invoice = @invoice.dup
@ -49,18 +42,12 @@ class BankTransactionTest < ActiveSupport::TestCase
transaction.autobind_invoice
end
end
end
def test_binds_if_this_sum_cancelled_invoice_already_present
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_number_generator").
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: {})
create_payable_invoice(number: '2222', total: 10, reference_no: '1234567')
another_invoice = @invoice.dup
@ -81,18 +68,12 @@ class BankTransactionTest < ActiveSupport::TestCase
transaction.autobind_invoice
end
end
end
def test_marks_the_first_one_as_paid_if_same_sum
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_number_generator").
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: {})
create_payable_invoice(number: '2222', total: 10, reference_no: '1234567')
another_invoice = @invoice.dup
@ -116,6 +97,7 @@ class BankTransactionTest < ActiveSupport::TestCase
assert(@invoice.paid?)
assert_not(another_invoice.paid?)
end
end
def test_matches_against_invoice_nubmber_and_reference_number_in_description
create_payable_invoice(number: '2222', total: 10, reference_no: '1234567')

View file

@ -7,19 +7,12 @@ class ReferenceNoTest < ActiveSupport::TestCase
end
def test_generated_reference_number_conforms_to_format
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/reference_number_generator").
with(
body: "{\"initiator\":\"registry\"}",
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: {})
if Feature.billing_system_integrated?
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/reference_number_generator")
.to_return(status: 200, body: "{\"reference_number\":\"12332\"}", headers: {})
reference_no = Billing::ReferenceNo.generate
assert_match Billing::ReferenceNo::REGEXP, reference_no
end
end
end

View file

@ -5,6 +5,7 @@ class InvoiceTest < ActiveSupport::TestCase
setup do
@invoice = invoices(:one)
Spy.on_instance_method(EisBilling::BaseController, :authorized).and_return(true)
end
def test_fixture_is_valid
@ -117,6 +118,7 @@ class InvoiceTest < ActiveSupport::TestCase
end
def test_creates_invoice_with_bank_transaction_total
if Feature.billing_system_integrated?
registrar = registrars(:bestnames)
transaction = bank_transactions(:one).dup
transaction.reference_no = registrar.reference_no
@ -127,21 +129,19 @@ class InvoiceTest < ActiveSupport::TestCase
.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")
.to_return(status: 200, body: "", headers: {})
.to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
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: {})
invoice = Invoice.create_from_transaction!(transaction)
assert_equal 250, 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").
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
@ -150,32 +150,24 @@ class InvoiceTest < ActiveSupport::TestCase
invoice_n = Invoice.order(number: :desc).last.number
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
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 + 5}\"}", headers: {})
transaction.sum = 0.99
invoice = Invoice.create_from_transaction!(transaction)
assert_equal 0.99, invoice.total
end
end
def test_emails_invoice_after_creating_topup_invoice
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").
with(
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}",
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(: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: {})
registrar = registrars(:bestnames)
@ -183,7 +175,6 @@ class InvoiceTest < ActiveSupport::TestCase
transaction.reference_no = registrar.reference_no
transaction.sum = 250
invoice_n = Invoice.order(number: :desc).last.number
response = OpenStruct.new(body: "{\"invoice_number\":\"#{invoice_n + 3}\"}")
Spy.on(EisBilling::GetInvoiceNumber, :send_invoice).and_return(response)
@ -192,3 +183,4 @@ class InvoiceTest < ActiveSupport::TestCase
end
end
end
end

View file

@ -6,6 +6,7 @@ class RegistrarTest < ActiveJob::TestCase
@original_default_language = Setting.default_language
@original_days_to_keep_invoices_active = Setting.days_to_keep_invoices_active
@old_validation_type = Truemail.configure.default_validation_type
Spy.on_instance_method(EisBilling::BaseController, :authorized).and_return(true)
end
teardown do
@ -144,30 +145,20 @@ class RegistrarTest < ActiveJob::TestCase
end
def test_issues_new_invoice
if Feature.billing_system_integrated?
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
with(
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}",
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: {})
to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
invoice_n = Invoice.order(number: :desc).last.number
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
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(: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: {})
travel_to Time.zone.parse('2010-07-05')
Setting.days_to_keep_invoices_active = 10
@ -176,39 +167,34 @@ class RegistrarTest < ActiveJob::TestCase
assert_equal Date.parse('2010-07-05'), invoice.issue_date
assert_equal Date.parse('2010-07-15'), invoice.due_date
end
end
def test_issues_e_invoice_along_with_invoice
if Feature.billing_system_integrated?
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
with(
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}",
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: {})
to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
invoice_n = Invoice.order(number: :desc).last.number
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
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(: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: {})
end
EInvoice::Providers::TestProvider.deliveries.clear
perform_enqueued_jobs do
@registrar.issue_prepayment_invoice(100)
end
unless Feature.billing_system_integrated?
assert_equal 1, EInvoice::Providers::TestProvider.deliveries.count
end
end
def test_invalid_without_address_street
registrar = valid_registrar

View file

@ -6,6 +6,7 @@ class AdminAreaBankStatementTest < ApplicationSystemTestCase
travel_to Time.zone.parse('2010-07-05 00:30:00')
@invoice = invoices(:one)
Spy.on_instance_method(EisBilling::BaseController, :authorized).and_return(true)
end
def test_update_bank_statement
@ -54,12 +55,19 @@ class AdminAreaBankStatementTest < ApplicationSystemTestCase
end
def test_can_bind_statement_transactions
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_number_generator")
.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")
.to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
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: {})
registrar.issue_prepayment_invoice(500)
@ -80,6 +88,7 @@ class AdminAreaBankStatementTest < ApplicationSystemTestCase
assert_text 'Invoices were fully binded'
end
end
def create_bank_statement
visit admin_bank_statements_path

View file

@ -14,16 +14,8 @@ class AdminRegistrarsSystemTest < ApplicationSystemTestCase
end
def test_creates_new_registrar
if Feature.billing_system_integrated?
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/reference_number_generator").
with(
body: "{\"initiator\":\"registry\"}",
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')
@ -46,6 +38,7 @@ class AdminRegistrarsSystemTest < ApplicationSystemTestCase
assert_text 'Registrar has been successfully created'
assert_text 'Acme Ltd'
end
end
def test_updates_registrar
assert_not_equal 'New name', @registrar.name

View file

@ -11,31 +11,19 @@ class AddDepositsTest < ApplicationSystemTestCase
end
def test_should_send_request_for_creating_invoice_to_eis_system
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").
with(
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}",
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").
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: {})
# eis_response = OpenStruct.new(body: "{\"payment_link\":\"http://link.test\"}")
# Spy.on_instance_method(EisBilling::AddDeposits, :send_invoice).and_return(eis_response)
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: {})
visit new_registrar_deposit_url
fill_in 'Amount', with: '100.0'
@ -44,3 +32,4 @@ class AddDepositsTest < ApplicationSystemTestCase
assert_text 'Everypay link'
end
end
end

View file

@ -7,6 +7,7 @@ class BalanceTopUpTest < ApplicationSystemTestCase
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::BaseController, :authorized).and_return(true)
end
teardown do
@ -14,17 +15,17 @@ class BalanceTopUpTest < ApplicationSystemTestCase
end
def test_creates_new_invoice
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_number_generator").
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(: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: {})
Setting.registry_vat_prc = 0.1
visit registrar_invoices_url
@ -42,3 +43,4 @@ class BalanceTopUpTest < ApplicationSystemTestCase
assert_text 'Please pay the following invoice'
end
end
end

View file

@ -27,17 +27,17 @@ class NewInvoicePaymentTest < ApplicationSystemTestCase
end
def test_create_new_SEB_payment
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_number_generator").
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(: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: {})
create_invoice_and_visit_its_page
click_link_or_button 'seb'
form = page.find('form')
@ -45,19 +45,20 @@ class NewInvoicePaymentTest < ApplicationSystemTestCase
assert_equal('post', form['method'])
assert_equal('240.00', form.find_by_id('VK_AMOUNT', visible: false).value)
end
end
def test_create_new_Every_Pay_payment
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_number_generator").
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(: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: {})
create_invoice_and_visit_its_page
click_link_or_button 'every_pay'
expected_hmac_fields = 'account_id,amount,api_username,callback_url,' +
@ -70,3 +71,4 @@ class NewInvoicePaymentTest < ApplicationSystemTestCase
assert_equal('240.00', form.find_by_id('amount', visible: false).value)
end
end
end

View file

@ -17,17 +17,17 @@ class NewInvoiceTest < ApplicationSystemTestCase
end
def test_create_new_invoice_with_positive_amount
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_number_generator").
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(: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: {})
visit registrar_invoices_path
click_link_or_button 'Add deposit'
fill_in 'Amount', with: '200.00'
@ -42,19 +42,20 @@ class NewInvoiceTest < ApplicationSystemTestCase
assert_text 'Subtotal 200,00 €'
assert_text 'Pay invoice'
end
end
def test_create_new_invoice_with_comma_in_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_number_generator").
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(: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: {})
visit registrar_invoices_path
click_link_or_button 'Add deposit'
fill_in 'Amount', with: '200,00'
@ -69,6 +70,7 @@ class NewInvoiceTest < ApplicationSystemTestCase
assert_text 'Subtotal 200,00 €'
assert_text 'Pay invoice'
end
end
def test_create_new_invoice_fails_when_amount_is_0
visit registrar_invoices_path

View file

@ -77,29 +77,22 @@ class ProcessPaymentsTaskTest < ActiveJob::TestCase
end
def test_if_invoice_is_overdue_than_48_hours
if Feature.billing_system_integrated?
invoice_n = Invoice.order(number: :desc).last.number
Spy.on_instance_method(SendEInvoiceTwoJob, :perform_now).and_return(true)
stub_request(:post, "http://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
to_return(status: 200, body: "", headers: {})
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/invoice_generator/invoice_number_generator").
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").
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: {})
to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
assert_not @invoice.paid?
@ -113,6 +106,7 @@ class ProcessPaymentsTaskTest < ActiveJob::TestCase
end
end
end
end
def test_doubles_are_valid
assert Lhv::ConnectApi.method_defined?(:credit_debit_notification_messages)
@ -167,31 +161,23 @@ class ProcessPaymentsTaskTest < ActiveJob::TestCase
assert payment_order.failed?
end
def test_credits_registrar_account_without_invoice_beforehand
def test_credits_registrar_athout_invoice_beforehand
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_number_generator").
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: {})
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}")
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
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: "{\"everypay_link\":\"http://link.test\"}", headers: {})
Spy.on_instance_method(SendEInvoiceTwoJob, :perform_now).and_return(true)
stub_request(:post, "http://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
to_return(status: 200, body: "", headers: {})
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: {})
registrar = registrars(:bestnames)
assert_changes -> { registrar.accounts.first.balance } do
@ -202,6 +188,7 @@ class ProcessPaymentsTaskTest < ActiveJob::TestCase
run_task
end
end
end
def test_topup_creates_invoice_with_total_of_transactioned_amount
registrar = registrars(:bestnames)
@ -211,29 +198,19 @@ class ProcessPaymentsTaskTest < ActiveJob::TestCase
end
def test_topup_creates_invoice_and_send_it_as_paid
if Feature.billing_system_integrated?
stub_request(:post, "http://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
to_return(status: 200, body: "", headers: {})
invoice_n = Invoice.order(number: :desc).last.number
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
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").
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: {})
to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
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: {})
registrar = registrars(:bestnames)
@invoice.payment_orders.destroy_all
@ -255,6 +232,7 @@ class ProcessPaymentsTaskTest < ActiveJob::TestCase
assert_equal 0.1, registrar.invoices.last.total
end
end
def test_output
assert_output "Transactions processed: 1\n" do

View file

@ -5,6 +5,7 @@ class ReloadBalanceTaskTest < ActiveSupport::TestCase
setup do
@registrar = registrars(:bestnames)
Spy.on_instance_method(EisBilling::BaseController, :authorized).and_return(true)
end
def test_issues_invoice_when_auto_reload_is_enabled_and_threshold_reached
@ -20,29 +21,20 @@ class ReloadBalanceTaskTest < ActiveSupport::TestCase
end
def test_issues_invoice_when_auto_reload_is_enabled_and_threshold_reached
if Feature.billing_system_integrated?
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
with(
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}",
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: {})
to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
invoice_n = Invoice.order(number: :desc).last.number
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
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(: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: {})
reload_amount = 100
registrar = registrar_with_auto_reload_enabled_and_threshold_reached(reload_amount)
@ -53,6 +45,7 @@ class ReloadBalanceTaskTest < ActiveSupport::TestCase
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
registrar = registrar_with_auto_reload_enabled_and_threshold_not_reached
@ -73,29 +66,20 @@ class ReloadBalanceTaskTest < ActiveSupport::TestCase
end
def test_marks_registrar_as_pending_balance_reload
if Feature.billing_system_integrated?
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
with(
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}",
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: {})
to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
invoice_n = Invoice.order(number: :desc).last.number
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
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(: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: {})
registrar = registrar_with_auto_reload_enabled_and_threshold_reached
capture_io { run_task }
@ -103,31 +87,23 @@ class ReloadBalanceTaskTest < ActiveSupport::TestCase
assert registrar.settings['balance_auto_reload']['pending']
end
end
def test_output
if Feature.billing_system_integrated?
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
with(
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}",
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: {})
to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
invoice_n = Invoice.order(number: :desc).last.number
stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
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(: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: {})
reload_amount = 100
registrar = registrar_with_auto_reload_enabled_and_threshold_reached(reload_amount)
assert_equal 'Best Names', registrar.name
@ -136,6 +112,7 @@ class ReloadBalanceTaskTest < ActiveSupport::TestCase
run_task
end
end
end
private