|
@@ -38,27 +38,34 @@ class Api::V1::UsersControllerTest < ActionDispatch::IntegrationTest
|
38
|
38
|
|
39
|
39
|
#UPDATE
|
40
|
40
|
test "should update user" do
|
41
|
|
- patch api_v1_user_url(@user), params: { user: { email: @user.email, username: @user.username, password: '123456' } }, as: :json
|
|
41
|
+ patch api_v1_user_url(@user),
|
|
42
|
+ params: { user: { email: @user.email, password: '123456' } },
|
|
43
|
+ headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
|
|
44
|
+ as: :json
|
42
|
45
|
assert_response :success
|
43
|
46
|
end
|
44
|
47
|
|
45
|
|
- # test "should not update user when invalid params are sent" do
|
46
|
|
- # patch api_v1_user_url(@user), params: { user: { email: 'bad_email', username: @user.username, password: '123456' } }, as: :json
|
47
|
|
- # assert_response :unprocessable_entity
|
48
|
|
- # end
|
|
48
|
+ test "should forbid update user" do
|
|
49
|
+ patch api_v1_user_url(@user),
|
|
50
|
+ params: { user: { email: @user.email, password: '123456' } },
|
|
51
|
+ as: :json
|
|
52
|
+ assert_response :forbidden
|
|
53
|
+ end
|
49
|
54
|
|
50
|
55
|
#DESTROY
|
51
|
56
|
test "should destroy user" do
|
52
|
57
|
assert_difference('User.count', -1) do
|
53
|
|
- delete api_v1_user_url(@user), as: :json
|
|
58
|
+ delete api_v1_user_url(@user),
|
|
59
|
+ headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
|
|
60
|
+ as: :json
|
54
|
61
|
end
|
55
|
62
|
assert_response :no_content
|
56
|
63
|
end
|
57
|
64
|
|
58
|
|
- # test "should forbid destroy user" do
|
59
|
|
- # assert_no_difference('User.count') do
|
60
|
|
- # delete api_v1_user_url(@user), as: :json
|
61
|
|
- # end
|
62
|
|
- # assert_response :forbidden
|
63
|
|
- # end
|
|
65
|
+ test "should forbid destroy user" do
|
|
66
|
+ assert_no_difference('User.count') do
|
|
67
|
+ delete api_v1_user_url(@user), as: :json
|
|
68
|
+ end
|
|
69
|
+ assert_response :forbidden
|
|
70
|
+ end
|
64
|
71
|
end
|