|
@@ -27,7 +27,6 @@ class Api::V1::TeamsControllerTest < ActionDispatch::IntegrationTest
|
27
|
27
|
assert_response :success
|
28
|
28
|
end
|
29
|
29
|
|
30
|
|
- # SHOW
|
31
|
30
|
test "should forbid show team" do
|
32
|
31
|
get api_v1_team_url(@team),
|
33
|
32
|
as: :json
|
|
@@ -37,30 +36,77 @@ class Api::V1::TeamsControllerTest < ActionDispatch::IntegrationTest
|
37
|
36
|
# CREATE
|
38
|
37
|
test "should create team" do
|
39
|
38
|
assert_difference('Team.count') do
|
40
|
|
- post api_v1_teams_url, params: { team: { name: "Random name", description: "Random description" } }, headers: { Authorization: JsonWebToken.encode(user_id: @user.id) }, as: :json
|
|
39
|
+ post api_v1_teams_url,
|
|
40
|
+ params: { team: { name: "Random name", description: "Random description" } },
|
|
41
|
+ headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
|
|
42
|
+ as: :json
|
41
|
43
|
end
|
42
|
44
|
assert_response :created
|
43
|
45
|
end
|
44
|
46
|
|
45
|
|
- test "should not create team when not logged in" do
|
|
47
|
+ test "should forbid create team when not logged in" do
|
46
|
48
|
assert_no_difference('Team.count') do
|
47
|
|
- post api_v1_teams_url, params: { team: { name: "Random name", description: "Random description" } }, as: :json
|
|
49
|
+ post api_v1_teams_url,
|
|
50
|
+ params: { team: { name: "Random name", description: "Random description" } },
|
|
51
|
+ as: :json
|
48
|
52
|
end
|
49
|
53
|
assert_response :forbidden
|
50
|
54
|
end
|
51
|
55
|
|
52
|
|
- test "should not create team with taken name" do
|
|
56
|
+ test "should forbid create team with taken name" do
|
53
|
57
|
assert_no_difference('Team.count') do
|
54
|
|
- post api_v1_teams_url, params: { team: { name: @team.name, description: "Random description" } }, headers: { Authorization: JsonWebToken.encode(user_id: @user.id) }, as: :json
|
|
58
|
+ post api_v1_teams_url,
|
|
59
|
+ params: { team: { name: @team.name, description: "Random description" } },
|
|
60
|
+ headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
|
|
61
|
+ as: :json
|
55
|
62
|
end
|
56
|
63
|
assert_response :unprocessable_entity
|
57
|
64
|
end
|
58
|
65
|
|
59
|
|
- test "should not create team without name" do
|
|
66
|
+ test "should forbid create a team without name" do
|
60
|
67
|
assert_no_difference('Team.count') do
|
61
|
|
- post api_v1_teams_url, params: { team: { description: "Random description"} }, headers: { Authorization: JsonWebToken.encode(user_id: @user.id) }, as: :json
|
|
68
|
+ post api_v1_teams_url,
|
|
69
|
+ params: { team: { description: "Random description"} },
|
|
70
|
+ headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
|
|
71
|
+ as: :json
|
62
|
72
|
end
|
63
|
73
|
assert_response :unprocessable_entity
|
64
|
74
|
end
|
65
|
75
|
|
|
76
|
+ # UPDATE
|
|
77
|
+ test "should update team" do
|
|
78
|
+ patch api_v1_team_url(@team),
|
|
79
|
+ params: { team: { name: "New name", description: "New description" } },
|
|
80
|
+ headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
|
|
81
|
+ as: :json
|
|
82
|
+ assert_response :success
|
|
83
|
+ end
|
|
84
|
+
|
|
85
|
+ test "should not update team " do
|
|
86
|
+ patch api_v1_team_url(@team),
|
|
87
|
+ params: { team: { name: "New name", description: "New description" } },
|
|
88
|
+ as: :json
|
|
89
|
+ assert_response :forbidden
|
|
90
|
+ end
|
|
91
|
+
|
|
92
|
+ # Ajouter un test pour vérifier le statut de "current_user.can_edit" dans le modèle JoinedTeamUser
|
|
93
|
+
|
|
94
|
+ # DESTROY
|
|
95
|
+ test "should destroy team" do
|
|
96
|
+ assert_difference('Team.count', -1) do
|
|
97
|
+ delete api_v1_team_url(@team),
|
|
98
|
+ headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
|
|
99
|
+ as: :json
|
|
100
|
+ end
|
|
101
|
+ assert_response :no_content
|
|
102
|
+ end
|
|
103
|
+
|
|
104
|
+ test "should forbid destroy team" do
|
|
105
|
+ assert_no_difference('Team.count') do
|
|
106
|
+ delete api_v1_team_url(@team), as: :json
|
|
107
|
+ end
|
|
108
|
+ assert_response :forbidden
|
|
109
|
+ end
|
|
110
|
+ # Ajouter un test pour vérifier le statut de "current_user.can_edit" dans le modèle JoinedTeamUser
|
|
111
|
+
|
66
|
112
|
end
|