mirror of
https://github.com/internetee/registry.git
synced 2025-07-28 05:26:17 +02:00
implemented method which get invoice number from billins side and updated tests
This commit is contained in:
parent
390d693b13
commit
9f4942e522
8 changed files with 191 additions and 10 deletions
|
@ -24,6 +24,17 @@ class AdminAreaInvoicesIntegrationTest < ApplicationIntegrationTest
|
|||
end
|
||||
|
||||
def test_create_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: {})
|
||||
visit new_admin_invoice_path
|
||||
|
||||
assert_text 'Create new invoice'
|
||||
|
|
|
@ -16,6 +16,17 @@ class BankTransactionTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
def test_binds_if_this_sum_invoice_already_present
|
||||
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
|
||||
another_invoice.save(validate: false)
|
||||
|
@ -40,6 +51,17 @@ class BankTransactionTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
def test_binds_if_this_sum_cancelled_invoice_already_present
|
||||
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
|
||||
another_invoice.save(validate: false)
|
||||
|
@ -61,6 +83,17 @@ class BankTransactionTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
def test_marks_the_first_one_as_paid_if_same_sum
|
||||
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
|
||||
another_invoice.save(validate: false)
|
||||
|
|
|
@ -79,6 +79,10 @@ class InvoiceTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
def test_buyer_vat_no_is_taken_from_registrar_by_default
|
||||
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)
|
||||
|
||||
registrar = registrars(:bestnames)
|
||||
registrar.vat_no = 'US1234'
|
||||
invoice = @invoice.dup
|
||||
|
@ -118,13 +122,49 @@ class InvoiceTest < ActiveSupport::TestCase
|
|||
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/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 = 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
|
||||
invoice = Invoice.create_from_transaction!(transaction)
|
||||
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").
|
||||
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
|
||||
|
@ -136,6 +176,10 @@ 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)
|
||||
|
||||
assert_emails 1 do
|
||||
Invoice.create_from_transaction!(transaction)
|
||||
end
|
||||
|
|
|
@ -144,6 +144,18 @@ class RegistrarTest < ActiveJob::TestCase
|
|||
end
|
||||
|
||||
def test_issues_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: {})
|
||||
|
||||
travel_to Time.zone.parse('2010-07-05')
|
||||
Setting.days_to_keep_invoices_active = 10
|
||||
|
||||
|
@ -154,6 +166,17 @@ class RegistrarTest < ActiveJob::TestCase
|
|||
end
|
||||
|
||||
def test_issues_e_invoice_along_with_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: {})
|
||||
EInvoice::Providers::TestProvider.deliveries.clear
|
||||
|
||||
perform_enqueued_jobs do
|
||||
|
|
|
@ -77,6 +77,17 @@ class ProcessPaymentsTaskTest < ActiveJob::TestCase
|
|||
end
|
||||
|
||||
def test_if_invoice_is_overdue_than_48_hours
|
||||
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: {})
|
||||
assert_not @invoice.paid?
|
||||
|
||||
@account_activity.update(activity_type: "add_credit", bank_transaction: nil, created_at: Time.zone.today - 3.days, creator_str: 'AdminUser')
|
||||
|
@ -144,6 +155,17 @@ class ProcessPaymentsTaskTest < ActiveJob::TestCase
|
|||
end
|
||||
|
||||
def test_credits_registrar_account_without_invoice_beforehand
|
||||
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)
|
||||
|
||||
assert_changes -> { registrar.accounts.first.balance } do
|
||||
|
@ -163,6 +185,17 @@ class ProcessPaymentsTaskTest < ActiveJob::TestCase
|
|||
end
|
||||
|
||||
def test_topup_creates_invoice_and_send_it_as_paid
|
||||
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)
|
||||
@invoice.payment_orders.destroy_all
|
||||
@invoice.destroy
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue