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 => bearer_authorization_header(blocked_user)
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 => bearer_authorization_header(blocked_user)
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 => bearer_authorization_header(blocked_user)
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 => bearer_authorization_header(blocked_user)
57 assert_response :success