You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

api_pull_commits_test.go 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright 2021 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. package integrations
  5. import (
  6. "net/http"
  7. "testing"
  8. "code.gitea.io/gitea/models"
  9. repo_model "code.gitea.io/gitea/models/repo"
  10. "code.gitea.io/gitea/models/unittest"
  11. api "code.gitea.io/gitea/modules/structs"
  12. "github.com/stretchr/testify/assert"
  13. )
  14. func TestAPIPullCommits(t *testing.T) {
  15. defer prepareTestEnv(t)()
  16. pullIssue := unittest.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 2}).(*models.PullRequest)
  17. assert.NoError(t, pullIssue.LoadIssue())
  18. repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: pullIssue.HeadRepoID}).(*repo_model.Repository)
  19. session := loginUser(t, "user2")
  20. req := NewRequestf(t, http.MethodGet, "/api/v1/repos/%s/%s/pulls/%d/commits", repo.OwnerName, repo.Name, pullIssue.Index)
  21. resp := session.MakeRequest(t, req, http.StatusOK)
  22. var commits []*api.Commit
  23. DecodeJSON(t, resp, &commits)
  24. if !assert.Len(t, commits, 2) {
  25. return
  26. }
  27. assert.Equal(t, "5f22f7d0d95d614d25a5b68592adb345a4b5c7fd", commits[0].SHA)
  28. assert.Equal(t, "4a357436d925b5c974181ff12a994538ddc5a269", commits[1].SHA)
  29. }
  30. // TODO add tests for already merged PR and closed PR