2024-03-31 15:27:59 +02:00
|
|
|
// Copyright 2024 The Forgejo Authors
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
package issues_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models/db"
|
|
|
|
issues_model "code.gitea.io/gitea/models/issues"
|
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
|
|
|
"code.gitea.io/gitea/models/unittest"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2024-07-30 21:41:27 +02:00
|
|
|
"github.com/stretchr/testify/require"
|
2024-03-31 15:27:59 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetMaxIssueIndexForRepo(t *testing.T) {
|
2024-07-30 21:41:27 +02:00
|
|
|
require.NoError(t, unittest.PrepareTestDatabase())
|
2024-03-31 15:27:59 +02:00
|
|
|
|
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
|
|
|
|
|
|
|
maxPR, err := issues_model.GetMaxIssueIndexForRepo(db.DefaultContext, repo.ID)
|
2024-07-30 21:41:27 +02:00
|
|
|
require.NoError(t, err)
|
2024-03-31 15:27:59 +02:00
|
|
|
|
|
|
|
issue := testCreateIssue(t, repo.ID, repo.OwnerID, "title1", "content1", false)
|
|
|
|
assert.Greater(t, issue.Index, maxPR)
|
|
|
|
|
|
|
|
maxPR, err = issues_model.GetMaxIssueIndexForRepo(db.DefaultContext, repo.ID)
|
2024-07-30 21:41:27 +02:00
|
|
|
require.NoError(t, err)
|
2024-03-31 15:27:59 +02:00
|
|
|
|
|
|
|
pull := testCreateIssue(t, repo.ID, repo.OwnerID, "title2", "content2", true)
|
|
|
|
assert.Greater(t, pull.Index, maxPR)
|
|
|
|
|
|
|
|
maxPR, err = issues_model.GetMaxIssueIndexForRepo(db.DefaultContext, repo.ID)
|
2024-07-30 21:41:27 +02:00
|
|
|
require.NoError(t, err)
|
2024-03-31 15:27:59 +02:00
|
|
|
|
|
|
|
assert.Equal(t, maxPR, pull.Index)
|
|
|
|
}
|