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.getutc + 5.minutes
20 get "/api/#{Settings.api_version}/user/details", :headers => basic_authorization_header(blocked_user.display_name, "test")
21 assert_response :forbidden
25 blocked_user = create(:user)
26 moderator = create(:moderator_user)
28 block = UserBlock.create(
29 :user_id => blocked_user.id,
30 :creator_id => moderator.id,
32 :ends_at => Time.now.getutc + 5.minutes
34 get "/api/#{Settings.api_version}/user/details", :headers => basic_authorization_header(blocked_user.display_name, "test")
35 assert_response :forbidden
39 assert_response :success
40 post "/login", :params => { "username" => moderator.email, "password" => "test", :referer => "/blocks/#{block.id}/revoke" }
41 assert_response :redirect
43 assert_response :success
44 assert_template "user_blocks/revoke"
45 post "/blocks/#{block.id}/revoke", :params => { "confirm" => "yes" }
46 assert_response :redirect
48 assert_response :success
49 assert_template "user_blocks/show"
52 # access the API again. this time it should work
53 get "/api/#{Settings.api_version}/user/details", :headers => basic_authorization_header(blocked_user.display_name, "test")
54 assert_response :success