-
Notifications
You must be signed in to change notification settings - Fork 14
/
testing_issuing_integration_spec.rb
72 lines (58 loc) · 1.93 KB
/
testing_issuing_integration_spec.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
# frozen_string_literal: true
RSpec.describe CheckoutSdk::Issuing do
include IssuingHelper
skip 'Avoid creating cards all the time' do
before(:all) do
@cardholder = create_cardholder
@card = create_card @cardholder.id, true
@transaction = simulate_transaction @card
end
describe '.simulate_authorization' do
context 'when simulating authorization with valid card' do
it { authorizes_transaction get_issuing_api.issuing.simulate_authorization get_authorization_request }
end
end
describe '.simulate_increment' do
context 'when simulating increment authorization with valid card' do
it { authorizes_transaction get_issuing_api.issuing.simulate_increment @transaction.id, { 'amount' => 300 } }
end
end
describe '.simulate_clearing' do
context 'when simulating a clearing of an existing transaction' do
it { authorizes_clearing get_issuing_api.issuing.simulate_clearing @transaction.id, { 'amount' => 100 } }
end
end
describe '.simulate_reversal' do
context 'when simulating a reversal of an existing transaction' do
it { reverses_transaction get_issuing_api.issuing.simulate_reversal @transaction.id, { 'amount' => 100 } }
end
end
end
end
private
def authorizes_transaction(response)
assert_response response, %w[status]
expect(response.status).to eq 'Authorized'
end
def authorizes_clearing(response)
assert_response response
expect(response.http_metadata.status_code).to eq 202
end
def reverses_transaction(response)
assert_response response, %w[status]
expect(response.status).to eq 'Reversed'
end
def get_authorization_request
{
'card' => {
'id' => @card.id,
'expiry_month' => @card.expiry_month,
'expiry_year' => @card.expiry_year
},
'transaction' => {
'type' => 'purchase',
'amount' => 100,
'currency' => CheckoutSdk::Common::Currency::GBP
}
}
end