Cover EveryPay / BankLink payments with tests

This commit is contained in:
Karl Erik Õunapuu 2020-02-04 09:42:26 +02:00
parent b6469f3dfe
commit 6418924faf
7 changed files with 145 additions and 61 deletions

View file

@ -8,7 +8,7 @@ class BankLinkTest < ActiveSupport::TestCase
super
@invoice = invoices(:one)
@invoice.update!(total: 12)
@invoice.update!(account_activity: nil, total: 12)
travel_to '2018-04-01 00:30 +0300'
create_new_bank_link
@ -63,7 +63,6 @@ class BankLinkTest < ActiveSupport::TestCase
end
def create_new_bank_link
params = { return_url: 'return.url', response_url: 'response.url' }
@new_bank_link = PaymentOrder.new(type: 'PaymentOrders::Seb', invoice: @invoice)
@new_bank_link.return_url = 'return.url'
@new_bank_link.response_url = 'response.url'
@ -94,6 +93,20 @@ class BankLinkTest < ActiveSupport::TestCase
assert_equal(expected_response, @new_bank_link.form_fields)
end
def test_correct_channel_is_assigned
swed_link = PaymentOrder.create_with_type(type: 'swed', invoice: @invoice)
assert_equal swed_link.channel, 'Swed'
assert_equal swed_link.class.config_namespace_name, 'swed'
seb_link = PaymentOrder.create_with_type(type: 'seb', invoice: @invoice)
assert_equal seb_link.channel, 'Seb'
assert_equal seb_link.class.config_namespace_name, 'seb'
lhv_link = PaymentOrder.create_with_type(type: 'lhv', invoice: @invoice)
assert_equal lhv_link.channel, 'Lhv'
assert_equal lhv_link.class.config_namespace_name, 'lhv'
end
def test_valid_success_response_from_intermediary?
assert(@completed_bank_link.valid_response_from_intermediary?)
end
@ -107,21 +120,14 @@ class BankLinkTest < ActiveSupport::TestCase
refute(@cancelled_bank_link.settled_payment?)
end
def test_complete_transaction_calls_methods_on_transaction
mock_transaction = MiniTest::Mock.new
mock_transaction.expect(:sum= , '12.00', ['12.00'])
mock_transaction.expect(:bank_reference= , '1', ['1'])
mock_transaction.expect(:buyer_bank_code= , 'testvpos', ['testvpos'])
mock_transaction.expect(:buyer_iban= , '1234', ['1234'])
mock_transaction.expect(:paid_at= , Date.parse('2018-04-01 00:30:00 +0300'), [Time.parse('2018-04-01T00:30:00+0300')])
mock_transaction.expect(:buyer_name=, 'John Doe', ['John Doe'])
mock_transaction.expect(:save!, true)
mock_transaction.expect(:autobind_invoice, AccountActivity.new)
def test_successful_payment_creates_bank_transaction
@completed_bank_link.complete_transaction
BankTransaction.stub(:find_by, mock_transaction) do
@completed_bank_link.complete_transaction
end
transaction = BankTransaction.find_by(
sum: @completed_bank_link.response['VK_AMOUNT'],
buyer_name: @completed_bank_link.response['VK_SND_NAME']
)
mock_transaction.verify
assert transaction.present?
end
end

View file

@ -43,12 +43,33 @@ class PaymentOrdersTest < ActiveSupport::TestCase
end
end
def test_can_not_create_order_for_paid_invoice
invoice = invoices(:one)
payment_order = PaymentOrder.create_with_type(type: 'every_pay', invoice: invoice)
assert payment_order.invalid?
assert_includes payment_order.errors[:invoice], 'is already paid'
end
def test_order_without_channel_is_invalid
payment_order = PaymentOrder.new
assert payment_order.invalid?
assert_includes payment_order.errors[:type], 'is not supported'
end
def test_can_not_create_order_with_invalid_type
assert_raise NameError do
PaymentOrder.create_with_type(type: 'not_implemented', invoice: Invoice.new)
end
end
def test_supported_method_bool_does_not_fail
assert_not PaymentOrder.supported_method?('not_implemented', shortname: true)
assert PaymentOrder.supported_method?('every_pay', shortname: true)
assert_not PaymentOrder.supported_method?('PaymentOrders::NonExistant')
assert PaymentOrder.supported_method?('PaymentOrders::EveryPay')
end
def test_can_create_with_correct_subclass
payment = PaymentOrder.create_with_type(type: 'seb', invoice: Invoice.new)
assert_equal PaymentOrders::Seb, payment.class