]> git.openstreetmap.org Git - rails.git/blob - test/controllers/api/user_blocks/active_lists_controller_test.rb
Add active blocks list api endpoint with empty response
[rails.git] / test / controllers / api / user_blocks / active_lists_controller_test.rb
1 require "test_helper"
2
3 module Api
4   module UserBlocks
5     class ActiveListsControllerTest < ActionDispatch::IntegrationTest
6       ##
7       # test all routes which lead to this controller
8       def test_routes
9         assert_routing(
10           { :path => "/api/0.6/user/blocks/active", :method => :get },
11           { :controller => "api/user_blocks/active_lists", :action => "show" }
12         )
13         assert_routing(
14           { :path => "/api/0.6/user/blocks/active.json", :method => :get },
15           { :controller => "api/user_blocks/active_lists", :action => "show", :format => "json" }
16         )
17       end
18
19       def test_show_no_auth_header
20         get api_user_blocks_active_list_path
21         assert_response :unauthorized
22       end
23
24       def test_show_no_permission
25         user = create(:user)
26         user_auth_header = bearer_authorization_header(user, :scopes => %w[])
27
28         get api_user_blocks_active_list_path, :headers => user_auth_header
29         assert_response :forbidden
30       end
31
32       def test_show_empty
33         user = create(:user)
34         user_auth_header = bearer_authorization_header(user, :scopes => %w[read_prefs])
35         create(:user_block, :expired, :user => user)
36
37         get api_user_blocks_active_list_path, :headers => user_auth_header
38         assert_response :success
39         assert_dom "user_block", :count => 0
40       end
41     end
42   end
43 end