|
5 | 5 | package integration |
6 | 6 |
|
7 | 7 | import ( |
| 8 | + "fmt" |
8 | 9 | "net/http" |
9 | 10 | "net/url" |
10 | 11 | "strings" |
@@ -151,3 +152,38 @@ func TestAPIGetAll(t *testing.T) { |
151 | 152 | assert.Equal(t, "org25", apiOrgList[0].FullName) |
152 | 153 | assert.Equal(t, "public", apiOrgList[0].Visibility) |
153 | 154 | } |
| 155 | + |
| 156 | +func TestAPIOrgSearchEmptyTeam(t *testing.T) { |
| 157 | + onGiteaRun(t, func(*testing.T, *url.URL) { |
| 158 | + token := getUserToken(t, "user1") |
| 159 | + orgName := "org_with_empty_team" |
| 160 | + |
| 161 | + // create org |
| 162 | + req := NewRequestWithJSON(t, "POST", "/api/v1/orgs?token="+token, &api.CreateOrgOption{ |
| 163 | + UserName: orgName, |
| 164 | + }) |
| 165 | + MakeRequest(t, req, http.StatusCreated) |
| 166 | + |
| 167 | + // create team with no member |
| 168 | + req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/orgs/%s/teams?token=%s", orgName, token), &api.CreateTeamOption{ |
| 169 | + Name: "Empty", |
| 170 | + IncludesAllRepositories: true, |
| 171 | + Permission: "read", |
| 172 | + Units: []string{"repo.code", "repo.issues", "repo.ext_issues", "repo.wiki", "repo.pulls"}, |
| 173 | + }) |
| 174 | + MakeRequest(t, req, http.StatusCreated) |
| 175 | + |
| 176 | + // case-insensitive search for teams that have no members |
| 177 | + req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/orgs/%s/teams/search?q=%s&token=%s", orgName, "empty", token)) |
| 178 | + resp := MakeRequest(t, req, http.StatusOK) |
| 179 | + data := struct { |
| 180 | + Ok bool |
| 181 | + Data []*api.Team |
| 182 | + }{} |
| 183 | + DecodeJSON(t, resp, &data) |
| 184 | + assert.True(t, data.Ok) |
| 185 | + if assert.Len(t, data.Data, 1) { |
| 186 | + assert.EqualValues(t, "Empty", data.Data[0].Name) |
| 187 | + } |
| 188 | + }) |
| 189 | +} |
0 commit comments