Fix leaking test

This commit is contained in:
Maciej Szlosarczyk 2018-04-19 10:44:40 +03:00
parent 1cca930744
commit f6b1db2cce
No known key found for this signature in database
GPG key ID: 41D62D42D3B0D765
12 changed files with 134 additions and 31 deletions

View file

@ -6,25 +6,19 @@ class Registrar
skip_before_action :authenticate_user!, :check_ip_restriction, only: [:back, :callback]
# before_action :check_bank
# to handle existing model we should
# get invoice_id and then get number
# build BankTransaction without connection with right reference number
# do not connect transaction and invoice
# TODO: Refactor to :new
def pay
invoice = Invoice.find(params[:invoice_id])
opts = {
return_url: self.registrar_return_payment_with_url(params[:bank], invoice_id: invoice.id),
# TODO: Add required URL
response_url: "https://5fd921b0.ngrok.io/registrar/pay/callback/every_pay"
response_url: "https://53e21cc8.ngrok.io/registrar/pay/callback/every_pay"
}
@payment = ::Payments.create_with_type(params[:bank], invoice, opts)
@payment.create_transaction
end
# connect invoice and transaction
# both back and IPN
# TODO: Refactor to be restful
def back
invoice = Invoice.find(params[:invoice_id])
@ -60,11 +54,14 @@ class Registrar
private
# def banks
# ENV['payments_banks'].split(",").map(&:strip)
# end
def check_supported_payment_method
unless supported_payment_method?
raise StandardError.new("Not supported payment method")
end
end
def check_bank
def supported_payment_method?
raise StandardError.new("Not Implemented bank") unless banks.include?(params[:bank])
end
end

View file

@ -1,7 +1,7 @@
module Payments
class BankLink < Base
# TODO: Remove magic numbers, convert certain fields to proper constants
# TODO: Remove hashrockets
# DONE: Remove hashrockets
def form_fields
@fields ||= hash = {}
hash["VK_SERVICE"] = "1012"
@ -36,6 +36,8 @@ module Payments
private
SUCCESS_FIELDS =
def validate_success
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

View file

@ -7,7 +7,6 @@ FactoryBot.define do
city 'test'
state 'test'
zip 'test'
vat_rate 0.1
email 'test@test.com'
country_code 'EE'
accounting_customer_code 'test'

View file

@ -1,3 +1,8 @@
one:
sum: 1
currency: EUR
for_payments_test:
description: "Order nr. 1"
currency: "EUR"
iban: "1234"

View file

@ -34,4 +34,6 @@ overdue:
for_payments_test:
<<: *DEFAULTS
total: 100.00
total: 12.00
id: 1
number: 1

View file

@ -6,6 +6,7 @@ class BalanceTopUpTest < ActionDispatch::IntegrationTest
end
def test_creates_new_invoice
original_vat_prc = Setting.registry_vat_prc
Setting.registry_vat_prc = 0.1
visit registrar_invoices_url
@ -21,5 +22,7 @@ class BalanceTopUpTest < ActionDispatch::IntegrationTest
assert_equal BigDecimal(10), invoice.vat_rate
assert_equal BigDecimal('28.05'), invoice.total
assert_text 'Please pay the following invoice'
Setting.registry_vat_prc = original_vat_prc
end
end

View file

@ -18,21 +18,21 @@ class NewInvoicePaymentTest < ActionDispatch::IntegrationTest
create_invoice_and_visit_its_page
click_link_or_button 'Seb'
form = page.find('form')
assert_equal 'https://www.seb.ee/cgi-bin/dv.sh/ipank.r', form['action']
assert_equal 'post', form['method']
assert_equal '220.00', form.find_by_id('VK_AMOUNT', visible: false).value
assert_equal('https://www.seb.ee/cgi-bin/dv.sh/ipank.r', form['action'])
assert_equal('post', form['method'])
assert_equal('240.00', form.find_by_id('VK_AMOUNT', visible: false).value)
end
def test_create_new_Every_Pay_payment
create_invoice_and_visit_its_page
click_link_or_button 'Every pay'
expected_hmac_fields = 'account_id,amount,api_username,callback_url,' +
'customer_url,hmac_fields,nonce,order_reference,timestamp,transaction_type'
'customer_url,hmac_fields,nonce,order_reference,timestamp,transaction_type'
form = page.find('form')
assert_equal 'https://igw-demo.every-pay.com/transactions/', form['action']
assert_equal 'post', form['method']
assert_equal expected_hmac_fields, form.find_by_id('hmac_fields', visible: false).value
assert_equal '220.0', form.find_by_id('amount', visible: false).value
assert_equal('https://igw-demo.every-pay.com/transactions/', form['action'])
assert_equal('post', form['method'])
assert_equal(expected_hmac_fields, form.find_by_id('hmac_fields', visible: false).value)
assert_equal('240.0', form.find_by_id('amount', visible: false).value)
end
end

View file

@ -4,14 +4,6 @@ class NewInvoiceTest < ActionDispatch::IntegrationTest
setup do
@user = users(:api_bestnames)
login_as @user
@original_vat_rate = @user.registrar.vat_rate
@user.registrar.vat_rate = 0.2
end
teardown do
@user.registrar.vat_rate = @original_vat_rate
AccountActivity.destroy_all
Invoice.destroy_all
end
def test_show_balance

View file

@ -0,0 +1,99 @@
require 'test_helper'
class PaymentReturnTest < ActionDispatch::IntegrationTest
setup do
@user = users(:api_bestnames)
login_as @user
end
def create_invoice_with_items
@invoice = invoices(:for_payments_test)
invoice_item = invoice_items(:one)
@invoice.invoice_items << invoice_item
@invoice.invoice_items << invoice_item
@user.registrar.invoices << @invoice
end
def every_pay_request_params
{
nonce: "392f2d7748bc8cb0d14f263ebb7b8932",
timestamp: "1524136727",
api_username: "ca8d6336dd750ddb",
transaction_result: "completed",
payment_reference: "fd5d27b59a1eb597393cd5ff77386d6cab81ae05067e18d530b10f3802e30b56",
payment_state: "settled",
amount: "12.0",
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: "72fc94f117389cf5d34dba18a18d20886edb2bbb",
invoice_id: "12900000",
}
end
def bank_link_request_params
{
"VK_SERVICE": "1111",
"VK_VERSION": "008",
"VK_SND_ID": "KIAupMEE's",
"VK_AMOUNT": "12.00",
"VK_REC_ID": "1235",
"VK_CURR": "EUR",
"VK_T_NO": "1234",
"VK_STAMP": "ahdfjkadsfhjk",
"VK_REC_ACC": "1234",
"VK_REC_NAME": "John Doe",
"VK_SND_ACC": "1234",
"VK_SND_NAME": "Doe John",
"VK_REF": "1234",
"VK_MSG": "Foo",
"VK_T_DATETIME": "2018-04-19T15:52:59+0300",
invoice_id: "12900000",
}
end
def test_every_pay_return_creates_activity_redirects_to_invoice_path
create_invoice_with_items
request_params = every_pay_request_params.merge(invoice_id: @invoice.id)
account_activity_count = AccountActivity.count
post "/registrar/pay/return/every_pay", 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_Every_Pay_return_raises_RecordNotFound
create_invoice_with_items
request_params = every_pay_request_params.merge(invoice_id: "178907")
assert_raises(ActiveRecord::RecordNotFound) do
post "/registrar/pay/return/every_pay", request_params
end
end
def test_bank_link_return_redirects_to_invoice_paths
skip("Need credentials to model the expected request")
create_invoice_with_items
request_params = every_pay_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
create_invoice_with_items
request_params = bank_link_request_params.merge(invoice_id: "178907")
assert_raises(ActiveRecord::RecordNotFound) do
post "/registrar/pay/return/seb", request_params
end
end
end

View file

@ -4,7 +4,7 @@ class BankLinkTest < ActiveSupport::TestCase
def setup
super
@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)
travel_to '2018-04-01 00:30'

View file

@ -10,7 +10,11 @@ class RegistryTest < ActiveSupport::TestCase
end
def test_vat_rate
original_vat_prc = Setting.registry_vat_prc
Setting.registry_vat_prc = 0.25
assert_equal BigDecimal(25), @registry.vat_rate
Setting.registry_vat_prc = original_vat_prc
end
end