code.gitea.io/gitea@v1.21.7/tests/integration/api_pull_commits_test.go (about)

     1  // Copyright 2021 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package integration
     5  
     6  import (
     7  	"net/http"
     8  	"testing"
     9  
    10  	"code.gitea.io/gitea/models/db"
    11  	issues_model "code.gitea.io/gitea/models/issues"
    12  	repo_model "code.gitea.io/gitea/models/repo"
    13  	"code.gitea.io/gitea/models/unittest"
    14  	api "code.gitea.io/gitea/modules/structs"
    15  	"code.gitea.io/gitea/tests"
    16  
    17  	"github.com/stretchr/testify/assert"
    18  )
    19  
    20  func TestAPIPullCommits(t *testing.T) {
    21  	defer tests.PrepareTestEnv(t)()
    22  	pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2})
    23  	assert.NoError(t, pr.LoadIssue(db.DefaultContext))
    24  	repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: pr.HeadRepoID})
    25  
    26  	req := NewRequestf(t, http.MethodGet, "/api/v1/repos/%s/%s/pulls/%d/commits", repo.OwnerName, repo.Name, pr.Index)
    27  	resp := MakeRequest(t, req, http.StatusOK)
    28  
    29  	var commits []*api.Commit
    30  	DecodeJSON(t, resp, &commits)
    31  
    32  	if !assert.Len(t, commits, 2) {
    33  		return
    34  	}
    35  
    36  	assert.Equal(t, "5f22f7d0d95d614d25a5b68592adb345a4b5c7fd", commits[0].SHA)
    37  	assert.Equal(t, "4a357436d925b5c974181ff12a994538ddc5a269", commits[1].SHA)
    38  
    39  	assert.NotEmpty(t, commits[0].Files)
    40  	assert.NotEmpty(t, commits[1].Files)
    41  	assert.NotNil(t, commits[0].RepoCommit.Verification)
    42  	assert.NotNil(t, commits[1].RepoCommit.Verification)
    43  }
    44  
    45  // TODO add tests for already merged PR and closed PR