Skip to content

Commit 47278ad

Browse files
committed
added collaborator test
1 parent ace2e37 commit 47278ad

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

routers/repo/settings_test.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"code.gitea.io/gitea/models"
1212
"code.gitea.io/gitea/modules/auth"
13+
"code.gitea.io/gitea/modules/context"
1314
"code.gitea.io/gitea/modules/test"
1415

1516
"github.com/stretchr/testify/assert"
@@ -59,3 +60,64 @@ func TestAddReadWriteOnlyDeployKey(t *testing.T) {
5960
Mode: models.AccessModeWrite,
6061
})
6162
}
63+
64+
func TestCollaborationPost(t *testing.T) {
65+
66+
models.PrepareTestEnv(t)
67+
ctx := test.MockContext(t, "user2/repo1/issues/labels")
68+
test.LoadUser(t, ctx, 2)
69+
test.LoadUser(t, ctx, 4)
70+
test.LoadRepo(t, ctx, 1)
71+
72+
ctx.Req.Form.Set("collaborator", "user4")
73+
74+
u := &models.User{
75+
LowerName: "user2",
76+
Type: models.UserTypeIndividual,
77+
}
78+
79+
re := &models.Repository{
80+
ID: 2,
81+
Owner: u,
82+
}
83+
84+
repo := &context.Repository{
85+
Owner: u,
86+
Repository: re,
87+
}
88+
89+
ctx.Repo = repo
90+
91+
CollaborationPost(ctx)
92+
93+
assert.EqualValues(t, http.StatusFound, ctx.Resp.Status())
94+
95+
exists, err := re.IsCollaborator(4)
96+
assert.NoError(t, err)
97+
assert.True(t, exists)
98+
}
99+
100+
func TestCollaborationPost_InactiveUser(t *testing.T) {
101+
102+
models.PrepareTestEnv(t)
103+
ctx := test.MockContext(t, "user2/repo1/issues/labels")
104+
test.LoadUser(t, ctx, 2)
105+
test.LoadUser(t, ctx, 9)
106+
test.LoadRepo(t, ctx, 1)
107+
108+
ctx.Req.Form.Set("collaborator", "user9")
109+
110+
repo := &context.Repository{
111+
Owner: &models.User{
112+
LowerName: "user2",
113+
},
114+
}
115+
116+
ctx.Repo = repo
117+
118+
CollaborationPost(ctx)
119+
120+
assert.EqualValues(t, http.StatusFound, ctx.Resp.Status())
121+
assert.NotEmpty(t, ctx.Flash.ErrorMsg)
122+
123+
}

0 commit comments

Comments
 (0)