-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathremote_cams_test.rb
140 lines (112 loc) · 3.77 KB
/
remote_cams_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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
require 'test_helper'
class RemoteCamsTest < Test::Unit::TestCase
@@amount = 100
def setup
@gateway = CamsGateway.new(fixtures(:cams))
@amount = rand(100..100000)
@credit_card = credit_card('4111111111111111')
@declined_card = credit_card('4000300015555555')
@options = {
order_id: generate_unique_id,
billing_address: address,
description: 'Store Purchase'
}
end
def test_transcript_scrubbing
transcript = capture_transcript(@gateway) do
@gateway.purchase(@amount, @credit_card, @options)
end
transcript = @gateway.scrub(transcript)
assert_scrubbed(@credit_card.number, transcript)
assert_scrubbed(%r{=#{@credit_card.verification_value}\b}, transcript)
assert_scrubbed(@gateway.options[:password], transcript)
end
def test_successful_purchase
response = @gateway.purchase(@amount, @credit_card, @options)
assert_success response
assert_equal 'SUCCESS', response.message
end
def test_failed_purchase
response = @gateway.purchase(@amount, @declined_card, @options)
assert_failure response
assert !(%r(Invalid Credit Card Number) =~ response.message).nil?
end
def test_successful_purchase_with_reference
response = @gateway.purchase(@amount, @credit_card, @options)
assert_success response
assert_equal 'SUCCESS', response.message
setup
response2 = @gateway.purchase(@amount, response.authorization, @options)
assert_equal 'SUCCESS', response2.message
end
def test_failed_purchase_with_reference
response = @gateway.purchase(@amount, '00000', @options)
assert_failure response
assert !(%r(Invalid Transaction ID) =~ response.message).nil?
end
def test_successful_authorize_and_capture
auth = @gateway.authorize(@amount, @credit_card, @options)
assert_success auth
assert capture = @gateway.capture(@amount, auth.authorization)
assert_success capture
end
def test_failed_authorize
response = @gateway.authorize(@amount, @declined_card, @options)
assert_failure response
end
def test_partial_capture
auth = @gateway.authorize(@amount, @credit_card, @options)
assert_success auth
assert capture = @gateway.capture(@amount - 1, auth.authorization)
assert_success capture
end
def test_failed_capture
response = @gateway.capture(nil, '')
assert_failure response
end
def test_successful_refund
purchase = @gateway.purchase(@amount, @credit_card, @options)
assert_success purchase
assert refund = @gateway.refund(nil, purchase.authorization)
assert_success refund
end
def test_partial_refund
purchase = @gateway.purchase(@amount, @credit_card, @options)
assert_success purchase
assert refund = @gateway.refund(@amount - 1, purchase.authorization)
assert_success refund
end
def test_failed_refund
response = @gateway.refund(nil, '')
assert_failure response
end
def test_successful_void
auth = @gateway.authorize(@amount, @credit_card, @options)
assert_success auth
assert void = @gateway.void(auth.authorization)
assert_success void
end
def test_failed_void
response = @gateway.void('')
assert_failure response
end
def test_successful_verify
response = @gateway.verify(@credit_card, @options)
assert_success response
assert_equal nil, response.message
end
def test_failed_verify
response = @gateway.verify(@declined_card, @options)
assert_failure response
assert_match %r{Invalid Credit Card Number}, response.message
assert_equal Gateway::STANDARD_ERROR_CODE[:card_declined], response.error_code
end
def test_invalid_login
gateway = CamsGateway.new(
username: '',
password: ''
)
response = gateway.purchase(@amount, @credit_card, @options)
assert_failure response
end
end