]> git.openstreetmap.org Git - rails.git/blob - test/controllers/api/capabilities_controller_test.rb
Bump eslint from 9.9.0 to 9.9.1
[rails.git] / test / controllers / api / capabilities_controller_test.rb
1 require "test_helper"
2
3 module Api
4   class CapabilitiesControllerTest < ActionDispatch::IntegrationTest
5     ##
6     # test all routes which lead to this controller
7     def test_routes
8       assert_routing(
9         { :path => "/api/capabilities", :method => :get },
10         { :controller => "api/capabilities", :action => "show" }
11       )
12       assert_routing(
13         { :path => "/api/capabilities.json", :method => :get },
14         { :controller => "api/capabilities", :action => "show", :format => "json" }
15       )
16       assert_recognizes(
17         { :controller => "api/capabilities", :action => "show" },
18         { :path => "/api/0.6/capabilities", :method => :get }
19       )
20       assert_recognizes(
21         { :controller => "api/capabilities", :action => "show", :format => "json" },
22         { :path => "/api/0.6/capabilities.json", :method => :get }
23       )
24     end
25
26     def test_capabilities
27       get api_capabilities_path
28       assert_response :success
29       assert_select "osm[version='#{Settings.api_version}'][generator='#{Settings.generator}']", :count => 1 do
30         assert_select "api", :count => 1 do
31           assert_select "version[minimum='#{Settings.api_version}'][maximum='#{Settings.api_version}']", :count => 1
32           assert_select "area[maximum='#{Settings.max_request_area}']", :count => 1
33           assert_select "note_area[maximum='#{Settings.max_note_request_area}']", :count => 1
34           assert_select "tracepoints[per_page='#{Settings.tracepoints_per_page}']", :count => 1
35           assert_select "changesets" \
36                         "[maximum_elements='#{Changeset::MAX_ELEMENTS}']" \
37                         "[default_query_limit='#{Settings.default_changeset_query_limit}']" \
38                         "[maximum_query_limit='#{Settings.max_changeset_query_limit}']", :count => 1
39           assert_select "relationmembers[maximum='#{Settings.max_number_of_relation_members}']", :count => 1
40           assert_select "notes" \
41                         "[default_query_limit='#{Settings.default_note_query_limit}']" \
42                         "[maximum_query_limit='#{Settings.max_note_query_limit}']", :count => 1
43           assert_select "status[database='online']", :count => 1
44           assert_select "status[api='online']", :count => 1
45           assert_select "status[gpx='online']", :count => 1
46         end
47       end
48     end
49
50     def test_capabilities_json
51       get api_capabilities_path, :params => { :format => "json" }
52       assert_response :success
53       js = ActiveSupport::JSON.decode(@response.body)
54       assert_not_nil js
55
56       assert_equal Settings.api_version, js["version"]
57       assert_equal Settings.generator, js["generator"]
58       assert_equal Settings.api_version, js["api"]["version"]["minimum"]
59       assert_equal Settings.api_version, js["api"]["version"]["maximum"]
60       assert_equal Settings.max_request_area, js["api"]["area"]["maximum"]
61       assert_equal Settings.max_note_request_area, js["api"]["note_area"]["maximum"]
62       assert_equal Settings.tracepoints_per_page, js["api"]["tracepoints"]["per_page"]
63       assert_equal Changeset::MAX_ELEMENTS, js["api"]["changesets"]["maximum_elements"]
64       assert_equal Settings.default_changeset_query_limit, js["api"]["changesets"]["default_query_limit"]
65       assert_equal Settings.max_changeset_query_limit, js["api"]["changesets"]["maximum_query_limit"]
66       assert_equal Settings.max_number_of_relation_members, js["api"]["relationmembers"]["maximum"]
67       assert_equal Settings.default_note_query_limit, js["api"]["notes"]["default_query_limit"]
68       assert_equal Settings.max_note_query_limit, js["api"]["notes"]["maximum_query_limit"]
69       assert_equal "online", js["api"]["status"]["database"]
70       assert_equal "online", js["api"]["status"]["api"]
71       assert_equal "online", js["api"]["status"]["gpx"]
72       assert_equal Settings.imagery_blacklist.length, js["policy"]["imagery"]["blacklist"].length
73     end
74
75     def test_capabilities_api_readonly
76       with_settings(:status => "api_readonly") do
77         get api_capabilities_path
78         assert_response :success
79         assert_select "osm[version='#{Settings.api_version}'][generator='#{Settings.generator}']", :count => 1 do
80           assert_select "api", :count => 1 do
81             assert_select "status[database='online']", :count => 1
82             assert_select "status[api='readonly']", :count => 1
83             assert_select "status[gpx='online']", :count => 1
84           end
85         end
86       end
87     end
88
89     def test_capabilities_api_offline
90       with_settings(:status => "api_offline") do
91         get api_capabilities_path
92         assert_response :success
93         assert_select "osm[version='#{Settings.api_version}'][generator='#{Settings.generator}']", :count => 1 do
94           assert_select "api", :count => 1 do
95             assert_select "status[database='online']", :count => 1
96             assert_select "status[api='offline']", :count => 1
97             assert_select "status[gpx='online']", :count => 1
98           end
99         end
100       end
101     end
102
103     def test_capabilities_database_readonly
104       with_settings(:status => "database_readonly") do
105         get api_capabilities_path
106         assert_response :success
107         assert_select "osm[version='#{Settings.api_version}'][generator='#{Settings.generator}']", :count => 1 do
108           assert_select "api", :count => 1 do
109             assert_select "status[database='readonly']", :count => 1
110             assert_select "status[api='readonly']", :count => 1
111             assert_select "status[gpx='readonly']", :count => 1
112           end
113         end
114       end
115     end
116
117     def test_capabilities_database_offline
118       with_settings(:status => "database_offline") do
119         get api_capabilities_path
120         assert_response :success
121         assert_select "osm[version='#{Settings.api_version}'][generator='#{Settings.generator}']", :count => 1 do
122           assert_select "api", :count => 1 do
123             assert_select "status[database='offline']", :count => 1
124             assert_select "status[api='offline']", :count => 1
125             assert_select "status[gpx='offline']", :count => 1
126           end
127         end
128       end
129     end
130
131     def test_capabilities_gpx_offline
132       with_settings(:status => "gpx_offline") do
133         get api_capabilities_path
134         assert_response :success
135         assert_select "osm[version='#{Settings.api_version}'][generator='#{Settings.generator}']", :count => 1 do
136           assert_select "api", :count => 1 do
137             assert_select "status[database='online']", :count => 1
138             assert_select "status[api='online']", :count => 1
139             assert_select "status[gpx='offline']", :count => 1
140           end
141         end
142       end
143     end
144   end
145 end