|
| 1 | +// Copyright 2017 The Gitea Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a MIT-style |
| 3 | +// license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +package integrations |
| 6 | + |
| 7 | +import ( |
| 8 | + "net/http" |
| 9 | + "testing" |
| 10 | + |
| 11 | + "code.gitea.io/gitea/models" |
| 12 | + api "code.gitea.io/sdk/gitea" |
| 13 | + |
| 14 | + "fmt" |
| 15 | + "github.com/stretchr/testify/assert" |
| 16 | +) |
| 17 | + |
| 18 | +func TestAPIListIssues(t *testing.T) { |
| 19 | + prepareTestEnv(t) |
| 20 | + |
| 21 | + repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) |
| 22 | + owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User) |
| 23 | + |
| 24 | + session := loginUser(t, owner.Name) |
| 25 | + req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues?state=all", |
| 26 | + owner.Name, repo.Name) |
| 27 | + resp := session.MakeRequest(t, req) |
| 28 | + assert.EqualValues(t, http.StatusOK, resp.HeaderCode) |
| 29 | + var apiIssues []*api.Issue |
| 30 | + DecodeJSON(t, resp, &apiIssues) |
| 31 | + assert.Len(t, apiIssues, models.GetCount(t, &models.Issue{RepoID: repo.ID})) |
| 32 | + for _, apiIssue := range apiIssues { |
| 33 | + models.AssertExistsAndLoadBean(t, &models.Issue{ID: apiIssue.ID, RepoID: repo.ID}) |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +func TestAPICreateIssue(t *testing.T) { |
| 38 | + prepareTestEnv(t) |
| 39 | + const body, title = "apiTestBody", "apiTestTitle" |
| 40 | + |
| 41 | + repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) |
| 42 | + owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User) |
| 43 | + |
| 44 | + session := loginUser(t, owner.Name) |
| 45 | + |
| 46 | + urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues?state=all", owner.Name, repo.Name) |
| 47 | + req := NewRequestWithJSON(t, "POST", urlStr, &api.CreateIssueOption{ |
| 48 | + Body: body, |
| 49 | + Title: title, |
| 50 | + Assignee: owner.Name, |
| 51 | + }) |
| 52 | + resp := session.MakeRequest(t, req) |
| 53 | + assert.EqualValues(t, http.StatusCreated, resp.HeaderCode) |
| 54 | + var apiIssue api.Issue |
| 55 | + DecodeJSON(t, resp, &apiIssue) |
| 56 | + assert.Equal(t, apiIssue.Body, body) |
| 57 | + assert.Equal(t, apiIssue.Title, title) |
| 58 | + |
| 59 | + models.AssertExistsAndLoadBean(t, &models.Issue{ |
| 60 | + RepoID: repo.ID, |
| 61 | + AssigneeID: owner.ID, |
| 62 | + Content: body, |
| 63 | + Title: title, |
| 64 | + }) |
| 65 | +} |
0 commit comments