-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathokcomputer_spec.rb
More file actions
77 lines (67 loc) · 2.29 KB
/
okcomputer_spec.rb
File metadata and controls
77 lines (67 loc) · 2.29 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
require 'rails_helper'
RSpec.describe 'OKComputer', type: :request do
before do
allow(Alma::User).to receive(:find).and_return(Alma::User.new)
tind_health_check_url = "#{Rails.application.config.tind_base_uri}api/v1/search?In=en"
stub_request(:head, tind_health_check_url).to_return(status: 200)
stub_request(:head, Rails.application.config.x.healthcheck_urls.whois).to_return(status: 200)
stub_request(:head, Rails.application.config.x.healthcheck_urls.hathiTrust).to_return(status: 200)
stub_request(:head, Rails.application.config.x.healthcheck_urls.berkeley_service_now).to_return(status: 200)
stub_request(:get, Rails.application.config.paypal_payflow_url).to_return(status: 200)
end
it 'is mounted at /health' do
get '/health'
expect(response).to have_http_status :ok
end
context 'without SMTP enabled' do
before do
allow(ActionMailer::Base).to receive(:delivery_method).and_return(:test)
OkComputer::Registry.instance_variable_set(:@checks, {})
load Rails.root.join('config/initializers/okcomputer.rb')
end
it 'returns checks to /health' do
get '/health'
expect(response.parsed_body.keys).to match_array %w[
default
database
alma-patron-lookup
database-migrations
tind-api
whois-arin-api
paypal-payflow
hathitrust-api
berkeley-service-now
]
end
end
context 'with SMTP enabled' do
before do
allow(ActionMailer::Base).to receive(:delivery_method).and_return(:smtp)
allow(Net::SMTP).to receive(:start)
OkComputer::Registry.instance_variable_set(:@checks, {})
load Rails.root.join('config/initializers/okcomputer.rb')
end
it 'returns all checks to /health' do
get '/health'
expect(response.parsed_body.keys).to match_array %w[
default
database
alma-patron-lookup
database-migrations
tind-api
whois-arin-api
paypal-payflow
hathitrust-api
berkeley-service-now
mail-connectivity
]
end
end
context 'when Alma lookups fail' do
it 'returns a non-200 response' do
expect(Alma::User).to receive(:find).and_raise('Uh oh!')
get '/health'
expect(response).not_to have_http_status :ok
end
end
end