]> git.openstreetmap.org Git - rails.git/blob - test/controllers/api/permissions_controller_test.rb
Add frozen_string_literal comments to ruby files
[rails.git] / test / controllers / api / permissions_controller_test.rb
1 # frozen_string_literal: true
2
3 require "test_helper"
4
5 module Api
6   class PermissionsControllerTest < ActionDispatch::IntegrationTest
7     ##
8     # test all routes which lead to this controller
9     def test_routes
10       assert_routing(
11         { :path => "/api/0.6/permissions", :method => :get },
12         { :controller => "api/permissions", :action => "show" }
13       )
14       assert_routing(
15         { :path => "/api/0.6/permissions.json", :method => :get },
16         { :controller => "api/permissions", :action => "show", :format => "json" }
17       )
18     end
19
20     def test_permissions_anonymous
21       get api_permissions_path
22       assert_response :success
23       assert_select "osm > permissions", :count => 1 do
24         assert_select "permission", :count => 0
25       end
26
27       # Test json
28       get api_permissions_path(:format => "json")
29       assert_response :success
30       assert_equal "application/json", @response.media_type
31
32       js = ActiveSupport::JSON.decode(@response.body)
33       assert_not_nil js
34       assert_equal 0, js["permissions"].count
35     end
36
37     def test_permissions_oauth2
38       user = create(:user)
39       auth_header = bearer_authorization_header(user, :scopes => %w[read_prefs write_api])
40       get api_permissions_path, :headers => auth_header
41       assert_response :success
42       assert_select "osm > permissions", :count => 1 do
43         assert_select "permission", :count => 2
44         assert_select "permission[name='allow_read_prefs']", :count => 1
45         assert_select "permission[name='allow_write_api']", :count => 1
46         assert_select "permission[name='allow_read_gpx']", :count => 0
47       end
48     end
49   end
50 end