2024-03-28 10:19:24 -05:00
|
|
|
// Copyright 2024 The Gitea Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
package pull_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models/db"
|
|
|
|
issues_model "code.gitea.io/gitea/models/issues"
|
|
|
|
"code.gitea.io/gitea/models/unittest"
|
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
|
|
|
pull_service "code.gitea.io/gitea/services/pull"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2024-07-30 14:41:10 -05:00
|
|
|
"github.com/stretchr/testify/require"
|
2024-03-28 10:19:24 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestDismissReview(t *testing.T) {
|
2024-07-30 14:41:10 -05:00
|
|
|
require.NoError(t, unittest.PrepareTestDatabase())
|
2024-03-28 10:19:24 -05:00
|
|
|
|
|
|
|
pull := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{})
|
2024-07-30 14:41:10 -05:00
|
|
|
require.NoError(t, pull.LoadIssue(db.DefaultContext))
|
2024-03-28 10:19:24 -05:00
|
|
|
issue := pull.Issue
|
2024-07-30 14:41:10 -05:00
|
|
|
require.NoError(t, issue.LoadRepo(db.DefaultContext))
|
2024-03-28 10:19:24 -05:00
|
|
|
reviewer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
|
|
|
|
review, err := issues_model.CreateReview(db.DefaultContext, issues_model.CreateReviewOptions{
|
|
|
|
Issue: issue,
|
|
|
|
Reviewer: reviewer,
|
|
|
|
Type: issues_model.ReviewTypeReject,
|
|
|
|
})
|
|
|
|
|
2024-07-30 14:41:10 -05:00
|
|
|
require.NoError(t, err)
|
2024-03-28 10:19:24 -05:00
|
|
|
issue.IsClosed = true
|
|
|
|
pull.HasMerged = false
|
2024-07-30 14:41:10 -05:00
|
|
|
require.NoError(t, issues_model.UpdateIssueCols(db.DefaultContext, issue, "is_closed"))
|
|
|
|
require.NoError(t, pull.UpdateCols(db.DefaultContext, "has_merged"))
|
2024-03-28 10:19:24 -05:00
|
|
|
_, err = pull_service.DismissReview(db.DefaultContext, review.ID, issue.RepoID, "", &user_model.User{}, false, false)
|
2024-07-30 14:41:10 -05:00
|
|
|
require.Error(t, err)
|
2024-03-28 10:19:24 -05:00
|
|
|
assert.True(t, pull_service.IsErrDismissRequestOnClosedPR(err))
|
|
|
|
|
|
|
|
pull.HasMerged = true
|
|
|
|
pull.Issue.IsClosed = false
|
2024-07-30 14:41:10 -05:00
|
|
|
require.NoError(t, issues_model.UpdateIssueCols(db.DefaultContext, issue, "is_closed"))
|
|
|
|
require.NoError(t, pull.UpdateCols(db.DefaultContext, "has_merged"))
|
2024-03-28 10:19:24 -05:00
|
|
|
_, err = pull_service.DismissReview(db.DefaultContext, review.ID, issue.RepoID, "", &user_model.User{}, false, false)
|
2024-07-30 14:41:10 -05:00
|
|
|
require.Error(t, err)
|
2024-03-28 10:19:24 -05:00
|
|
|
assert.True(t, pull_service.IsErrDismissRequestOnClosedPR(err))
|
|
|
|
}
|