forked from codeforamerica/ohana-web-search
/
status_controller_spec.rb
45 lines (37 loc) · 1.51 KB
/
status_controller_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
require 'spec_helper'
describe StatusController do
describe "GET /.well-known/status" do
context "when everything is fine", :vcr do
it "returns success" do
get "get_status"
body = JSON.parse(response.body)
expect(body["status"]).to eq("ok")
end
end
context "when API does not return results" do
before do
VCR.turn_off!
end
after do
VCR.turn_on!
end
it "returns API failure error" do
stub_request(:get, "http://ohanapi.herokuapp.com/api/locations/downtown-palo-alto-food-closet?api_token=#{ENV["OHANA_API_TOKEN"]}").
with(:headers => {'Accept'=>'application/vnd.ohanapi-v1+json',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'User-Agent'=>'Ohanakapa Ruby Gem 1.0.0',
'X-Api-Token'=>"#{ENV["OHANA_API_TOKEN"]}"}).
to_return(:status => 200, :body => "", :headers => {})
stub_request(:get, "http://ohanapi.herokuapp.com/api/search?api_token=#{ENV["OHANA_API_TOKEN"]}&keyword=maceo").
with(:headers => {'Accept'=>'application/vnd.ohanapi-v1+json',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'User-Agent'=>'Ohanakapa Ruby Gem 1.0.0',
'X-Api-Token'=>"#{ENV["OHANA_API_TOKEN"]}"}).
to_return(:status => 200, :body => "", :headers => {})
get "get_status"
body = JSON.parse(response.body)
expect(body["status"]).to eq("API did not respond")
end
end
end
end