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 => "/user_blocks/#{block.id}/edit" }
43 assert_response :redirect
45 assert_response :success
46 assert_template "user_blocks/edit"
47 put "/user_blocks/#{block.id}", :params => { :user_block_period => "0",
48 :user_block => { :needs_view => false, :reason => "Unblocked" } }
49 assert_response :redirect
51 assert_response :success
52 assert_template "user_blocks/show"
55 # access the API again. this time it should work
56 get "/api/#{Settings.api_version}/user/details", :headers => basic_authorization_header(blocked_user.display_name, "test")
57 assert_response :success