3 class UserBlocksTest < ActionDispatch::IntegrationTest
5 blocked_user = create(:user)
7 get "/api/#{Settings.api_version}/user/details"
8 assert_response :unauthorized
10 get "/api/#{Settings.api_version}/user/details", :headers => basic_authorization_header(blocked_user.display_name, "test")
11 assert_response :success
15 :user_id => blocked_user.id,
16 :creator_id => create(:moderator_user).id,
18 :ends_at => Time.now.utc + 5.minutes,
19 :deactivates_at => Time.now.utc + 5.minutes
21 get "/api/#{Settings.api_version}/user/details", :headers => basic_authorization_header(blocked_user.display_name, "test")
22 assert_response :forbidden
26 blocked_user = create(:user)
27 moderator = create(:moderator_user)
29 block = UserBlock.create(
30 :user_id => blocked_user.id,
31 :creator_id => moderator.id,
33 :ends_at => Time.now.utc + 5.minutes,
34 :deactivates_at => Time.now.utc + 5.minutes
36 get "/api/#{Settings.api_version}/user/details", :headers => basic_authorization_header(blocked_user.display_name, "test")
37 assert_response :forbidden
41 assert_response :success
42 post "/login", :params => { "username" => moderator.email, "password" => "test", :referer => "/blocks/#{block.id}/revoke" }
43 assert_response :redirect
45 assert_response :success
46 assert_template "user_blocks/revoke"
47 post "/blocks/#{block.id}/revoke", :params => { "confirm" => "yes" }
48 assert_response :redirect
50 assert_response :success
51 assert_template "user_blocks/show"
54 # access the API again. this time it should work
55 get "/api/#{Settings.api_version}/user/details", :headers => basic_authorization_header(blocked_user.display_name, "test")
56 assert_response :success