]> git.openstreetmap.org Git - rails.git/blob - test/controllers/api/capabilities_controller_test.rb
Invert trace images in dark mode
[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   end
75 end