From 9b6b8a5e2fc672d88a80ce5b2ae1bc79d1e6dc68 Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Wed, 26 Jan 2022 13:24:58 +0200 Subject: [PATCH] added link generator into admin part --- app/controllers/admin/invoices_controller.rb | 10 ++++++ test/system/admin_area/bank_statement_test.rb | 11 +++++++ .../registrar_area/add_deposits_test.rb | 11 +++++++ .../billing/balance_top_up_test.rb | 11 +++++++ .../invoices/new_invoice_payment_test.rb | 22 +++++++++++++ .../registrar_area/invoices/new_test.rb | 26 +++++++++++++-- test/system/registrar_area/invoices_test.rb | 13 ++++++++ test/tasks/registrars/reload_balance_test.rb | 33 +++++++++++++++++++ 8 files changed, 135 insertions(+), 2 deletions(-) diff --git a/app/controllers/admin/invoices_controller.rb b/app/controllers/admin/invoices_controller.rb index 223257605..8410b6ca7 100644 --- a/app/controllers/admin/invoices_controller.rb +++ b/app/controllers/admin/invoices_controller.rb @@ -13,6 +13,7 @@ module Admin if @invoice&.persisted? flash[:notice] = t(:record_created) + send_invoice_data_to_billing_system redirect_to [:admin, @invoice] else flash.now[:alert] = t(:failed_to_create_record) @@ -100,5 +101,14 @@ module Admin invoices.where(account_activities: { created_at: date_from..date_until }) end + + def send_invoice_data_to_billing_system + add_invoice_instance = EisBilling::AddDeposits.new(@invoice) + result = add_invoice_instance.send_invoice + + link = JSON.parse(result.body)['everypay_link'] + + @invoice.update(payment_link: link) + end end end diff --git a/test/system/admin_area/bank_statement_test.rb b/test/system/admin_area/bank_statement_test.rb index 1405081e2..4f17862ed 100644 --- a/test/system/admin_area/bank_statement_test.rb +++ b/test/system/admin_area/bank_statement_test.rb @@ -54,6 +54,17 @@ class AdminAreaBankStatementTest < ApplicationSystemTestCase end def test_can_bind_statement_transactions + 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: {}) registrar = registrars(:bestnames) registrar.issue_prepayment_invoice(500) invoice = registrar.invoices.last diff --git a/test/system/registrar_area/add_deposits_test.rb b/test/system/registrar_area/add_deposits_test.rb index 2d12e63ad..ce516f98f 100644 --- a/test/system/registrar_area/add_deposits_test.rb +++ b/test/system/registrar_area/add_deposits_test.rb @@ -11,6 +11,17 @@ class AddDepositsTest < ApplicationSystemTestCase end def test_should_send_request_for_creating_invoice_to_eis_system + 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: {}) eis_response = OpenStruct.new(body: "{\"payment_link\":\"http://link.test\"}") Spy.on_instance_method(EisBilling::AddDeposits, :send_invoice).and_return(eis_response) 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 0c2129d21..5c7526682 100644 --- a/test/system/registrar_area/billing/balance_top_up_test.rb +++ b/test/system/registrar_area/billing/balance_top_up_test.rb @@ -14,6 +14,17 @@ class BalanceTopUpTest < ApplicationSystemTestCase end def test_creates_new_invoice + 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: {}) Setting.registry_vat_prc = 0.1 visit registrar_invoices_url 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 a162a6b56..452a9612b 100644 --- a/test/system/registrar_area/invoices/new_invoice_payment_test.rb +++ b/test/system/registrar_area/invoices/new_invoice_payment_test.rb @@ -27,6 +27,17 @@ class NewInvoicePaymentTest < ApplicationSystemTestCase end def test_create_new_SEB_payment + 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_invoice_and_visit_its_page click_link_or_button 'seb' form = page.find('form') @@ -36,6 +47,17 @@ class NewInvoicePaymentTest < ApplicationSystemTestCase end def test_create_new_Every_Pay_payment + 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_invoice_and_visit_its_page click_link_or_button 'every_pay' expected_hmac_fields = 'account_id,amount,api_username,callback_url,' + diff --git a/test/system/registrar_area/invoices/new_test.rb b/test/system/registrar_area/invoices/new_test.rb index 664d0d3c9..23dce68fe 100644 --- a/test/system/registrar_area/invoices/new_test.rb +++ b/test/system/registrar_area/invoices/new_test.rb @@ -17,6 +17,17 @@ class NewInvoiceTest < ApplicationSystemTestCase end def test_create_new_invoice_with_positive_amount + 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: {}) visit registrar_invoices_path click_link_or_button 'Add deposit' fill_in 'Amount', with: '200.00' @@ -27,12 +38,23 @@ class NewInvoiceTest < ApplicationSystemTestCase end assert_text 'Please pay the following invoice' - assert_text 'Invoice no. 131050' + assert_text "Invoice no. #{invoice_n + 3}" assert_text 'Subtotal 200,00 €' assert_text 'Pay invoice' end def test_create_new_invoice_with_comma_in_number + 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: {}) visit registrar_invoices_path click_link_or_button 'Add deposit' fill_in 'Amount', with: '200,00' @@ -43,7 +65,7 @@ class NewInvoiceTest < ApplicationSystemTestCase end assert_text 'Please pay the following invoice' - assert_text 'Invoice no. 131050' + assert_text "Invoice no. #{invoice_n + 3}" assert_text 'Subtotal 200,00 €' assert_text 'Pay invoice' end diff --git a/test/system/registrar_area/invoices_test.rb b/test/system/registrar_area/invoices_test.rb index 250f00913..09af232b5 100644 --- a/test/system/registrar_area/invoices_test.rb +++ b/test/system/registrar_area/invoices_test.rb @@ -44,6 +44,19 @@ class RegistrarAreaInvoicesTest < ApplicationSystemTestCase end 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::AddDeposits, :send_invoice).and_return(eis_response) + 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: {}) invoice = invoices(:unpaid) visit registrar_invoice_url(invoice) diff --git a/test/tasks/registrars/reload_balance_test.rb b/test/tasks/registrars/reload_balance_test.rb index 0c14f95c9..296574a21 100644 --- a/test/tasks/registrars/reload_balance_test.rb +++ b/test/tasks/registrars/reload_balance_test.rb @@ -20,6 +20,17 @@ class ReloadBalanceTaskTest < ActiveSupport::TestCase end def test_issues_invoice_when_auto_reload_is_enabled_and_threshold_reached + 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: {}) reload_amount = 100 registrar = registrar_with_auto_reload_enabled_and_threshold_reached(reload_amount) @@ -50,6 +61,17 @@ class ReloadBalanceTaskTest < ActiveSupport::TestCase end def test_marks_registrar_as_pending_balance_reload + 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: {}) registrar = registrar_with_auto_reload_enabled_and_threshold_reached capture_io { run_task } @@ -59,6 +81,17 @@ class ReloadBalanceTaskTest < ActiveSupport::TestCase end def test_output + 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: {}) reload_amount = 100 registrar = registrar_with_auto_reload_enabled_and_threshold_reached(reload_amount) assert_equal 'Best Names', registrar.name