3 class UserBlocksTest < ActionDispatch::IntegrationTest
4 def auth_header(user, pass)
5 { "HTTP_AUTHORIZATION" => format("Basic %{auth}", :auth => Base64.encode64("#{user}:#{pass}")) }
9 blocked_user = create(:user)
11 get "/api/#{API_VERSION}/user/details"
12 assert_response :unauthorized
14 get "/api/#{API_VERSION}/user/details", :headers => auth_header(blocked_user.display_name, "test")
15 assert_response :success
19 :user_id => blocked_user.id,
20 :creator_id => create(:moderator_user).id,
22 :ends_at => Time.now.getutc + 5.minutes
24 get "/api/#{API_VERSION}/user/details", :headers => auth_header(blocked_user.display_name, "test")
25 assert_response :forbidden
29 blocked_user = create(:user)
30 moderator = create(:moderator_user)
32 block = UserBlock.create(
33 :user_id => blocked_user.id,
34 :creator_id => moderator.id,
36 :ends_at => Time.now.getutc + 5.minutes
38 get "/api/#{API_VERSION}/user/details", :headers => auth_header(blocked_user.display_name, "test")
39 assert_response :forbidden
43 assert_response :success
44 post "/login", :params => { "username" => moderator.email, "password" => "test", :referer => "/blocks/#{block.id}/revoke" }
45 assert_response :redirect
47 assert_response :success
48 assert_template "user_blocks/revoke"
49 post "/blocks/#{block.id}/revoke", :params => { "confirm" => "yes" }
50 assert_response :redirect
52 assert_response :success
53 assert_template "user_blocks/show"
56 # access the API again. this time it should work
57 get "/api/#{API_VERSION}/user/details", :headers => auth_header(blocked_user.display_name, "test")
58 assert_response :success