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

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