|
@@ -10,29 +10,39 @@ class Api::V1::MembershipsControllerTest < ActionDispatch::IntegrationTest
|
10
|
10
|
end
|
11
|
11
|
|
12
|
12
|
# INDEX
|
13
|
|
- test "should access Membership index" do
|
14
|
|
- get api_v1_memberships_url,
|
|
13
|
+ test "should access Membership index - specifix team" do
|
|
14
|
+ get api_v1_team_memberships_url(@team),
|
15
|
15
|
headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
|
16
|
16
|
as: :json
|
17
|
17
|
assert_response :success
|
|
18
|
+
|
|
19
|
+ json_response = JSON.parse(self.response.body)
|
|
20
|
+ assert_equal @membership.member_id, json_response['data'][0]['attributes']['member_id']
|
18
|
21
|
end
|
19
|
22
|
|
20
|
|
- test "should forbid Membership index" do
|
|
23
|
+ test "should access Membership index - all teams" do
|
21
|
24
|
get api_v1_memberships_url,
|
|
25
|
+ headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
|
|
26
|
+ as: :json
|
|
27
|
+ assert_response :success
|
|
28
|
+ end
|
|
29
|
+
|
|
30
|
+ test "should not access Membership index" do
|
|
31
|
+ get api_v1_team_memberships_url(@team),
|
22
|
32
|
as: :json
|
23
|
33
|
assert_response :forbidden
|
24
|
34
|
end
|
25
|
35
|
|
26
|
36
|
# SHOW
|
27
|
37
|
test "should show Membership" do
|
28
|
|
- get api_v1_memberships_url(@membership),
|
|
38
|
+ get api_v1_team_memberships_url(@team, @membership),
|
29
|
39
|
headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
|
30
|
40
|
as: :json
|
31
|
41
|
assert_response :success
|
32
|
42
|
end
|
33
|
43
|
|
34
|
44
|
test "should forbid show Membership" do
|
35
|
|
- get api_v1_memberships_url(@membership),
|
|
45
|
+ get api_v1_team_memberships_url(@team, @membership),
|
36
|
46
|
as: :json
|
37
|
47
|
assert_response :forbidden
|
38
|
48
|
end
|
|
@@ -41,60 +51,60 @@ class Api::V1::MembershipsControllerTest < ActionDispatch::IntegrationTest
|
41
|
51
|
# test "should create membership" do
|
42
|
52
|
# assert_difference("Membership.count") do
|
43
|
53
|
# post api_v1_memberships_url,
|
44
|
|
- # params: { membership: { team_id: @team.id, member_id: @user.id, can_edit: false } },
|
|
54
|
+ # params: { membership: { team_id: @team2.id, member_id: @user2.id, can_edit: false } },
|
45
|
55
|
# headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
|
46
|
56
|
# as: :json
|
47
|
57
|
# end
|
48
|
58
|
# assert_response :created
|
49
|
59
|
# end
|
50
|
60
|
|
51
|
|
- test "should forbid create membership" do
|
52
|
|
- assert_no_difference("Membership.count") do
|
53
|
|
- post api_v1_memberships_url,
|
54
|
|
- params: { membership: { team_id: @team.id, member_id: @user.id, can_edit: false } },
|
55
|
|
- as: :json
|
56
|
|
- end
|
57
|
|
- assert_response :forbidden
|
58
|
|
- end
|
|
61
|
+ # test "should forbid create membership" do
|
|
62
|
+ # assert_no_difference("Membership.count") do
|
|
63
|
+ # post api_v1_memberships_url,
|
|
64
|
+ # params: { membership: { team_id: @team.id, member_id: @user.id, can_edit: false } },
|
|
65
|
+ # as: :json
|
|
66
|
+ # end
|
|
67
|
+ # assert_response :forbidden
|
|
68
|
+ # end
|
59
|
69
|
|
60
|
|
- # UPDATE
|
61
|
|
- test "should update membership" do
|
62
|
|
- patch api_v1_membership_url(@membership),
|
63
|
|
- headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
|
64
|
|
- params: { membership: { can_edit: true } },
|
65
|
|
- as: :json
|
66
|
|
- assert_response :success
|
67
|
|
- end
|
|
70
|
+ # # UPDATE
|
|
71
|
+ # test "should update membership" do
|
|
72
|
+ # patch api_v1_membership_url(@membership),
|
|
73
|
+ # headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
|
|
74
|
+ # params: { membership: { can_edit: true } },
|
|
75
|
+ # as: :json
|
|
76
|
+ # assert_response :success
|
|
77
|
+ # end
|
68
|
78
|
|
69
|
|
- test "should forbid update membership" do
|
70
|
|
- patch api_v1_membership_url(@membership),
|
71
|
|
- params: { membership: { can_edit: true } },
|
72
|
|
- as: :json
|
73
|
|
- assert_response :forbidden
|
74
|
|
- end
|
|
79
|
+ # test "should forbid update membership" do
|
|
80
|
+ # patch api_v1_membership_url(@membership),
|
|
81
|
+ # params: { membership: { can_edit: true } },
|
|
82
|
+ # as: :json
|
|
83
|
+ # assert_response :forbidden
|
|
84
|
+ # end
|
75
|
85
|
|
76
|
|
- test "should forbid update read_only attributes - team_id" do
|
77
|
|
- patch api_v1_membership_url(@membership),
|
78
|
|
- headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
|
79
|
|
- params: { membership: { team_id: @team2.id, member_id: @user2.id } },
|
80
|
|
- as: :json
|
81
|
|
- assert_response :unprocessable_entity
|
82
|
|
- end
|
|
86
|
+ # test "should forbid update read_only attributes - team_id" do
|
|
87
|
+ # patch api_v1_membership_url(@membership),
|
|
88
|
+ # headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
|
|
89
|
+ # params: { membership: { team_id: @team2.id, member_id: @user2.id } },
|
|
90
|
+ # as: :json
|
|
91
|
+ # assert_response :unprocessable_entity
|
|
92
|
+ # end
|
83
|
93
|
|
84
|
|
- # DESTROY
|
85
|
|
- test "should destroy membership" do
|
86
|
|
- assert_difference('Membership.count', -1) do
|
87
|
|
- delete api_v1_membership_url(@membership),
|
88
|
|
- headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
|
89
|
|
- as: :json
|
90
|
|
- end
|
91
|
|
- assert_response :no_content
|
92
|
|
- end
|
|
94
|
+ # # DESTROY
|
|
95
|
+ # test "should destroy membership" do
|
|
96
|
+ # assert_difference('Membership.count', -1) do
|
|
97
|
+ # delete api_v1_membership_url(@membership),
|
|
98
|
+ # headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
|
|
99
|
+ # as: :json
|
|
100
|
+ # end
|
|
101
|
+ # assert_response :no_content
|
|
102
|
+ # end
|
93
|
103
|
|
94
|
|
- test "should forbid destroy membership" do
|
95
|
|
- assert_no_difference('Membership.count') do
|
96
|
|
- delete api_v1_membership_url(@membership), as: :json
|
97
|
|
- end
|
98
|
|
- assert_response :forbidden
|
99
|
|
- end
|
|
104
|
+ # test "should forbid destroy membership" do
|
|
105
|
+ # assert_no_difference('Membership.count') do
|
|
106
|
+ # delete api_v1_membership_url(@membership), as: :json
|
|
107
|
+ # end
|
|
108
|
+ # assert_response :forbidden
|
|
109
|
+ # end
|
100
|
110
|
end
|