From f22f16d7209bd1be278181f7d15a504c69d3c8a0 Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Mon, 17 Jan 2022 11:55:43 +0200 Subject: [PATCH] added tests --- app/services/eis_billing/base.rb | 2 +- config/application.yml.sample | 1 + .../registrar_area/add_deposits_test.rb | 25 +++++++++++ .../billing/balance_top_up_test.rb | 5 +++ .../invoices/new_invoice_payment_test.rb | 3 ++ .../registrar_area/invoices/new_test.rb | 4 ++ test/system/registrar_area/invoices_test.rb | 43 ++++++++++++++++++- 7 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 test/system/registrar_area/add_deposits_test.rb diff --git a/app/services/eis_billing/base.rb b/app/services/eis_billing/base.rb index 3b99cae4f..173adabbd 100644 --- a/app/services/eis_billing/base.rb +++ b/app/services/eis_billing/base.rb @@ -7,7 +7,7 @@ module EisBilling # irb(main):048:0> decrypted_back = crypt.decrypt_and_verify(encrypted_data) # => "PLEASE CREATE INVOICE" TOKEN = "Bearer WA9UvDmzR9UcE5rLqpWravPQtdS8eDMAIynzGdSOTw==--9ZShwwij3qmLeuMJ--NE96w2PnfpfyIuuNzDJTGw==".freeze - BASE_URL = "http://eis_billing_system:3000".freeze + BASE_URL = ENV['eis_billing_system_base_url'] protected diff --git a/config/application.yml.sample b/config/application.yml.sample index 02b230ff4..d39f3617c 100644 --- a/config/application.yml.sample +++ b/config/application.yml.sample @@ -235,3 +235,4 @@ registry_demo_accredited_users_url: 'http://registry.test/api/v1/accreditation_c a_and_aaaa_validation_timeout: '1' nameserver_validation_timeout: '1' +eis_billing_system_base_url: 'http://eis_billing_system:3000' diff --git a/test/system/registrar_area/add_deposits_test.rb b/test/system/registrar_area/add_deposits_test.rb new file mode 100644 index 000000000..9fd9c3062 --- /dev/null +++ b/test/system/registrar_area/add_deposits_test.rb @@ -0,0 +1,25 @@ +require 'application_system_test_case' + +class AddDepositsTest < ApplicationSystemTestCase + include ActionMailer::TestHelper + + setup do + sign_in users(:api_bestnames) + @invoice = invoices(:one) + + ActionMailer::Base.deliveries.clear + end + + def test_should_send_request_for_creating_invoice_to_eis_system + eis_response = OpenStruct.new(body: "{\"payment_link\":\"http://link.test\"}") + Spy.on_instance_method(EisBilling::GetInvoiceLink, :send_request).and_return(eis_response) + + Spy.on_instance_method(EisBilling::AddDeposits, :send_invoice).and_return(eis_response) + + visit new_registrar_deposit_url + fill_in 'Amount', with: '100.0' + click_button text: 'Add' + + assert_text 'Everypay link' + end +end diff --git a/test/system/registrar_area/billing/balance_top_up_test.rb b/test/system/registrar_area/billing/balance_top_up_test.rb index be378df97..83c093e73 100644 --- a/test/system/registrar_area/billing/balance_top_up_test.rb +++ b/test/system/registrar_area/billing/balance_top_up_test.rb @@ -4,6 +4,11 @@ class BalanceTopUpTest < ApplicationSystemTestCase setup do sign_in users(:api_bestnames) @original_registry_vat_rate = Setting.registry_vat_prc + + 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::GetInvoiceLink, :send_request).and_return(eis_response) + end teardown do diff --git a/test/system/registrar_area/invoices/new_invoice_payment_test.rb b/test/system/registrar_area/invoices/new_invoice_payment_test.rb index ea4b924fe..0b0a5c6e6 100644 --- a/test/system/registrar_area/invoices/new_invoice_payment_test.rb +++ b/test/system/registrar_area/invoices/new_invoice_payment_test.rb @@ -3,6 +3,9 @@ require 'application_system_test_case' class NewInvoicePaymentTest < ApplicationSystemTestCase def setup super + 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::GetInvoiceLink, :send_request).and_return(eis_response) @original_vat_prc = Setting.registry_vat_prc Setting.registry_vat_prc = 0.2 diff --git a/test/system/registrar_area/invoices/new_test.rb b/test/system/registrar_area/invoices/new_test.rb index 26ab34385..f56f6cb7d 100644 --- a/test/system/registrar_area/invoices/new_test.rb +++ b/test/system/registrar_area/invoices/new_test.rb @@ -6,6 +6,10 @@ class NewInvoiceTest < ApplicationSystemTestCase @user = users(:api_bestnames) sign_in @user + + 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::GetInvoiceLink, :send_request).and_return(eis_response) end def test_show_balance diff --git a/test/system/registrar_area/invoices_test.rb b/test/system/registrar_area/invoices_test.rb index e64204165..b6ed40924 100644 --- a/test/system/registrar_area/invoices_test.rb +++ b/test/system/registrar_area/invoices_test.rb @@ -8,9 +8,14 @@ class RegistrarAreaInvoicesTest < ApplicationSystemTestCase @invoice = invoices(:one) ActionMailer::Base.deliveries.clear + eis_response = OpenStruct.new(body: "{\"payment_link\":\"http://link.test\"}") + Spy.on_instance_method(EisBilling::AddDeposits, :send_invoice).and_return(eis_response) end def test_cancels_an_invoice + eis_response = OpenStruct.new(body: "{\"payment_link\":\"http://link.test\"}") + Spy.on_instance_method(EisBilling::GetInvoiceLink, :send_request).and_return(eis_response) + @invoice.account_activity = nil assert @invoice.cancellable? @@ -23,12 +28,18 @@ class RegistrarAreaInvoicesTest < ApplicationSystemTestCase end def test_invoice_delivery_form_is_pre_populated_with_billing_email_of_a_registrar + eis_response = OpenStruct.new(body: "{\"payment_link\":\"http://link.test\"}") + Spy.on_instance_method(EisBilling::GetInvoiceLink, :send_request).and_return(eis_response) + assert_equal 'billing@bestnames.test', @invoice.buyer.billing_email visit new_registrar_invoice_delivery_url(@invoice) assert_field 'Recipient', with: 'billing@bestnames.test' end def test_delivers_an_invoice + eis_response = OpenStruct.new(body: "{\"payment_link\":\"http://link.test\"}") + Spy.on_instance_method(EisBilling::GetInvoiceLink, :send_request).and_return(eis_response) + visit registrar_invoice_url(@invoice) click_on 'Send' fill_in 'Recipient', with: 'billing@registrar.test' @@ -40,4 +51,34 @@ class RegistrarAreaInvoicesTest < ApplicationSystemTestCase assert_current_path registrar_invoice_path(@invoice) assert_text 'Invoice has been sent' end -end \ No newline at end of file + + def test_if_invoice_unpaid_should_be_present_everypay_link + eis_response = OpenStruct.new(body: "{\"payment_link\":\"http://link.test\"}") + Spy.on_instance_method(EisBilling::GetInvoiceLink, :send_request).and_return(eis_response) + + invoice = invoices(:unpaid) + visit registrar_invoice_url(invoice) + + assert_text 'Everypay link' + end + + def test_if_invoice_unpaid_and_not_generated_link_comes_then_should_render_no_everypay_link + eis_response = OpenStruct.new(body: "{\"error\":\"Invoice not found\", \"status\":\"no_found\"}") + Spy.on_instance_method(EisBilling::GetInvoiceLink, :send_request).and_return(eis_response) + + invoice = invoices(:unpaid) + visit registrar_invoice_url(invoice) + + assert_text 'No everypay link' + end + + def test_if_invoice_aldready_paid_there_should_not_any_everypay_link + eis_response = OpenStruct.new(body: "{\"payment_link\":\"http://link.test\"}") + Spy.on_instance_method(EisBilling::GetInvoiceLink, :send_request).and_return(eis_response) + + visit registrar_invoice_url(@invoice) + + assert_no_text 'No everypay link' + assert_no_text 'Everypay link' + end +end