|
@@ -4,7 +4,9 @@ class Api::V1::MembershipsControllerTest < ActionDispatch::IntegrationTest
|
4
|
4
|
setup do
|
5
|
5
|
@membership = memberships(:one)
|
6
|
6
|
@user = users(:one)
|
|
7
|
+ @user2 = users(:two)
|
7
|
8
|
@team = teams(:one)
|
|
9
|
+ @team2 = teams(:two)
|
8
|
10
|
end
|
9
|
11
|
|
10
|
12
|
# INDEX
|
|
@@ -45,7 +47,6 @@ class Api::V1::MembershipsControllerTest < ActionDispatch::IntegrationTest
|
45
|
47
|
# end
|
46
|
48
|
# assert_response :created
|
47
|
49
|
# end
|
48
|
|
-
|
49
|
50
|
|
50
|
51
|
test "should forbid create membership" do
|
51
|
52
|
assert_no_difference("Membership.count") do
|
|
@@ -55,4 +56,53 @@ class Api::V1::MembershipsControllerTest < ActionDispatch::IntegrationTest
|
55
|
56
|
end
|
56
|
57
|
assert_response :forbidden
|
57
|
58
|
end
|
|
59
|
+
|
|
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
|
|
68
|
+
|
|
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
|
|
75
|
+
|
|
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 } },
|
|
80
|
+ # as: :json
|
|
81
|
+ # assert_response :unprocessable_entity
|
|
82
|
+ # end
|
|
83
|
+
|
|
84
|
+ # test "should forbid update read_only attributes - member_id" do
|
|
85
|
+ # patch api_v1_membership_url(@membership),
|
|
86
|
+ # headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
|
|
87
|
+ # params: { membership: { member_id: @user2.id } },
|
|
88
|
+ # as: :json
|
|
89
|
+ # assert_response :unprocessable_entity
|
|
90
|
+ # end
|
|
91
|
+
|
|
92
|
+ # DESTROY
|
|
93
|
+ test "should destroy membership" do
|
|
94
|
+ assert_difference('Membership.count', -1) do
|
|
95
|
+ delete api_v1_membership_url(@membership),
|
|
96
|
+ headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
|
|
97
|
+ as: :json
|
|
98
|
+ end
|
|
99
|
+ assert_response :no_content
|
|
100
|
+ end
|
|
101
|
+
|
|
102
|
+ test "should forbid destroy membership" do
|
|
103
|
+ assert_no_difference('Membership.count') do
|
|
104
|
+ delete api_v1_membership_url(@membership), as: :json
|
|
105
|
+ end
|
|
106
|
+ assert_response :forbidden
|
|
107
|
+ end
|
58
|
108
|
end
|