mirror of
https://github.com/internetee/registry.git
synced 2025-08-12 20:49:36 +02:00
Fix timezone problem in tests
This commit is contained in:
parent
f6b1db2cce
commit
e066b1d246
6 changed files with 66 additions and 47 deletions
|
@ -36,8 +36,6 @@ module Payments
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
SUCCESS_FIELDS =
|
|
||||||
|
|
||||||
def validate_success
|
def validate_success
|
||||||
pars = %w(VK_SERVICE VK_VERSION VK_SND_ID VK_REC_ID VK_STAMP VK_T_NO VK_AMOUNT VK_CURR
|
pars = %w(VK_SERVICE VK_VERSION VK_SND_ID VK_REC_ID VK_STAMP VK_T_NO VK_AMOUNT VK_CURR
|
||||||
VK_REC_ACC VK_REC_NAME VK_SND_ACC VK_SND_NAME VK_REF VK_MSG VK_T_DATETIME).freeze
|
VK_REC_ACC VK_REC_NAME VK_SND_ACC VK_SND_NAME VK_REF VK_MSG VK_T_DATETIME).freeze
|
||||||
|
|
|
@ -56,7 +56,7 @@ module Payments
|
||||||
timestamp: Time.now.to_i.to_s,
|
timestamp: Time.now.to_i.to_s,
|
||||||
callback_url: response_url,
|
callback_url: response_url,
|
||||||
customer_url: return_url,
|
customer_url: return_url,
|
||||||
amount: invoice.total,
|
amount: number_with_precision(invoice.total, precision: 2),
|
||||||
order_reference: SecureRandom.hex(15),
|
order_reference: SecureRandom.hex(15),
|
||||||
transaction_type: 'charge',
|
transaction_type: 'charge',
|
||||||
hmac_fields: ''
|
hmac_fields: ''
|
||||||
|
|
|
@ -136,7 +136,7 @@ payments_intermediaries: >
|
||||||
# payments_intermediary_api_user - API username, in case it's different than the seller account
|
# payments_intermediary_api_user - API username, in case it's different than the seller account
|
||||||
# payments_intermediary_api_key - API key given to you by intermediary
|
# payments_intermediary_api_key - API key given to you by intermediary
|
||||||
payments_every_pay_url: 'https://igw-demo.every-pay.com/transactions/'
|
payments_every_pay_url: 'https://igw-demo.every-pay.com/transactions/'
|
||||||
payments_every_pay_seller_account: 'account'
|
payments_every_pay_seller_account: 'EUR3D1'
|
||||||
payments_every_pay_api_user: 'api_user'
|
payments_every_pay_api_user: 'api_user'
|
||||||
payments_every_pay_api_key: 'api_key'
|
payments_every_pay_api_key: 'api_key'
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ class PaymentReturnTest < ActionDispatch::IntegrationTest
|
||||||
transaction_result: "completed",
|
transaction_result: "completed",
|
||||||
payment_reference: "fd5d27b59a1eb597393cd5ff77386d6cab81ae05067e18d530b10f3802e30b56",
|
payment_reference: "fd5d27b59a1eb597393cd5ff77386d6cab81ae05067e18d530b10f3802e30b56",
|
||||||
payment_state: "settled",
|
payment_state: "settled",
|
||||||
amount: "12.0",
|
amount: "12.00",
|
||||||
order_reference: "e468a2d59a731ccc546f2165c3b1a6",
|
order_reference: "e468a2d59a731ccc546f2165c3b1a6",
|
||||||
account_id: "EUR3D1",
|
account_id: "EUR3D1",
|
||||||
cc_type: "master_card",
|
cc_type: "master_card",
|
||||||
|
@ -32,7 +32,7 @@ class PaymentReturnTest < ActionDispatch::IntegrationTest
|
||||||
cc_year: "2018",
|
cc_year: "2018",
|
||||||
cc_holder_name: "John Doe",
|
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_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: "72fc94f117389cf5d34dba18a18d20886edb2bbb",
|
hmac: "efac1c732835668cd86023a7abc140506c692f0d",
|
||||||
invoice_id: "12900000",
|
invoice_id: "12900000",
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,7 +4,7 @@ class BankLinkTest < ActiveSupport::TestCase
|
||||||
def setup
|
def setup
|
||||||
super
|
super
|
||||||
@invoice = invoices(:valid)
|
@invoice = invoices(:valid)
|
||||||
params = {return_url: 'return.url', response_url: 'response.url'}
|
params = { return_url: 'return.url', response_url: 'response.url' }
|
||||||
@bank_link = Payments::BankLink.new('seb', @invoice, params)
|
@bank_link = Payments::BankLink.new('seb', @invoice, params)
|
||||||
|
|
||||||
travel_to '2018-04-01 00:30'
|
travel_to '2018-04-01 00:30'
|
||||||
|
@ -15,7 +15,7 @@ class BankLinkTest < ActiveSupport::TestCase
|
||||||
travel_back
|
travel_back
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_is_not_valid_without_response
|
def test_response_is_not_valid_without_response
|
||||||
assert_equal false, @bank_link.valid_response?
|
assert_equal false, @bank_link.valid_response?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,64 +1,85 @@
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class EveryPayTest < ActiveSupport::TestCase
|
class EveryPayTest < ActiveSupport::TestCase
|
||||||
def setup
|
setup do
|
||||||
super
|
@invoice = invoices(:for_payments_test)
|
||||||
|
invoice_item = invoice_items(:one)
|
||||||
|
|
||||||
@original_methods = ENV['payment_methods']
|
@invoice.invoice_items << invoice_item
|
||||||
@original_seb_URL = ENV['seb_payment_url']
|
@invoice.invoice_items << invoice_item
|
||||||
ENV['payment_methods'] = 'seb, swed, credit_card'
|
|
||||||
ENV['seb_payment_url'] = 'https://example.com/seb_url'
|
|
||||||
ENV['seb_seller_account'] = 'SEB'
|
|
||||||
ENV['seb_bank_certificate'] = 'test/fixtures/files/seb_bank_cert.pem'
|
|
||||||
ENV['seb_seller_certificate'] = 'test/fixtures/files/seb_seller_key.pem'
|
|
||||||
|
|
||||||
@invoice = invoices(:valid)
|
|
||||||
params = {
|
params = {
|
||||||
response:
|
response:
|
||||||
{
|
{
|
||||||
utf8:"✓",
|
utf8: "✓",
|
||||||
_method: "put",
|
_method: "put",
|
||||||
authenticity_token: "OnA69vbccQtMt3C9wxEWigs5Gpf/7z+NoxRCMkFPlTvaATs8+OgMKF1I4B2f+vuK37zCgpWZaWWtyuslRRSwkw==",
|
authenticity_token: "OnA69vbccQtMt3C9wxEWigs5Gpf/7z+NoxRCMkFPlTvaATs8+OgMKF1I4B2f+vuK37zCgpWZaWWtyuslRRSwkw==",
|
||||||
nonce: "8a9063b3c13edb00522d446481cb1886",
|
nonce: "392f2d7748bc8cb0d14f263ebb7b8932",
|
||||||
timestamp: "1524036436",
|
timestamp: "1524136727",
|
||||||
api_username: "ca8d6336dd750ddb",
|
api_username: "ca8d6336dd750ddb",
|
||||||
transaction_result: "completed",
|
transaction_result: "completed",
|
||||||
payment_reference: "3380fc36f02a7c1d2b0a700794e7a6ef8683191b3f0dc88b762e72c6e573adaf",
|
payment_reference: "fd5d27b59a1eb597393cd5ff77386d6cab81ae05067e18d530b10f3802e30b56",
|
||||||
payment_state: "settled",
|
payment_state: "settled",
|
||||||
amount: "240.0",
|
amount: "12.00",
|
||||||
order_reference: "59fa7f639211d1e14952bad73ccb50",
|
order_reference: "e468a2d59a731ccc546f2165c3b1a6",
|
||||||
account_id: "EUR3D1",
|
account_id: "EUR3D1",
|
||||||
cc_type: "master_card",
|
cc_type: "master_card",
|
||||||
cc_last_four_digits: "0487",
|
cc_last_four_digits: "0487",
|
||||||
cc_month: "10",
|
cc_month: "10",
|
||||||
cc_year: "2018",
|
cc_year: "2018",
|
||||||
cc_holder_name: "John Doe",
|
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_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: "d5b11b001b248532ad5af529f072b5b76347936a",
|
hmac: "efac1c732835668cd86023a7abc140506c692f0d",
|
||||||
controller: "registrar/payments",
|
invoice_id: "1",
|
||||||
action: "back",
|
|
||||||
bank: "every_pay"
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@every_pay = Payments::EveryPay.new('every_pay', @invoice, params)
|
@every_pay = Payments::EveryPay.new('every_pay', @invoice, params)
|
||||||
|
@other_pay = Payments::EveryPay.new('every_pay', @invoice, {})
|
||||||
|
|
||||||
travel_to '2018-04-01 00:30'
|
# To avoid problems with time conversion.
|
||||||
|
travel_to Time.at(1522542600)
|
||||||
end
|
end
|
||||||
|
|
||||||
def teardown
|
teardown do
|
||||||
super
|
|
||||||
|
|
||||||
ENV['payment_methods'] = @original_methods
|
|
||||||
ENV['seb_payment_url'] = @original_seb_URL
|
|
||||||
travel_back
|
travel_back
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_form_fields
|
def test_form_fields
|
||||||
|
expected_fields = {
|
||||||
|
api_username: "api_user",
|
||||||
|
account_id: "EUR3D1",
|
||||||
|
timestamp: "1522542600",
|
||||||
|
amount: "12.00",
|
||||||
|
order_reference: "Order nr. 1",
|
||||||
|
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|
|
||||||
|
assert_equal(v, form_fields[k])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_is_not_valid_without_response
|
def test_valid_response?
|
||||||
|
assert(@every_pay.valid_response?)
|
||||||
|
refute(@other_pay.valid_response?)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_validation
|
def test_settled_payment?
|
||||||
|
assert(@every_pay.settled_payment?)
|
||||||
|
other_pay = Payments::EveryPay.new(
|
||||||
|
'every_pay', @invoice, {response: {payment_state: "CANCELLED"}}
|
||||||
|
)
|
||||||
|
refute(other_pay.settled_payment?)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_valid_response?
|
||||||
|
assert(@every_pay.valid_response?)
|
||||||
|
refute(@other_pay.valid_response?)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_complete_transaction_returns_account_activity_or_nil
|
||||||
|
assert_instance_of(AccountActivity, @every_pay.complete_transaction)
|
||||||
|
refute(@other_pay.complete_transaction)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue