Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegPhenomenon committed Sep 23, 2024
1 parent 1179674 commit 9d18f76
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 84 deletions.
4 changes: 4 additions & 0 deletions test/jobs/update_whois_record_job_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
require 'test_helper'
require 'rake'

class SendEInvoiceJobTest < ActiveJob::TestCase
setup do
Rails.application.load_tasks
end

def test_job_is_updating_domains
domain_names = Domain.find_in_batches.first.map(&:name)
Expand Down
4 changes: 2 additions & 2 deletions test/models/contact/company_register_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def object.simple_data(registration_number:)
object
end

assert_equal 'registered', @acme_ltd.return_company_status
assert_equal Contact::CompanyRegister::REGISTERED.downcase, @acme_ltd.return_company_status.downcase

CompanyRegister::Client.define_singleton_method(:new, original_new_method)
end
Expand All @@ -36,7 +36,7 @@ def test_only_org_can_be_checked
def test_should_return_liquided_value
@company_register_stub.stub :simple_data, [Company.new('1234567', 'ACME Ltd', 'L')] do
@acme_ltd.stub :company_register, @company_register_stub do
assert_equal 'liquidated', @acme_ltd.return_company_status
assert_equal Contact::CompanyRegister::LIQUIDATED.downcase, @acme_ltd.return_company_status.downcase
end
end
end
Expand Down
1 change: 1 addition & 0 deletions test/tasks/check_force_delete_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class CheckForceDeleteTaskTest < ActiveSupport::TestCase
include ActiveJob::TestHelper

def setup
Rails.application.load_tasks
@contact = contacts(:john)
@invalid_contact = contacts(:invalid_email)
end
Expand Down
6 changes: 3 additions & 3 deletions test/tasks/company_status_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ def collect_company_data(open_data_file_path)
collect_company_data_method.call(open_data_file_path)
end
end



# Выполняем задачу
silence_stream(STDOUT) { @task.execute }

@task.execute
# Проверяем, что опции установлены корректно
assert_equal 'tmp/ettevotja_rekvisiidid__lihtandmed.csv', options[:open_data_file_path]
assert_equal 'tmp/missing_companies_in_business_registry.csv', options[:missing_companies_output_path]
Expand Down
1 change: 1 addition & 0 deletions test/tasks/contacts/archive_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'test_helper'
require 'rake'

class ArchiveContactsTaskTest < ActiveSupport::TestCase
def test_archives_inactive_contacts
Expand Down
2 changes: 2 additions & 0 deletions test/tasks/epp/clear_expired_sessions_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
require 'test_helper'
require 'rake'

class EppClearExpiredSessionsTaskTest < ActiveSupport::TestCase
setup do
Rails.application.load_tasks
@original_session_timeout = EppSession.timeout
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
require 'test_helper'
require 'rake'

class ProcessPaymentsTaskTest < ActiveJob::TestCase
setup do
Rake::Task['invoices:process_payments'].reenable

@payment_amount = payment_amount = 0.1
@payment_currency = payment_currency = 'EUR'
@payment_date = payment_date = Date.parse('2010-07-05')
@payment_reference_number = payment_reference_number = '13'
@payment_description = payment_description = @invoice_number = '1234'
beneficiary_iban = 'GB33BUKB20201555555555'
@beneficiary_iban = 'GB33BUKB20201555555555'

@invoice = create_payable_invoice(number: @invoice_number,
total: payment_amount,
Expand All @@ -19,47 +22,16 @@ class ProcessPaymentsTaskTest < ActiveJob::TestCase
response_message = {
message: 'got it'
}
stub_request(:post, 'https://eis_billing_system:3000/api/v1/invoice_generator/invoice_status')
.to_return(status: 200, body: response_message.to_json, headers: {})

Setting.registry_iban = beneficiary_iban

Lhv::ConnectApi.class_eval do
define_method :credit_debit_notification_messages do
transaction = OpenStruct.new(amount: payment_amount,
currency: payment_currency,
date: payment_date,
payment_reference_number: payment_reference_number,
payment_description: payment_description)
message = OpenStruct.new(bank_account_iban: beneficiary_iban,
credit_transactions: [transaction])
[message]
end
end
Setting.registry_iban = @beneficiary_iban
end

def test_not_raises_error_if_bad_reference
@payment_description = 'some weird description 252923'
beneficiary_iban = 'GB33BUKB20201555555555'

Lhv::ConnectApi.class_eval do
define_method :credit_debit_notification_messages do
transaction = OpenStruct.new(amount: @payment_amount,
currency: @payment_currency,
date: @payment_date,
payment_reference_number: @payment_reference_number,
payment_description: @payment_description)
message = OpenStruct.new(bank_account_iban: beneficiary_iban,
credit_transactions: [transaction])
[message]
end
end

assert_no_difference 'AccountActivity.count' do
assert_no_difference 'Invoice.count' do
assert_no_difference -> {@account.balance} do
assert_nothing_raised do
capture_io { run_task }
capture_io { run_task(bad_reference: true) }
end
end
end
Expand All @@ -84,22 +56,6 @@ def test_cannot_create_new_invoice_if_transaction_binded_to_paid_invoice
end

def test_if_invoice_is_overdue_than_48_hours
invoice_n = Invoice.order(number: :desc).last.number

Spy.on_instance_method(SendEInvoiceJob, :perform_now).and_return(true)

stub_request(:post, 'https://eis_billing_system:3000/api/v1/e_invoice/e_invoice')
.to_return(status: 200, body: '', headers: {})

stub_request(:put, 'https://registry:3000/eis_billing/e_invoice_response')
.to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})

stub_request(:post, 'https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator')
.to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})

stub_request(:post, 'https://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator')
.to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})

assert_not @invoice.paid?

@account_activity.update(activity_type: 'add_credit', bank_transaction: nil,
Expand Down Expand Up @@ -168,23 +124,6 @@ def test_attaches_failed_payment_order_to_invoice
end

def test_credits_registrar_athout_invoice_beforehand
invoice_n = Invoice.order(number: :desc).last.number
stub_request(:post, 'https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator')
.to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}")

stub_request(:post, 'https://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator')
.to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})

Spy.on_instance_method(SendEInvoiceJob, :perform_now).and_return(true)

stub_request(:post, 'https://eis_billing_system:3000/api/v1/e_invoice/e_invoice')
.to_return(status: 200, body: '', headers: {})

stub_request(:put, 'https://registry:3000/eis_billing/e_invoice_response')
.to_return(status: 200,
body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}",
headers: {})

registrar = registrars(:bestnames)

assert_changes -> { registrar.accounts.first.balance } do
Expand All @@ -204,16 +143,6 @@ def test_topup_creates_invoice_with_total_of_transactioned_amount
end

def test_topup_creates_invoice_and_send_it_as_paid
stub_request(:post, 'https://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator')
.to_return(status: 200, body: { everypay_link: 'http://link.test' }.to_json, headers: {})

invoice_n = Invoice.order(number: :desc).last.number
stub_request(:post, 'https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator')
.to_return(status: 200, body: { invoice_number: (invoice_n + 3).to_s }.to_json, headers: {})

stub_request(:post, 'https://eis_billing_system:3000/api/v1/e_invoice/e_invoice')
.to_return(status: 200, body: '', headers: {})

registrar = registrars(:bestnames)
@invoice.payment_orders.destroy_all
@invoice.destroy
Expand Down Expand Up @@ -248,8 +177,35 @@ def test_parses_keystore_properly

private

def run_task
Rake::Task['invoices:process_payments'].execute
def run_task(bad_reference: false)
response_message = {
message: 'got it'
}
invoice_number = Invoice.order(number: :desc).last.number
stub_request(:post, 'https://eis_billing_system:3000/api/v1/invoice_generator/invoice_status')
.to_return(status: 200, body: response_message.to_json, headers: {})
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_number + 10}\"}", headers: {})
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
stub_request(:post, "https://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
to_return(status: 200, body: "", headers: {})

Lhv::ConnectApi.class_eval do
define_method :credit_debit_notification_messages do
transaction = OpenStruct.new(amount: 0.1,
currency: 'EUR',
date: Date.parse('2010-07-05'),
payment_reference_number: bad_reference ? 'some weird description 252923' : '13',
payment_description: '1234')
message = OpenStruct.new(bank_account_iban: 'GB33BUKB20201555555555',
credit_transactions: [transaction])
[message]
end
end

Rake::Task['invoices:process_payments'].reenable
Rake::Task['invoices:process_payments'].invoke
end

def create_payable_invoice(attributes = {})
Expand Down
2 changes: 2 additions & 0 deletions test/tasks/registrars/reload_balance_test.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
require 'test_helper'
require 'rake'

class ReloadBalanceTaskTest < ActiveSupport::TestCase
include ActionView::Helpers::NumberHelper

setup do
Rails.application.load_tasks
@registrar = registrars(:bestnames)
Spy.on_instance_method(EisBilling::BaseController, :authorized).and_return(true)
end
Expand Down

0 comments on commit 9d18f76

Please sign in to comment.