|
| 1 | +// Copyright 2024 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 | + auth_model "code.gitea.io/gitea/models/auth" |
| 11 | + "code.gitea.io/gitea/models/unittest" |
| 12 | + user_model "code.gitea.io/gitea/models/user" |
| 13 | + "code.gitea.io/gitea/modules/setting" |
| 14 | + api "code.gitea.io/gitea/modules/structs" |
| 15 | + "code.gitea.io/gitea/tests" |
| 16 | + "github.com/stretchr/testify/assert" |
| 17 | +) |
| 18 | + |
| 19 | +func TestAPICompareTag(t *testing.T) { |
| 20 | + defer tests.PrepareTestEnv(t)() |
| 21 | + |
| 22 | + user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) |
| 23 | + // Login as User2. |
| 24 | + session := loginUser(t, user.Name) |
| 25 | + token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) |
| 26 | + |
| 27 | + repoName := "repo1" |
| 28 | + |
| 29 | + req := NewRequestf(t, "GET", "/user2/%s/compare/v1.1...master", repoName). |
| 30 | + AddTokenAuth(token) |
| 31 | + resp := MakeRequest(t, req, http.StatusOK) |
| 32 | + |
| 33 | + var apiResp *api.Compare |
| 34 | + DecodeJSON(t, resp, &apiResp) |
| 35 | + |
| 36 | + assert.Len(t, apiResp.TotalCommits, 1) |
| 37 | + assert.Equal(t, "Initial commit", apiResp.Commits[0].RepoCommit.Message) |
| 38 | + assert.Equal(t, "65f1bf27bc3bf70f64657658635e66094edbcb4d", apiResp.Commits[0].SHA) |
| 39 | + assert.Equal(t, setting.AppURL+"api/v1/repos/user2/repo1/git/commits/65f1bf27bc3bf70f64657658635e66094edbcb4d", apiResp.Commits[0].URL) |
| 40 | +} |
0 commit comments