/
remote_garanti_test.rb
63 lines (53 loc) · 1.84 KB
/
remote_garanti_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
require 'test_helper'
# NOTE: tests may fail randomly because Garanti returns random(!) responses for their test server
class RemoteGarantiTest < Test::Unit::TestCase
def setup
@gateway = GarantiGateway.new(fixtures(:garanti))
@amount = 100 # 1 cents = 0.01$
@declined_card = credit_card('4282209027132017')
@credit_card = credit_card('4282209027132016', month: 5, year: 2018, verification_value: 358)
@options = {
:order_id => generate_unique_id,
:billing_address => address,
:description => 'Store Purchase'
}
end
def teardown
$KCODE = @original_kcode if @original_kcode
end
def test_successful_purchase
assert response = @gateway.purchase(@amount, @credit_card, @options)
assert_success response
assert_equal 'Approved', response.message
end
def test_unsuccessful_purchase
assert response = @gateway.purchase(@amount, @declined_card, @options)
assert_failure response
assert_match %r{Declined}, response.message
end
def test_authorize_and_capture
amount = @amount
assert auth = @gateway.authorize(amount, @credit_card, @options)
assert_success auth
assert_equal 'Approved', auth.message
assert auth.authorization
assert capture = @gateway.capture(amount, auth.authorization)
assert_success capture
end
def test_failed_capture
assert response = @gateway.capture(@amount, '')
assert_failure response
assert_match %r{Declined}, response.message
end
def test_invalid_login
gateway = GarantiGateway.new(
:login => 'PROVAUT',
:terminal_id => '30691300',
:merchant_id => '',
:password => ''
)
assert response = gateway.purchase(@amount, @credit_card, @options)
assert_failure response
assert_equal '0651', response.params["reason_code"]
end
end