mirror of
https://github.com/internetee/registry.git
synced 2025-06-10 14:44:47 +02:00
Rework test to operate on mocks, since it does not need real objects
This commit is contained in:
parent
d7eca597d1
commit
841a069ca4
5 changed files with 100 additions and 82 deletions
|
@ -65,8 +65,7 @@ module Payments
|
|||
transaction.paid_at = Time.parse(response["VK_T_DATETIME"])
|
||||
|
||||
transaction.save!
|
||||
account_activity = transaction.autobind_invoice
|
||||
account_activity
|
||||
transaction.autobind_invoice
|
||||
end
|
||||
|
||||
def settled_payment?
|
||||
|
|
|
@ -42,8 +42,7 @@ module Payments
|
|||
transaction.buyer_name = response[:cc_holder_name]
|
||||
|
||||
transaction.save!
|
||||
account_activity = transaction.autobind_invoice
|
||||
account_activity
|
||||
transaction.autobind_invoice
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -82,12 +82,10 @@ class PaymentReturnTest < ActionDispatch::IntegrationTest
|
|||
def test_bank_link_return_redirects_to_invoice_paths
|
||||
create_invoice_with_items
|
||||
request_params = bank_link_request_params.merge(invoice_id: @invoice.id)
|
||||
account_activity_count = AccountActivity.count
|
||||
|
||||
post "/registrar/pay/return/seb", request_params
|
||||
assert_equal(302, response.status)
|
||||
assert_redirected_to(registrar_invoice_path(@invoice))
|
||||
assert_equal(account_activity_count + 1, AccountActivity.count)
|
||||
end
|
||||
|
||||
def test_bank_link_return
|
||||
|
|
|
@ -26,24 +26,24 @@ class BankLinkTest < ActiveSupport::TestCase
|
|||
|
||||
def create_completed_bank_link
|
||||
params = {
|
||||
"VK_SERVICE": "1111",
|
||||
"VK_VERSION": "008",
|
||||
"VK_SND_ID": "testvpos",
|
||||
"VK_REC_ID": "seb",
|
||||
"VK_STAMP": 1,
|
||||
"VK_T_NO": "1",
|
||||
"VK_AMOUNT": "12.00",
|
||||
"VK_CURR": "EUR",
|
||||
"VK_REC_ACC": "1234",
|
||||
"VK_REC_NAME": "Eesti Internet",
|
||||
"VK_SND_ACC": "1234",
|
||||
"VK_SND_NAME": "John Doe",
|
||||
"VK_REF": "",
|
||||
"VK_MSG": "Order nr 1",
|
||||
"VK_T_DATETIME": "2018-04-01T00:30:00+0300",
|
||||
"VK_MAC": "CZZvcptkxfuOxRR88JmT4N+Lw6Hs4xiQfhBWzVYldAcRTQbcB/lPf9MbJzBE4e1/HuslQgkdCFt5g1xW2lJwrVDBQTtP6DAHfvxU3kkw7dbk0IcwhI4whUl68/QCwlXEQTAVDv1AFnGVxXZ40vbm/aLKafBYgrirB5SUe8+g9FE=",
|
||||
"VK_ENCODING": "UTF-8",
|
||||
"VK_LANG": "ENG"
|
||||
'VK_SERVICE': '1111',
|
||||
'VK_VERSION': '008',
|
||||
'VK_SND_ID': 'testvpos',
|
||||
'VK_REC_ID': 'seb',
|
||||
'VK_STAMP': 1,
|
||||
'VK_T_NO': '1',
|
||||
'VK_AMOUNT': '12.00',
|
||||
'VK_CURR': 'EUR',
|
||||
'VK_REC_ACC': '1234',
|
||||
'VK_REC_NAME': 'Eesti Internet',
|
||||
'VK_SND_ACC': '1234',
|
||||
'VK_SND_NAME': 'John Doe',
|
||||
'VK_REF': '',
|
||||
'VK_MSG': 'Order nr 1',
|
||||
'VK_T_DATETIME': '2018-04-01T00:30:00+0300',
|
||||
'VK_MAC': 'CZZvcptkxfuOxRR88JmT4N+Lw6Hs4xiQfhBWzVYldAcRTQbcB/lPf9MbJzBE4e1/HuslQgkdCFt5g1xW2lJwrVDBQTtP6DAHfvxU3kkw7dbk0IcwhI4whUl68/QCwlXEQTAVDv1AFnGVxXZ40vbm/aLKafBYgrirB5SUe8+g9FE=',
|
||||
'VK_ENCODING': 'UTF-8',
|
||||
'VK_LANG': 'ENG'
|
||||
}.with_indifferent_access
|
||||
|
||||
@completed_bank_link = Payments::BankLink.new(
|
||||
|
@ -53,16 +53,16 @@ class BankLinkTest < ActiveSupport::TestCase
|
|||
|
||||
def create_cancelled_bank_link
|
||||
params = {
|
||||
"VK_SERVICE": "1911",
|
||||
"VK_VERSION": "008",
|
||||
"VK_SND_ID": "testvpos",
|
||||
"VK_REC_ID": "seb",
|
||||
"VK_STAMP": 1,
|
||||
"VK_REF": "",
|
||||
"VK_MSG": "Order nr 1",
|
||||
"VK_MAC": "PElE2mYXXN50q2UBvTuYU1rN0BmOQcbafPummDnWfNdm9qbaGQkGyOn0XaaFGlrdEcldXaHBbZKUS0HegIgjdDfl2NOk+wkLNNH0Iu38KzZaxHoW9ga7vqiyKHC8dcxkHiO9HsOnz77Sy/KpWCq6cz48bi3fcMgo+MUzBMauWoQ=",
|
||||
"VK_ENCODING": "UTF-8",
|
||||
"VK_LANG": "ENG"
|
||||
'VK_SERVICE': '1911',
|
||||
'VK_VERSION': '008',
|
||||
'VK_SND_ID': 'testvpos',
|
||||
'VK_REC_ID': 'seb',
|
||||
'VK_STAMP': 1,
|
||||
'VK_REF': '',
|
||||
'VK_MSG': 'Order nr 1',
|
||||
'VK_MAC': 'PElE2mYXXN50q2UBvTuYU1rN0BmOQcbafPummDnWfNdm9qbaGQkGyOn0XaaFGlrdEcldXaHBbZKUS0HegIgjdDfl2NOk+wkLNNH0Iu38KzZaxHoW9ga7vqiyKHC8dcxkHiO9HsOnz77Sy/KpWCq6cz48bi3fcMgo+MUzBMauWoQ=',
|
||||
'VK_ENCODING': 'UTF-8',
|
||||
'VK_LANG': 'ENG'
|
||||
}.with_indifferent_access
|
||||
|
||||
@cancelled_bank_link = Payments::BankLink.new(
|
||||
|
@ -81,20 +81,20 @@ class BankLinkTest < ActiveSupport::TestCase
|
|||
|
||||
def test_form_fields
|
||||
expected_response = {
|
||||
"VK_SERVICE": "1012",
|
||||
"VK_VERSION": "008",
|
||||
"VK_SND_ID": "testvpos",
|
||||
"VK_STAMP": 1,
|
||||
"VK_AMOUNT": "12.00",
|
||||
"VK_CURR": "EUR",
|
||||
"VK_REF": "",
|
||||
"VK_MSG": "Order nr. 1",
|
||||
"VK_RETURN": "return.url",
|
||||
"VK_CANCEL": "return.url",
|
||||
"VK_DATETIME": "2018-04-01T00:30:00+0300",
|
||||
"VK_MAC": "q70UNFV4ih1qYij2+CyrHaApc3OE66igy3ijuR1m9dl0Cg+lIrAUsP47JChAF7PRErwZ78vSuZwrg0Vabhlp3WoC934ik2FiE04BBxUUTndONvguaNR1wvl0FiwfXFljLncX7TOmRraywJljKC5vTnIRNT2+1HXvmv0v576PGao=",
|
||||
"VK_ENCODING": "UTF-8",
|
||||
"VK_LANG": "ENG"
|
||||
'VK_SERVICE': '1012',
|
||||
'VK_VERSION': '008',
|
||||
'VK_SND_ID': 'testvpos',
|
||||
'VK_STAMP': 1,
|
||||
'VK_AMOUNT': '12.00',
|
||||
'VK_CURR': 'EUR',
|
||||
'VK_REF': '',
|
||||
'VK_MSG': 'Order nr. 1',
|
||||
'VK_RETURN': 'return.url',
|
||||
'VK_CANCEL': 'return.url',
|
||||
'VK_DATETIME': '2018-04-01T00:30:00+0300',
|
||||
'VK_MAC': 'q70UNFV4ih1qYij2+CyrHaApc3OE66igy3ijuR1m9dl0Cg+lIrAUsP47JChAF7PRErwZ78vSuZwrg0Vabhlp3WoC934ik2FiE04BBxUUTndONvguaNR1wvl0FiwfXFljLncX7TOmRraywJljKC5vTnIRNT2+1HXvmv0v576PGao=',
|
||||
'VK_ENCODING': 'UTF-8',
|
||||
'VK_LANG': 'ENG'
|
||||
}.with_indifferent_access
|
||||
|
||||
assert_equal(expected_response, @new_bank_link.form_fields)
|
||||
|
@ -113,8 +113,21 @@ class BankLinkTest < ActiveSupport::TestCase
|
|||
refute(@cancelled_bank_link.settled_payment?)
|
||||
end
|
||||
|
||||
def test_complete_transaction_returns_account_activity_or_nil
|
||||
assert_instance_of(AccountActivity, @completed_bank_link.complete_transaction)
|
||||
assert_nil(@cancelled_bank_link.complete_transaction)
|
||||
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)
|
||||
|
||||
BankTransaction.stub(:find_by, mock_transaction) do
|
||||
@completed_bank_link.complete_transaction
|
||||
end
|
||||
|
||||
mock_transaction.verify
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,26 +11,26 @@ class EveryPayTest < ActiveSupport::TestCase
|
|||
params = {
|
||||
response:
|
||||
{
|
||||
utf8: "✓",
|
||||
_method: "put",
|
||||
authenticity_token: "OnA69vbccQtMt3C9wxEWigs5Gpf/7z+NoxRCMkFPlTvaATs8+OgMKF1I4B2f+vuK37zCgpWZaWWtyuslRRSwkw==",
|
||||
nonce: "392f2d7748bc8cb0d14f263ebb7b8932",
|
||||
timestamp: "1524136727",
|
||||
api_username: "ca8d6336dd750ddb",
|
||||
transaction_result: "completed",
|
||||
payment_reference: "fd5d27b59a1eb597393cd5ff77386d6cab81ae05067e18d530b10f3802e30b56",
|
||||
payment_state: "settled",
|
||||
amount: "12.00",
|
||||
order_reference: "e468a2d59a731ccc546f2165c3b1a6",
|
||||
account_id: "EUR3D1",
|
||||
cc_type: "master_card",
|
||||
cc_last_four_digits: "0487",
|
||||
cc_month: "10",
|
||||
cc_year: "2018",
|
||||
cc_holder_name: "John Doe",
|
||||
hmac_fields: "account_id,amount,api_username,cc_holder_name,cc_last_four_digits,cc_month,cc_type,cc_year,hmac_fields,nonce,order_reference,payment_reference,payment_state,timestamp,transaction_result",
|
||||
hmac: "efac1c732835668cd86023a7abc140506c692f0d",
|
||||
invoice_id: "1",
|
||||
utf8: '✓',
|
||||
_method: 'put',
|
||||
authenticity_token: 'OnA69vbccQtMt3C9wxEWigs5Gpf/7z+NoxRCMkFPlTvaATs8+OgMKF1I4B2f+vuK37zCgpWZaWWtyuslRRSwkw==',
|
||||
nonce: '392f2d7748bc8cb0d14f263ebb7b8932',
|
||||
timestamp: '1524136727',
|
||||
api_username: 'ca8d6336dd750ddb',
|
||||
transaction_result: 'completed',
|
||||
payment_reference: 'fd5d27b59a1eb597393cd5ff77386d6cab81ae05067e18d530b10f3802e30b56',
|
||||
payment_state: 'settled',
|
||||
amount: '12.00',
|
||||
order_reference: 'e468a2d59a731ccc546f2165c3b1a6',
|
||||
account_id: 'EUR3D1',
|
||||
cc_type: 'master_card',
|
||||
cc_last_four_digits: '0487',
|
||||
cc_month: '10',
|
||||
cc_year: '2018',
|
||||
cc_holder_name: 'John Doe',
|
||||
hmac_fields: 'account_id,amount,api_username,cc_holder_name,cc_last_four_digits,cc_month,cc_type,cc_year,hmac_fields,nonce,order_reference,payment_reference,payment_state,timestamp,transaction_result',
|
||||
hmac: 'efac1c732835668cd86023a7abc140506c692f0d',
|
||||
invoice_id: '1',
|
||||
},
|
||||
}
|
||||
@every_pay = Payments::EveryPay.new('every_pay', @invoice, params)
|
||||
|
@ -46,12 +46,12 @@ class EveryPayTest < ActiveSupport::TestCase
|
|||
|
||||
def test_form_fields
|
||||
expected_fields = {
|
||||
api_username: "api_user",
|
||||
account_id: "EUR3D1",
|
||||
timestamp: "1522542600",
|
||||
amount: "12.00",
|
||||
transaction_type: "charge",
|
||||
hmac_fields: "account_id,amount,api_username,callback_url,customer_url,hmac_fields,nonce,order_reference,timestamp,transaction_type"
|
||||
api_username: 'api_user',
|
||||
account_id: 'EUR3D1',
|
||||
timestamp: '1522542600',
|
||||
amount: '12.00',
|
||||
transaction_type: 'charge',
|
||||
hmac_fields: 'account_id,amount,api_username,callback_url,customer_url,hmac_fields,nonce,order_reference,timestamp,transaction_type'
|
||||
}
|
||||
form_fields = @every_pay.form_fields
|
||||
expected_fields.each do |k, v|
|
||||
|
@ -67,14 +67,23 @@ class EveryPayTest < ActiveSupport::TestCase
|
|||
def test_settled_payment?
|
||||
assert(@every_pay.settled_payment?)
|
||||
other_pay = Payments::EveryPay.new(
|
||||
'every_pay', @invoice, {response: {payment_state: "CANCELLED"}}
|
||||
'every_pay', @invoice, {response: {payment_state: 'CANCELLED'}}
|
||||
)
|
||||
refute(other_pay.settled_payment?)
|
||||
end
|
||||
|
||||
def test_complete_transaction_returns_account_activity_or_nil
|
||||
# skip('Figure out what fails in Travis')
|
||||
assert_instance_of(AccountActivity, @every_pay.complete_transaction)
|
||||
refute(@other_pay.complete_transaction)
|
||||
def test_complete_transaction_calls_methods_on_transaction
|
||||
mock_transaction = MiniTest::Mock.new
|
||||
mock_transaction.expect(:sum= , '12.00', ['12.00'])
|
||||
mock_transaction.expect(:paid_at= , Date.strptime('1524136727', '%s'), [Date.strptime('1524136727', '%s')])
|
||||
mock_transaction.expect(:buyer_name=, 'John Doe', ['John Doe'])
|
||||
mock_transaction.expect(:save!, true)
|
||||
mock_transaction.expect(:autobind_invoice, AccountActivity.new)
|
||||
|
||||
BankTransaction.stub(:find_by, mock_transaction) do
|
||||
@every_pay.complete_transaction
|
||||
end
|
||||
|
||||
mock_transaction.verify
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue