Skip to content

Commit

Permalink
Improve tests
Browse files Browse the repository at this point in the history
- Remove unnecessary fixtures
- Remove teardown steps
- Improve readability
  • Loading branch information
Artur Beljajev committed Jun 20, 2019
1 parent 07b23ca commit 6745226
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 58 deletions.
7 changes: 2 additions & 5 deletions test/fixtures/bank_transactions.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
one:
sum: 1
currency: EUR

for_payments_test:
description: "Order nr. 1"
currency: "EUR"
iban: "1234"
description: Order nr. 1
iban: US75512108001245126199
19 changes: 3 additions & 16 deletions test/fixtures/invoices.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,11 @@ one:
issue_date: <%= Date.parse '2010-07-05' %>
due_date: <%= Date.parse '2010-07-06' %>
currency: EUR
seller_name: John Doe
seller_iban: 1234
seller_name: Seller Ltd
seller_iban: US75512108001245126199
buyer: bestnames
buyer_name: Jane Doe
vat_rate: 0.1
total: 16.50
reference_no: 13
number: 1

for_payments_test:
number: 1
issue_date: <%= Date.parse '2010-07-05' %>
due_date: <%= Date.parse '2010-07-06' %>
currency: EUR
seller_name: John Doe
seller_iban: 1234
buyer: bestnames
buyer_name: Jane Doe
vat_rate: 0.1
reference_no: 13
total: 12.00
number: 1
13 changes: 2 additions & 11 deletions test/models/payment_orders/bank_link_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,15 @@ class BankLinkTest < ActiveSupport::TestCase
def setup
super

@invoice = invoices(:for_payments_test)
invoice_item = invoice_items(:one)

@invoice.items << invoice_item
@invoice.items << invoice_item
@invoice = invoices(:one)
@invoice.update!(total: 12)

travel_to '2018-04-01 00:30 +0300'
create_new_bank_link
create_completed_bank_link
create_cancelled_bank_link
end

def teardown
super

travel_back
end

def create_completed_bank_link
params = {
'VK_SERVICE': '1111',
Expand Down
13 changes: 2 additions & 11 deletions test/models/payment_orders/every_pay_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ class EveryPayTest < ActiveSupport::TestCase
def setup
super

@invoice = invoices(:for_payments_test)
invoice_item = invoice_items(:one)

@invoice.items << invoice_item
@invoice.items << invoice_item
@invoice = invoices(:one)
@invoice.update!(total: 12)

params = {
response:
Expand Down Expand Up @@ -41,12 +38,6 @@ def setup
travel_to Time.zone.parse('2018-04-01 00:30:00 +0000')
end

def teardown
super

travel_back
end

def test_form_fields
expected_fields = {
api_username: 'api_user',
Expand Down
38 changes: 24 additions & 14 deletions test/system/registrar_area/invoices/payment_callback_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,30 @@ def setup
sign_in @user
end

def create_invoice_with_items
@invoice = invoices(:for_payments_test)
invoice_item = invoice_items(:one)
def test_every_pay_callback_returns_status_200
invoice = payable_invoice
assert_matching_bank_transaction_exists(invoice)

request_params = every_pay_request_params.merge(invoice_id: invoice.id)
post "/registrar/pay/callback/every_pay", request_params

assert_response :ok
end

private

@invoice.items << invoice_item
@invoice.items << invoice_item
@user.registrar.invoices << @invoice
def payable_invoice
invoice = invoices(:one)
invoice.update!(account_activity: nil)
invoice
end

def assert_matching_bank_transaction_exists(invoice)
assert BankTransaction.find_by(
description: invoice.order,
currency: invoice.currency,
iban: invoice.seller_iban
), 'Matching bank transaction should exist'
end

def every_pay_request_params
Expand All @@ -39,11 +56,4 @@ def every_pay_request_params
payment_method: "every_pay"
}
end

def test_every_pay_callback_returns_status_200
create_invoice_with_items
request_params = every_pay_request_params.merge(invoice_id: @invoice.id)
post "/registrar/pay/callback/every_pay", request_params
assert_equal(200, response.status)
end
end
end
2 changes: 1 addition & 1 deletion test/system/registrar_area/invoices/payment_return_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def setup
end

def create_invoice_with_items
@invoice = invoices(:for_payments_test)
@invoice = invoices(:one)
invoice_item = invoice_items(:one)

@invoice.items << invoice_item
Expand Down

0 comments on commit 6745226

Please sign in to comment.