Skip to content

Commit 618dabd

Browse files
committed
Added tests to make sure a collaborator cannot be added twice
1 parent 61cb9b9 commit 618dabd

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

routers/repo/settings_test.go

+24-6
Original file line numberDiff line numberDiff line change
@@ -97,26 +97,44 @@ func TestCollaborationPost(t *testing.T) {
9797
assert.True(t, exists)
9898
}
9999

100-
func TestCollaborationPost_InactiveUser(t *testing.T) {
100+
func TestCollaborationPost_AddCollaboratorTwice(t *testing.T) {
101101

102102
models.PrepareTestEnv(t)
103103
ctx := test.MockContext(t, "user2/repo1/issues/labels")
104104
test.LoadUser(t, ctx, 2)
105-
test.LoadUser(t, ctx, 9)
105+
test.LoadUser(t, ctx, 4)
106106
test.LoadRepo(t, ctx, 1)
107107

108-
ctx.Req.Form.Set("collaborator", "user9")
108+
ctx.Req.Form.Set("collaborator", "user4")
109+
110+
u := &models.User{
111+
LowerName: "user2",
112+
Type: models.UserTypeIndividual,
113+
}
114+
115+
re := &models.Repository{
116+
ID: 2,
117+
Owner: u,
118+
}
109119

110120
repo := &context.Repository{
111-
Owner: &models.User{
112-
LowerName: "user2",
113-
},
121+
Owner: u,
122+
Repository: re,
114123
}
115124

116125
ctx.Repo = repo
117126

118127
CollaborationPost(ctx)
119128

129+
assert.EqualValues(t, http.StatusFound, ctx.Resp.Status())
130+
131+
exists, err := re.IsCollaborator(4)
132+
assert.NoError(t, err)
133+
assert.True(t, exists)
134+
135+
// Try adding the same collaborator again
136+
CollaborationPost(ctx)
137+
120138
assert.EqualValues(t, http.StatusFound, ctx.Resp.Status())
121139
assert.NotEmpty(t, ctx.Flash.ErrorMsg)
122140
}

0 commit comments

Comments
 (0)