2020-04-05 08:20:50 +02:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
2022-11-27 19:20:29 +01:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-04-05 08:20:50 +02:00
|
|
|
|
2022-06-13 11:37:59 +02:00
|
|
|
package issues_test
|
2018-08-06 06:43:22 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-01-20 00:26:57 +01:00
|
|
|
"code.gitea.io/gitea/models/db"
|
2022-06-13 11:37:59 +02:00
|
|
|
issues_model "code.gitea.io/gitea/models/issues"
|
2023-11-05 14:25:40 +01:00
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2021-11-12 15:36:47 +01:00
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2021-11-24 10:49:20 +01:00
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2021-11-17 13:34:35 +01:00
|
|
|
|
2018-08-06 06:43:22 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
2024-07-30 21:41:10 +02:00
|
|
|
"github.com/stretchr/testify/require"
|
2018-08-06 06:43:22 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetReviewByID(t *testing.T) {
|
2024-07-30 21:41:10 +02:00
|
|
|
require.NoError(t, unittest.PrepareTestDatabase())
|
2022-06-13 11:37:59 +02:00
|
|
|
review, err := issues_model.GetReviewByID(db.DefaultContext, 1)
|
2024-07-30 21:41:10 +02:00
|
|
|
require.NoError(t, err)
|
2018-08-06 06:43:22 +02:00
|
|
|
assert.Equal(t, "Demo Review", review.Content)
|
2022-06-13 11:37:59 +02:00
|
|
|
assert.Equal(t, issues_model.ReviewTypeApprove, review.Type)
|
2018-08-06 06:43:22 +02:00
|
|
|
|
2022-06-13 11:37:59 +02:00
|
|
|
_, err = issues_model.GetReviewByID(db.DefaultContext, 23892)
|
2024-07-30 21:41:10 +02:00
|
|
|
require.Error(t, err)
|
2022-06-13 11:37:59 +02:00
|
|
|
assert.True(t, issues_model.IsErrReviewNotExist(err), "IsErrReviewNotExist")
|
2018-08-06 06:43:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestReview_LoadAttributes(t *testing.T) {
|
2024-07-30 21:41:10 +02:00
|
|
|
require.NoError(t, unittest.PrepareTestDatabase())
|
2022-08-16 04:22:25 +02:00
|
|
|
review := unittest.AssertExistsAndLoadBean(t, &issues_model.Review{ID: 1})
|
2024-07-30 21:41:10 +02:00
|
|
|
require.NoError(t, review.LoadAttributes(db.DefaultContext))
|
2018-08-06 06:43:22 +02:00
|
|
|
assert.NotNil(t, review.Issue)
|
|
|
|
assert.NotNil(t, review.Reviewer)
|
|
|
|
|
2022-08-16 04:22:25 +02:00
|
|
|
invalidReview1 := unittest.AssertExistsAndLoadBean(t, &issues_model.Review{ID: 2})
|
2024-07-30 21:41:10 +02:00
|
|
|
require.Error(t, invalidReview1.LoadAttributes(db.DefaultContext))
|
2018-08-06 06:43:22 +02:00
|
|
|
|
2022-08-16 04:22:25 +02:00
|
|
|
invalidReview2 := unittest.AssertExistsAndLoadBean(t, &issues_model.Review{ID: 3})
|
2024-07-30 21:41:10 +02:00
|
|
|
require.Error(t, invalidReview2.LoadAttributes(db.DefaultContext))
|
2018-08-06 06:43:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestReview_LoadCodeComments(t *testing.T) {
|
2024-07-30 21:41:10 +02:00
|
|
|
require.NoError(t, unittest.PrepareTestDatabase())
|
2018-08-06 06:43:22 +02:00
|
|
|
|
2022-08-16 04:22:25 +02:00
|
|
|
review := unittest.AssertExistsAndLoadBean(t, &issues_model.Review{ID: 4})
|
2024-07-30 21:41:10 +02:00
|
|
|
require.NoError(t, review.LoadAttributes(db.DefaultContext))
|
|
|
|
require.NoError(t, review.LoadCodeComments(db.DefaultContext))
|
2018-08-06 06:43:22 +02:00
|
|
|
assert.Len(t, review.CodeComments, 1)
|
|
|
|
assert.Equal(t, int64(4), review.CodeComments["README.md"][int64(4)][0].Line)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestReviewType_Icon(t *testing.T) {
|
2022-06-13 11:37:59 +02:00
|
|
|
assert.Equal(t, "check", issues_model.ReviewTypeApprove.Icon())
|
|
|
|
assert.Equal(t, "diff", issues_model.ReviewTypeReject.Icon())
|
|
|
|
assert.Equal(t, "comment", issues_model.ReviewTypeComment.Icon())
|
|
|
|
assert.Equal(t, "comment", issues_model.ReviewTypeUnknown.Icon())
|
|
|
|
assert.Equal(t, "dot-fill", issues_model.ReviewTypeRequest.Icon())
|
|
|
|
assert.Equal(t, "comment", issues_model.ReviewType(6).Icon())
|
2018-08-06 06:43:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestFindReviews(t *testing.T) {
|
2024-07-30 21:41:10 +02:00
|
|
|
require.NoError(t, unittest.PrepareTestDatabase())
|
2022-06-13 11:37:59 +02:00
|
|
|
reviews, err := issues_model.FindReviews(db.DefaultContext, issues_model.FindReviewOptions{
|
|
|
|
Type: issues_model.ReviewTypeApprove,
|
2018-08-06 06:43:22 +02:00
|
|
|
IssueID: 2,
|
|
|
|
ReviewerID: 1,
|
|
|
|
})
|
2024-07-30 21:41:10 +02:00
|
|
|
require.NoError(t, err)
|
2018-08-06 06:43:22 +02:00
|
|
|
assert.Len(t, reviews, 1)
|
|
|
|
assert.Equal(t, "Demo Review", reviews[0].Content)
|
|
|
|
}
|
|
|
|
|
2023-06-09 16:34:49 +02:00
|
|
|
func TestFindLatestReviews(t *testing.T) {
|
2024-07-30 21:41:10 +02:00
|
|
|
require.NoError(t, unittest.PrepareTestDatabase())
|
2023-06-09 16:34:49 +02:00
|
|
|
reviews, err := issues_model.FindLatestReviews(db.DefaultContext, issues_model.FindReviewOptions{
|
|
|
|
Type: issues_model.ReviewTypeApprove,
|
|
|
|
IssueID: 11,
|
|
|
|
})
|
2024-07-30 21:41:10 +02:00
|
|
|
require.NoError(t, err)
|
2023-06-09 16:34:49 +02:00
|
|
|
assert.Len(t, reviews, 2)
|
|
|
|
assert.Equal(t, "duplicate review from user5 (latest)", reviews[0].Content)
|
2023-09-14 04:59:53 +02:00
|
|
|
assert.Equal(t, "singular review from org6 and final review for this pr", reviews[1].Content)
|
2023-06-09 16:34:49 +02:00
|
|
|
}
|
|
|
|
|
2018-08-06 06:43:22 +02:00
|
|
|
func TestGetCurrentReview(t *testing.T) {
|
2024-07-30 21:41:10 +02:00
|
|
|
require.NoError(t, unittest.PrepareTestDatabase())
|
2022-08-16 04:22:25 +02:00
|
|
|
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 2})
|
|
|
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
|
2018-08-06 06:43:22 +02:00
|
|
|
|
2022-06-13 11:37:59 +02:00
|
|
|
review, err := issues_model.GetCurrentReview(db.DefaultContext, user, issue)
|
2024-07-30 21:41:10 +02:00
|
|
|
require.NoError(t, err)
|
2018-08-06 06:43:22 +02:00
|
|
|
assert.NotNil(t, review)
|
2022-06-13 11:37:59 +02:00
|
|
|
assert.Equal(t, issues_model.ReviewTypePending, review.Type)
|
2018-08-06 06:43:22 +02:00
|
|
|
assert.Equal(t, "Pending Review", review.Content)
|
|
|
|
|
2022-08-16 04:22:25 +02:00
|
|
|
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 7})
|
2022-06-13 11:37:59 +02:00
|
|
|
review2, err := issues_model.GetCurrentReview(db.DefaultContext, user2, issue)
|
2024-07-30 21:41:10 +02:00
|
|
|
require.Error(t, err)
|
2022-06-13 11:37:59 +02:00
|
|
|
assert.True(t, issues_model.IsErrReviewNotExist(err))
|
2018-08-06 06:43:22 +02:00
|
|
|
assert.Nil(t, review2)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCreateReview(t *testing.T) {
|
2024-07-30 21:41:10 +02:00
|
|
|
require.NoError(t, unittest.PrepareTestDatabase())
|
2018-08-06 06:43:22 +02:00
|
|
|
|
2022-08-16 04:22:25 +02:00
|
|
|
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 2})
|
|
|
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
|
2018-08-06 06:43:22 +02:00
|
|
|
|
2022-06-13 11:37:59 +02:00
|
|
|
review, err := issues_model.CreateReview(db.DefaultContext, issues_model.CreateReviewOptions{
|
2018-08-06 06:43:22 +02:00
|
|
|
Content: "New Review",
|
2022-06-13 11:37:59 +02:00
|
|
|
Type: issues_model.ReviewTypePending,
|
2018-08-06 06:43:22 +02:00
|
|
|
Issue: issue,
|
|
|
|
Reviewer: user,
|
|
|
|
})
|
2024-07-30 21:41:10 +02:00
|
|
|
require.NoError(t, err)
|
2018-08-06 06:43:22 +02:00
|
|
|
assert.Equal(t, "New Review", review.Content)
|
2022-06-13 11:37:59 +02:00
|
|
|
unittest.AssertExistsAndLoadBean(t, &issues_model.Review{Content: "New Review"})
|
2018-08-06 06:43:22 +02:00
|
|
|
}
|
|
|
|
|
2019-12-04 02:08:56 +01:00
|
|
|
func TestGetReviewersByIssueID(t *testing.T) {
|
2024-07-30 21:41:10 +02:00
|
|
|
require.NoError(t, unittest.PrepareTestDatabase())
|
2018-11-22 14:17:36 +01:00
|
|
|
|
2022-08-16 04:22:25 +02:00
|
|
|
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 3})
|
|
|
|
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
2023-09-14 04:59:53 +02:00
|
|
|
org3 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3})
|
2022-08-16 04:22:25 +02:00
|
|
|
user4 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4})
|
2018-11-22 14:17:36 +01:00
|
|
|
|
2022-06-13 11:37:59 +02:00
|
|
|
expectedReviews := []*issues_model.Review{}
|
2019-12-04 02:08:56 +01:00
|
|
|
expectedReviews = append(expectedReviews,
|
2022-06-13 11:37:59 +02:00
|
|
|
&issues_model.Review{
|
2023-09-14 04:59:53 +02:00
|
|
|
Reviewer: org3,
|
2022-06-13 11:37:59 +02:00
|
|
|
Type: issues_model.ReviewTypeReject,
|
2019-12-04 02:08:56 +01:00
|
|
|
UpdatedUnix: 946684812,
|
2018-11-22 14:17:36 +01:00
|
|
|
},
|
2022-06-13 11:37:59 +02:00
|
|
|
&issues_model.Review{
|
2019-12-04 02:08:56 +01:00
|
|
|
Reviewer: user4,
|
2022-06-13 11:37:59 +02:00
|
|
|
Type: issues_model.ReviewTypeApprove,
|
2019-12-04 02:08:56 +01:00
|
|
|
UpdatedUnix: 946684813,
|
|
|
|
},
|
2022-06-13 11:37:59 +02:00
|
|
|
&issues_model.Review{
|
2019-12-04 02:08:56 +01:00
|
|
|
Reviewer: user2,
|
2022-06-13 11:37:59 +02:00
|
|
|
Type: issues_model.ReviewTypeReject,
|
2019-12-04 02:08:56 +01:00
|
|
|
UpdatedUnix: 946684814,
|
2018-11-22 14:17:36 +01:00
|
|
|
})
|
|
|
|
|
2023-09-25 15:17:37 +02:00
|
|
|
allReviews, err := issues_model.GetReviewsByIssueID(db.DefaultContext, issue.ID)
|
2024-07-30 21:41:10 +02:00
|
|
|
require.NoError(t, err)
|
2023-05-25 04:06:27 +02:00
|
|
|
for _, review := range allReviews {
|
2024-07-30 21:41:10 +02:00
|
|
|
require.NoError(t, review.LoadReviewer(db.DefaultContext))
|
2020-10-12 21:55:13 +02:00
|
|
|
}
|
2023-05-25 04:06:27 +02:00
|
|
|
if assert.Len(t, allReviews, 3) {
|
|
|
|
for i, review := range allReviews {
|
|
|
|
assert.Equal(t, expectedReviews[i].Reviewer, review.Reviewer)
|
|
|
|
assert.Equal(t, expectedReviews[i].Type, review.Type)
|
|
|
|
assert.Equal(t, expectedReviews[i].UpdatedUnix, review.UpdatedUnix)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-25 15:17:37 +02:00
|
|
|
allReviews, err = issues_model.GetReviewsByIssueID(db.DefaultContext, issue.ID)
|
2024-07-30 21:41:10 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, allReviews.LoadReviewers(db.DefaultContext))
|
2020-05-02 02:20:51 +02:00
|
|
|
if assert.Len(t, allReviews, 3) {
|
|
|
|
for i, review := range allReviews {
|
|
|
|
assert.Equal(t, expectedReviews[i].Reviewer, review.Reviewer)
|
|
|
|
assert.Equal(t, expectedReviews[i].Type, review.Type)
|
|
|
|
assert.Equal(t, expectedReviews[i].UpdatedUnix, review.UpdatedUnix)
|
|
|
|
}
|
2019-12-04 02:08:56 +01:00
|
|
|
}
|
2018-11-22 14:17:36 +01:00
|
|
|
}
|
2021-02-11 18:32:25 +01:00
|
|
|
|
|
|
|
func TestDismissReview(t *testing.T) {
|
2024-07-30 21:41:10 +02:00
|
|
|
require.NoError(t, unittest.PrepareTestDatabase())
|
2021-04-15 12:03:11 +02:00
|
|
|
|
2022-08-16 04:22:25 +02:00
|
|
|
rejectReviewExample := unittest.AssertExistsAndLoadBean(t, &issues_model.Review{ID: 9})
|
|
|
|
requestReviewExample := unittest.AssertExistsAndLoadBean(t, &issues_model.Review{ID: 11})
|
|
|
|
approveReviewExample := unittest.AssertExistsAndLoadBean(t, &issues_model.Review{ID: 8})
|
2021-04-15 12:03:11 +02:00
|
|
|
assert.False(t, rejectReviewExample.Dismissed)
|
|
|
|
assert.False(t, requestReviewExample.Dismissed)
|
|
|
|
assert.False(t, approveReviewExample.Dismissed)
|
|
|
|
|
2024-07-30 21:41:10 +02:00
|
|
|
require.NoError(t, issues_model.DismissReview(db.DefaultContext, rejectReviewExample, true))
|
2022-08-16 04:22:25 +02:00
|
|
|
rejectReviewExample = unittest.AssertExistsAndLoadBean(t, &issues_model.Review{ID: 9})
|
|
|
|
requestReviewExample = unittest.AssertExistsAndLoadBean(t, &issues_model.Review{ID: 11})
|
2021-04-15 12:03:11 +02:00
|
|
|
assert.True(t, rejectReviewExample.Dismissed)
|
|
|
|
assert.False(t, requestReviewExample.Dismissed)
|
|
|
|
|
2024-07-30 21:41:10 +02:00
|
|
|
require.NoError(t, issues_model.DismissReview(db.DefaultContext, requestReviewExample, true))
|
2022-08-16 04:22:25 +02:00
|
|
|
rejectReviewExample = unittest.AssertExistsAndLoadBean(t, &issues_model.Review{ID: 9})
|
|
|
|
requestReviewExample = unittest.AssertExistsAndLoadBean(t, &issues_model.Review{ID: 11})
|
2021-04-15 12:03:11 +02:00
|
|
|
assert.True(t, rejectReviewExample.Dismissed)
|
|
|
|
assert.False(t, requestReviewExample.Dismissed)
|
|
|
|
assert.False(t, approveReviewExample.Dismissed)
|
|
|
|
|
2024-07-30 21:41:10 +02:00
|
|
|
require.NoError(t, issues_model.DismissReview(db.DefaultContext, requestReviewExample, true))
|
2022-08-16 04:22:25 +02:00
|
|
|
rejectReviewExample = unittest.AssertExistsAndLoadBean(t, &issues_model.Review{ID: 9})
|
|
|
|
requestReviewExample = unittest.AssertExistsAndLoadBean(t, &issues_model.Review{ID: 11})
|
2021-04-15 12:03:11 +02:00
|
|
|
assert.True(t, rejectReviewExample.Dismissed)
|
|
|
|
assert.False(t, requestReviewExample.Dismissed)
|
|
|
|
assert.False(t, approveReviewExample.Dismissed)
|
|
|
|
|
2024-07-30 21:41:10 +02:00
|
|
|
require.NoError(t, issues_model.DismissReview(db.DefaultContext, requestReviewExample, false))
|
2022-08-16 04:22:25 +02:00
|
|
|
rejectReviewExample = unittest.AssertExistsAndLoadBean(t, &issues_model.Review{ID: 9})
|
|
|
|
requestReviewExample = unittest.AssertExistsAndLoadBean(t, &issues_model.Review{ID: 11})
|
2021-04-15 12:03:11 +02:00
|
|
|
assert.True(t, rejectReviewExample.Dismissed)
|
|
|
|
assert.False(t, requestReviewExample.Dismissed)
|
|
|
|
assert.False(t, approveReviewExample.Dismissed)
|
|
|
|
|
2024-07-30 21:41:10 +02:00
|
|
|
require.NoError(t, issues_model.DismissReview(db.DefaultContext, requestReviewExample, false))
|
2022-08-16 04:22:25 +02:00
|
|
|
rejectReviewExample = unittest.AssertExistsAndLoadBean(t, &issues_model.Review{ID: 9})
|
|
|
|
requestReviewExample = unittest.AssertExistsAndLoadBean(t, &issues_model.Review{ID: 11})
|
2021-04-15 12:03:11 +02:00
|
|
|
assert.True(t, rejectReviewExample.Dismissed)
|
|
|
|
assert.False(t, requestReviewExample.Dismissed)
|
|
|
|
assert.False(t, approveReviewExample.Dismissed)
|
|
|
|
|
2024-07-30 21:41:10 +02:00
|
|
|
require.NoError(t, issues_model.DismissReview(db.DefaultContext, rejectReviewExample, false))
|
2021-04-15 12:03:11 +02:00
|
|
|
assert.False(t, rejectReviewExample.Dismissed)
|
|
|
|
assert.False(t, requestReviewExample.Dismissed)
|
|
|
|
assert.False(t, approveReviewExample.Dismissed)
|
|
|
|
|
2024-07-30 21:41:10 +02:00
|
|
|
require.NoError(t, issues_model.DismissReview(db.DefaultContext, approveReviewExample, true))
|
2021-04-15 12:03:11 +02:00
|
|
|
assert.False(t, rejectReviewExample.Dismissed)
|
|
|
|
assert.False(t, requestReviewExample.Dismissed)
|
|
|
|
assert.True(t, approveReviewExample.Dismissed)
|
2021-02-11 18:32:25 +01:00
|
|
|
}
|
2023-01-15 06:00:09 +01:00
|
|
|
|
|
|
|
func TestDeleteReview(t *testing.T) {
|
2024-07-30 21:41:10 +02:00
|
|
|
require.NoError(t, unittest.PrepareTestDatabase())
|
2023-01-15 06:00:09 +01:00
|
|
|
|
|
|
|
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 2})
|
|
|
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
|
|
|
|
|
|
|
|
review1, err := issues_model.CreateReview(db.DefaultContext, issues_model.CreateReviewOptions{
|
|
|
|
Content: "Official rejection",
|
|
|
|
Type: issues_model.ReviewTypeReject,
|
|
|
|
Official: false,
|
|
|
|
Issue: issue,
|
|
|
|
Reviewer: user,
|
|
|
|
})
|
2024-07-30 21:41:10 +02:00
|
|
|
require.NoError(t, err)
|
2023-01-15 06:00:09 +01:00
|
|
|
|
|
|
|
review2, err := issues_model.CreateReview(db.DefaultContext, issues_model.CreateReviewOptions{
|
|
|
|
Content: "Official approval",
|
|
|
|
Type: issues_model.ReviewTypeApprove,
|
|
|
|
Official: true,
|
|
|
|
Issue: issue,
|
|
|
|
Reviewer: user,
|
|
|
|
})
|
2024-07-30 21:41:10 +02:00
|
|
|
require.NoError(t, err)
|
2023-01-15 06:00:09 +01:00
|
|
|
|
2024-07-30 21:41:10 +02:00
|
|
|
require.NoError(t, issues_model.DeleteReview(db.DefaultContext, review2))
|
2023-01-15 06:00:09 +01:00
|
|
|
|
|
|
|
_, err = issues_model.GetReviewByID(db.DefaultContext, review2.ID)
|
2024-07-30 21:41:10 +02:00
|
|
|
require.Error(t, err)
|
2023-01-15 06:00:09 +01:00
|
|
|
assert.True(t, issues_model.IsErrReviewNotExist(err), "IsErrReviewNotExist")
|
|
|
|
|
|
|
|
review1, err = issues_model.GetReviewByID(db.DefaultContext, review1.ID)
|
2024-07-30 21:41:10 +02:00
|
|
|
require.NoError(t, err)
|
2023-01-15 06:00:09 +01:00
|
|
|
assert.True(t, review1.Official)
|
|
|
|
}
|
2023-11-05 14:25:40 +01:00
|
|
|
|
|
|
|
func TestDeleteDismissedReview(t *testing.T) {
|
2024-07-30 21:41:10 +02:00
|
|
|
require.NoError(t, unittest.PrepareTestDatabase())
|
2023-11-05 14:25:40 +01:00
|
|
|
|
|
|
|
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 2})
|
|
|
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
|
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID})
|
|
|
|
review, err := issues_model.CreateReview(db.DefaultContext, issues_model.CreateReviewOptions{
|
|
|
|
Content: "reject",
|
|
|
|
Type: issues_model.ReviewTypeReject,
|
|
|
|
Official: false,
|
|
|
|
Issue: issue,
|
|
|
|
Reviewer: user,
|
|
|
|
})
|
2024-07-30 21:41:10 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, issues_model.DismissReview(db.DefaultContext, review, true))
|
2023-11-05 14:25:40 +01:00
|
|
|
comment, err := issues_model.CreateComment(db.DefaultContext, &issues_model.CreateCommentOptions{
|
|
|
|
Type: issues_model.CommentTypeDismissReview,
|
|
|
|
Doer: user,
|
|
|
|
Repo: repo,
|
|
|
|
Issue: issue,
|
|
|
|
ReviewID: review.ID,
|
|
|
|
Content: "dismiss",
|
|
|
|
})
|
2024-07-30 21:41:10 +02:00
|
|
|
require.NoError(t, err)
|
2023-11-05 14:25:40 +01:00
|
|
|
unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: comment.ID})
|
2024-07-30 21:41:10 +02:00
|
|
|
require.NoError(t, issues_model.DeleteReview(db.DefaultContext, review))
|
2023-11-05 14:25:40 +01:00
|
|
|
unittest.AssertNotExistsBean(t, &issues_model.Comment{ID: comment.ID})
|
|
|
|
}
|
2024-03-28 16:19:24 +01:00
|
|
|
|
|
|
|
func TestAddReviewRequest(t *testing.T) {
|
2024-07-30 21:41:10 +02:00
|
|
|
require.NoError(t, unittest.PrepareTestDatabase())
|
2024-03-28 16:19:24 +01:00
|
|
|
|
|
|
|
pull := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 1})
|
2024-07-30 21:41:10 +02:00
|
|
|
require.NoError(t, pull.LoadIssue(db.DefaultContext))
|
2024-03-28 16:19:24 +01:00
|
|
|
issue := pull.Issue
|
2024-07-30 21:41:10 +02:00
|
|
|
require.NoError(t, issue.LoadRepo(db.DefaultContext))
|
2024-03-28 16:19:24 +01:00
|
|
|
reviewer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
|
|
|
|
_, err := issues_model.CreateReview(db.DefaultContext, issues_model.CreateReviewOptions{
|
|
|
|
Issue: issue,
|
|
|
|
Reviewer: reviewer,
|
|
|
|
Type: issues_model.ReviewTypeReject,
|
|
|
|
})
|
|
|
|
|
2024-07-30 21:41:10 +02:00
|
|
|
require.NoError(t, err)
|
2024-03-28 16:19:24 +01:00
|
|
|
pull.HasMerged = false
|
2024-07-30 21:41:10 +02:00
|
|
|
require.NoError(t, pull.UpdateCols(db.DefaultContext, "has_merged"))
|
2024-03-28 16:19:24 +01:00
|
|
|
issue.IsClosed = true
|
|
|
|
_, err = issues_model.AddReviewRequest(db.DefaultContext, issue, reviewer, &user_model.User{})
|
2024-07-30 21:41:10 +02:00
|
|
|
require.Error(t, err)
|
2024-03-28 16:19:24 +01:00
|
|
|
assert.True(t, issues_model.IsErrReviewRequestOnClosedPR(err))
|
|
|
|
|
|
|
|
pull.HasMerged = true
|
2024-07-30 21:41:10 +02:00
|
|
|
require.NoError(t, pull.UpdateCols(db.DefaultContext, "has_merged"))
|
2024-03-28 16:19:24 +01:00
|
|
|
issue.IsClosed = false
|
|
|
|
_, err = issues_model.AddReviewRequest(db.DefaultContext, issue, reviewer, &user_model.User{})
|
2024-07-30 21:41:10 +02:00
|
|
|
require.Error(t, err)
|
2024-03-28 16:19:24 +01:00
|
|
|
assert.True(t, issues_model.IsErrReviewRequestOnClosedPR(err))
|
|
|
|
}
|