-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi_controller_spec.rb
99 lines (84 loc) · 3.94 KB
/
api_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
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
require 'rails_helper'
RSpec.describe Api::V0::ApiController, type: :controller do
before(:each) do
@request.env["devise.mapping"] = Devise.mappings[:developer_account]
dev_account = FactoryGirl.create(:developer_account)
dev_account.confirm
sign_in dev_account
end
let(:recognized_key_secret){controller.current_developer_account.current_api_key}
context "when request does not contain an api key" do
let(:response){
rsp = get :event_search, {"format"=>"json"}
JSON.parse(rsp.body)
}
it "should return MissingApiKeyError" do
matching_error_messages = response["errors"].select{|str| str.include?("MissingApiKeyError")}
expect(matching_error_messages).to_not be_empty
end
it "should not return any results" do
expect(response["results"]).to be_empty
end
end
context "when request contains an unrecognized api key" do
let(:unrecognized_key_secret){"idksomething"}
let(:response){
rsp = get :event_search, {"format"=>"json", "api_key"=> unrecognized_key_secret}
JSON.parse(rsp.body)
}
it "should return UnrecognizedApiKeyError" do
matching_error_messages = response["errors"].select{|str| str.include?("UnrecognizedApiKeyError")}
expect(matching_error_messages).to_not be_empty
end
it "should not return any results" do
expect(response["results"]).to be_empty
end
end
context "when request contains a recognized, unrevoked api key" do
let(:response){
rsp = get :event_search, {"format"=>"json", "api_key"=>recognized_key_secret}
JSON.parse(rsp.body)
}
it "should not return MissingApiKeyError nor UnrecognizedApiKeyError" do
matching_error_messages = response["errors"].select{|str| str.include?("MissingApiKeyError") || str.include?("UnrecognizedApiKeyError")}
expect(matching_error_messages).to be_empty
end
end
context "when request contains an unrecognized search parameter" do
let(:response){
rsp = get :event_search, {
"format"=>"json",
"api_key"=>recognized_key_secret,
"def_name"=>"MARTINEZ"
}
JSON.parse(rsp.body)
}
it "should return UnrecognizedEventSearchParameter" do
matching_error_messages = response["errors"].select{|str| str.include?("UnrecognizedEventSearchParameter")}
expect(matching_error_messages).to_not be_empty
end
it "should not return any results" do
expect(response["results"]).to be_empty
end
end
#todo: test each of the following example searches:
# GET /api/v0/event-search.json
# GET /api/v0/event-search.json?case_number=SLC%20161901292
# GET /api/v0/event-search.json?case_number=SLC%20161901292&defendant_name=MARTINEZ
# GET /api/v0/event-search.json?case_number=SLC%20161901292&defendant_name=JONES
# GET /api/v0/event-search.json?defendant_name=MARTINEZ
# GET /api/v0/event-search.json?api_key=123abc456def
# GET /api/v0/event-search.json?api_key=123abc456def&defendant_name=MARTINEZ
# GET /api/v0/event-search.json?api_key=123abc456def&defendant_name=martin
# GET /api/v0/event-search.json?api_key=123abc456def&case_number=SLC%20161901292
# GET /api/v0/event-search.json?api_key=123abc456def&court_room=W43
# GET /api/v0/event-search.json?api_key=123abc456def&court_date=2016-02-25
# GET /api/v0/event-search.json?api_key=123abc456def&defendant_otn=43333145
# GET /api/v0/event-search.json?api_key=123abc456def&defendant_dob=1988-04-05
# GET /api/v0/event-search.json?api_key=123abc456def&defendant_so=368570
# GET /api/v0/event-search.json?api_key=123abc456def&defendant_lea=15-165332
# GET /api/v0/event-search.json?api_key=123abc456def&citation_number=49090509
# GET /api/v0/event-search.json?api_key=123abc456def&court_date=2016-02-25&court_room=W43
# GET /api/v0/event-search.json?api_key=123abc456def&case_number=SLC%20161901292&defendant_name=MARTINEZ
# GET /api/v0/event-search.json?api_key=123abc456def&case_number=SLC%20161901292&defendant_name=JONES
end