-
Notifications
You must be signed in to change notification settings - Fork 14
/
sessions_integration_spec.rb
157 lines (128 loc) · 6.14 KB
/
sessions_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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
RSpec.describe CheckoutSdk::Sessions do
include SessionsHelper
describe '.request_session' do
context 'when requesting card session using browser sessions with valid parameters' do
it 'creates a browser session' do
browser_session = get_browser_session
request = get_non_hosted_session browser_session,
CheckoutSdk::Sessions::Category::PAYMENT,
CheckoutSdk::Common::ChallengeIndicator::NO_PREFERENCE,
CheckoutSdk::Sessions::TransactionType::GOODS_SERVICE
response = oauth_sdk.sessions.request_session request
assert_response response, %w[id
session_secret]
end
end
context 'when requesting card session using an app session with valid parameters' do
it 'creates an app session' do
app_session = get_app_session
request = get_non_hosted_session app_session,
CheckoutSdk::Sessions::Category::PAYMENT,
CheckoutSdk::Common::ChallengeIndicator::NO_PREFERENCE,
CheckoutSdk::Sessions::TransactionType::GOODS_SERVICE
response = oauth_sdk.sessions.request_session request
assert_response response, %w[id
session_secret]
end
end
end
describe '.get_session_details' do
context 'when fetching existent card browser session' do
subject(:session) { request_non_hosted_browser_session }
it 'retrieves session details' do
response = oauth_sdk.sessions.get_session_details session.id
assert_response response, %w[id
session_secret]
expect(response.id).to eq session.id
expect(response.amount).to eq session.amount
expect(response.currency).to eq session.currency
expect(response.completed).to eq session.completed
expect(response.authentication_type).to eq session.authentication_type
expect(response.session_secret).to eq session.session_secret
end
end
context 'when fetching existent card app session' do
subject(:session) { request_non_hosted_app_session }
it 'retrieves session details' do
response = oauth_sdk.sessions.get_session_details session.id
assert_response response, %w[id
session_secret]
expect(response.id).to eq session.id
expect(response.amount).to eq session.amount
expect(response.currency).to eq session.currency
expect(response.completed).to eq session.completed
expect(response.authentication_type).to eq session.authentication_type
expect(response.session_secret).to eq session.session_secret
end
end
context 'when fetching inexistent session', skip: 'returns Access denied status when updating' do
it 'raises an error' do
expect { oauth_sdk.sessions.get_session_details 'not_found' }
.to raise_error(CheckoutSdk::CheckoutApiException) { |e| expect(e.http_metadata.status_code).to eq 404 }
end
end
end
describe '.update_session' do
before(:each) do
@session = oauth_sdk.sessions.request_session get_hosted_session
end
context 'when updating a Card session with an ID browser session' do
it 'updates fields correctly' do
response = oauth_sdk.sessions.update_session @session.id, get_browser_session
assert_response response, %w[id
session_secret]
end
end
context 'when updating a Card session with session secret browser session' do
it 'updates fields correctly' do
response = oauth_sdk.sessions.update_session @session.id, get_browser_session, @session.session_secret
assert_response response, %w[id]
end
end
end
describe '.complete_session' do
before(:each) do
@session = oauth_sdk.sessions.request_session get_hosted_session
end
context 'when trying to complete session with pending status and without session secret' do
it 'raises an error because of session state' do
expect { oauth_sdk.sessions.complete_session @session.id }
.to raise_error(CheckoutSdk::CheckoutApiException) {
|e| expect(e.http_metadata.status_code).to eq 403
expect(e.error_details[:error_codes].first).to eq 'update_not_allowed_due_to_state'
}
end
end
context 'when trying to complete session with pending status and with session secret' do
it 'raises an error because of session state' do
expect { oauth_sdk.sessions.complete_session @session.id, @session.session_secret }
.to raise_error(CheckoutSdk::CheckoutApiException) {
|e| expect(e.http_metadata.status_code).to eq 403
expect(e.error_details[:error_codes].first).to eq 'update_not_allowed_due_to_state'
}
end
end
end
describe '.update_3ds_method_completion' do
before(:each) do
@session = oauth_sdk.sessions.request_session get_hosted_session
end
context 'when updating session with 3ds method completion indicator' do
it 'updates fields correctly' do
three_ds_request = CheckoutSdk::Sessions::ThreeDsMethodCompletionRequest.new
three_ds_request.three_ds_method_completion = CheckoutSdk::Sessions::ThreeDsMethodCompletion::Y
response = oauth_sdk.sessions.update_3ds_method_completion @session.id, three_ds_request
assert_response response, %w[id
session_secret]
end
end
context 'when updating session with 3ds method completion indicator and using session secret' do
it 'updates fields correctly' do
three_ds_request = CheckoutSdk::Sessions::ThreeDsMethodCompletionRequest.new
three_ds_request.three_ds_method_completion = CheckoutSdk::Sessions::ThreeDsMethodCompletion::Y
response = oauth_sdk.sessions.update_3ds_method_completion @session.id, three_ds_request, @session.session_secret
assert_response response, %w[id]
end
end
end
end