-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfees_request_spec.rb
More file actions
102 lines (85 loc) · 3.75 KB
/
fees_request_spec.rb
File metadata and controls
102 lines (85 loc) · 3.75 KB
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
require 'forms_helper'
describe 'Fees', type: :request do
def base_url_for(user_id = nil)
"https://api-na.hosted.exlibrisgroup.com/almaws/v1/users/#{user_id}"
end
let(:alma_api_key) { 'totally-fake-key' }
let(:request_headers) { { 'Accept' => 'application/json', 'Authorization' => "apikey #{alma_api_key}" } }
before do
allow(AlmaJwtValidator).to receive(:decode_and_verify_jwt).and_return(
[{ 'userName' => '10335026' }]
)
allow(Rails.application.config).to receive_messages(
alma_api_key: alma_api_key,
alma_jwt_secret: 'fake-jwt-secret'
)
end
it 'redirects to the fallback URL if there is no jwt' do
get fees_path
expect(response).to redirect_to('https://www.lib.berkeley.edu/find/borrow-renew?section=pay-fees')
end
it 'redirects to error page if request has a non-existant alma id' do
user_id = '10335026'
stub_request(:get, "#{base_url_for(user_id)}/fees")
.with(headers: request_headers)
.to_return(status: 404, body: '')
get '/fees?&jwt=totallyfakejwt'
follow_redirect!
expect(response).to have_http_status(:ok)
expect(response.body).to include('Error')
end
it 'list page with an existing alma id routes to index page' do
user_id = '10335026'
stub_request(:get, "#{base_url_for(user_id)}/fees")
.with(headers: request_headers)
.to_return(status: 200, body: File.new('spec/data/fees/alma-fees-list.json'))
get "/fees?&jwt=#{File.read('spec/data/fees/alma-fees-jwt.txt')}"
expect(response.body).to include('<h1>List of Fees</h1>')
expect(response.body).to include('Lost item process fee')
end
it 'payments page lists fees to confirm payment' do
user_id = '10335026'
stub_request(:get, "#{base_url_for(user_id)}/fees")
.with(headers: request_headers)
.to_return(status: 200, body: File.new('spec/data/fees/alma-fees-list.json'))
post '/fees/payment', params: { alma_id: user_id, fee: { payment: ['3260566220006532'] } }
expect(response).to have_http_status(:ok)
expect(response.body).to include('<h1>Confirm Fees to Pay</h1>')
expect(response.body).to include('Lost item process fee')
expect(response.body).to include('Total Payment: $10.00')
end
it 'payments page redirects to index if no fee was selected for payment' do
jwt = File.read('spec/data/fees/alma-fees-jwt.txt').strip
post '/fees/payment', params: { jwt: jwt }
expect(response).to have_http_status(:found)
expect(response).to redirect_to("#{fees_path}?jwt=#{jwt}")
end
it 'successful transaction_complete returns status 200' do
user_id = '10335026'
stub_request(:post, "#{base_url_for(user_id)}/fees/3260566220006532")
.with(
headers: request_headers,
query: { amount: '10.00', external_transaction_id: nil, method: 'ONLINE', op: 'pay' }
)
.to_return(status: 200, body: '', headers: {})
stub_request(:get, "#{base_url_for(user_id)}/fees")
.with(headers: request_headers)
.to_return(status: 200, body: File.new('spec/data/fees/alma-fees-list.json'))
post '/fees/transaction_complete', params: { RESULT: '0', USER1: user_id, USER2: ['3260566220006532'] }
expect(response).to have_http_status(:ok)
end
it 'unsuccessful transaction_complete returns status 500' do
post '/fees/transaction_complete', params: { RESULT: '100', USER1: '10335026', USER2: ['3260566220006532'] }
expect(response).to have_http_status(:internal_server_error)
end
it 'fail page renders' do
get fees_transaction_fail_path
expect(response).to have_http_status(:ok)
expect(response.body).to include('Payment Failed')
end
it 'error page renders' do
get fees_transaction_error_path
expect(response).to have_http_status(:ok)
expect(response.body).to include('Error')
end
end