|
@@ -3,11 +3,27 @@ require "test_helper"
|
3
|
3
|
class Api::V1::UsersControllerTest < ActionDispatch::IntegrationTest
|
4
|
4
|
setup do
|
5
|
5
|
@user = users(:one)
|
|
6
|
+ @admin = users(:admin)
|
|
7
|
+ end
|
|
8
|
+
|
|
9
|
+ # INDEX
|
|
10
|
+ test "should access index user" do
|
|
11
|
+ get api_v1_users_url,
|
|
12
|
+ headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
|
|
13
|
+ as: :json
|
|
14
|
+ assert_response :success
|
|
15
|
+ end
|
|
16
|
+
|
|
17
|
+ test "should forbid index user" do
|
|
18
|
+ get api_v1_users_url, as: :json
|
|
19
|
+ assert_response :forbidden
|
6
|
20
|
end
|
7
|
21
|
|
8
|
22
|
#SHOW
|
9
|
23
|
test "should show user" do
|
10
|
|
- get api_v1_user_url(@user), as: :json
|
|
24
|
+ get api_v1_user_url(@user),
|
|
25
|
+ headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
|
|
26
|
+ as: :json
|
11
|
27
|
assert_response :success
|
12
|
28
|
# Test to ensure response contains the correct email
|
13
|
29
|
|
|
@@ -16,6 +32,12 @@ class Api::V1::UsersControllerTest < ActionDispatch::IntegrationTest
|
16
|
32
|
assert_equal @user.username, json_response.dig(:data, :attributes, :username)
|
17
|
33
|
end
|
18
|
34
|
|
|
35
|
+ test "should not show user" do
|
|
36
|
+ get api_v1_user_url(@user),
|
|
37
|
+ as: :json
|
|
38
|
+ assert_response :forbidden
|
|
39
|
+ end
|
|
40
|
+
|
19
|
41
|
#CREATE
|
20
|
42
|
test "should create user" do
|
21
|
43
|
assert_difference('User.count') do
|