summaryrefslogtreecommitdiffstats
path: root/models/review_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/review_test.go')
-rw-r--r--models/review_test.go71
1 files changed, 36 insertions, 35 deletions
diff --git a/models/review_test.go b/models/review_test.go
index accc184193..c809a3d662 100644
--- a/models/review_test.go
+++ b/models/review_test.go
@@ -7,11 +7,12 @@ package models
import (
"testing"
+ "code.gitea.io/gitea/models/db"
"github.com/stretchr/testify/assert"
)
func TestGetReviewByID(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
review, err := GetReviewByID(1)
assert.NoError(t, err)
assert.Equal(t, "Demo Review", review.Content)
@@ -23,23 +24,23 @@ func TestGetReviewByID(t *testing.T) {
}
func TestReview_LoadAttributes(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
- review := AssertExistsAndLoadBean(t, &Review{ID: 1}).(*Review)
+ assert.NoError(t, db.PrepareTestDatabase())
+ review := db.AssertExistsAndLoadBean(t, &Review{ID: 1}).(*Review)
assert.NoError(t, review.LoadAttributes())
assert.NotNil(t, review.Issue)
assert.NotNil(t, review.Reviewer)
- invalidReview1 := AssertExistsAndLoadBean(t, &Review{ID: 2}).(*Review)
+ invalidReview1 := db.AssertExistsAndLoadBean(t, &Review{ID: 2}).(*Review)
assert.Error(t, invalidReview1.LoadAttributes())
- invalidReview2 := AssertExistsAndLoadBean(t, &Review{ID: 3}).(*Review)
+ invalidReview2 := db.AssertExistsAndLoadBean(t, &Review{ID: 3}).(*Review)
assert.Error(t, invalidReview2.LoadAttributes())
}
func TestReview_LoadCodeComments(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
- review := AssertExistsAndLoadBean(t, &Review{ID: 4}).(*Review)
+ review := db.AssertExistsAndLoadBean(t, &Review{ID: 4}).(*Review)
assert.NoError(t, review.LoadAttributes())
assert.NoError(t, review.LoadCodeComments())
assert.Len(t, review.CodeComments, 1)
@@ -56,7 +57,7 @@ func TestReviewType_Icon(t *testing.T) {
}
func TestFindReviews(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
reviews, err := FindReviews(FindReviewOptions{
Type: ReviewTypeApprove,
IssueID: 2,
@@ -68,9 +69,9 @@ func TestFindReviews(t *testing.T) {
}
func TestGetCurrentReview(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
- issue := AssertExistsAndLoadBean(t, &Issue{ID: 2}).(*Issue)
- user := AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
+ assert.NoError(t, db.PrepareTestDatabase())
+ issue := db.AssertExistsAndLoadBean(t, &Issue{ID: 2}).(*Issue)
+ user := db.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
review, err := GetCurrentReview(user, issue)
assert.NoError(t, err)
@@ -78,7 +79,7 @@ func TestGetCurrentReview(t *testing.T) {
assert.Equal(t, ReviewTypePending, review.Type)
assert.Equal(t, "Pending Review", review.Content)
- user2 := AssertExistsAndLoadBean(t, &User{ID: 7}).(*User)
+ user2 := db.AssertExistsAndLoadBean(t, &User{ID: 7}).(*User)
review2, err := GetCurrentReview(user2, issue)
assert.Error(t, err)
assert.True(t, IsErrReviewNotExist(err))
@@ -86,10 +87,10 @@ func TestGetCurrentReview(t *testing.T) {
}
func TestCreateReview(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
- issue := AssertExistsAndLoadBean(t, &Issue{ID: 2}).(*Issue)
- user := AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
+ issue := db.AssertExistsAndLoadBean(t, &Issue{ID: 2}).(*Issue)
+ user := db.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
review, err := CreateReview(CreateReviewOptions{
Content: "New Review",
@@ -99,16 +100,16 @@ func TestCreateReview(t *testing.T) {
})
assert.NoError(t, err)
assert.Equal(t, "New Review", review.Content)
- AssertExistsAndLoadBean(t, &Review{Content: "New Review"})
+ db.AssertExistsAndLoadBean(t, &Review{Content: "New Review"})
}
func TestGetReviewersByIssueID(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
- issue := AssertExistsAndLoadBean(t, &Issue{ID: 3}).(*Issue)
- user2 := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
- user3 := AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
- user4 := AssertExistsAndLoadBean(t, &User{ID: 4}).(*User)
+ issue := db.AssertExistsAndLoadBean(t, &Issue{ID: 3}).(*Issue)
+ user2 := db.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
+ user3 := db.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
+ user4 := db.AssertExistsAndLoadBean(t, &User{ID: 4}).(*User)
expectedReviews := []*Review{}
expectedReviews = append(expectedReviews,
@@ -143,45 +144,45 @@ func TestGetReviewersByIssueID(t *testing.T) {
}
func TestDismissReview(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
- rejectReviewExample := AssertExistsAndLoadBean(t, &Review{ID: 9}).(*Review)
- requestReviewExample := AssertExistsAndLoadBean(t, &Review{ID: 11}).(*Review)
- approveReviewExample := AssertExistsAndLoadBean(t, &Review{ID: 8}).(*Review)
+ rejectReviewExample := db.AssertExistsAndLoadBean(t, &Review{ID: 9}).(*Review)
+ requestReviewExample := db.AssertExistsAndLoadBean(t, &Review{ID: 11}).(*Review)
+ approveReviewExample := db.AssertExistsAndLoadBean(t, &Review{ID: 8}).(*Review)
assert.False(t, rejectReviewExample.Dismissed)
assert.False(t, requestReviewExample.Dismissed)
assert.False(t, approveReviewExample.Dismissed)
assert.NoError(t, DismissReview(rejectReviewExample, true))
- rejectReviewExample = AssertExistsAndLoadBean(t, &Review{ID: 9}).(*Review)
- requestReviewExample = AssertExistsAndLoadBean(t, &Review{ID: 11}).(*Review)
+ rejectReviewExample = db.AssertExistsAndLoadBean(t, &Review{ID: 9}).(*Review)
+ requestReviewExample = db.AssertExistsAndLoadBean(t, &Review{ID: 11}).(*Review)
assert.True(t, rejectReviewExample.Dismissed)
assert.False(t, requestReviewExample.Dismissed)
assert.NoError(t, DismissReview(requestReviewExample, true))
- rejectReviewExample = AssertExistsAndLoadBean(t, &Review{ID: 9}).(*Review)
- requestReviewExample = AssertExistsAndLoadBean(t, &Review{ID: 11}).(*Review)
+ rejectReviewExample = db.AssertExistsAndLoadBean(t, &Review{ID: 9}).(*Review)
+ requestReviewExample = db.AssertExistsAndLoadBean(t, &Review{ID: 11}).(*Review)
assert.True(t, rejectReviewExample.Dismissed)
assert.False(t, requestReviewExample.Dismissed)
assert.False(t, approveReviewExample.Dismissed)
assert.NoError(t, DismissReview(requestReviewExample, true))
- rejectReviewExample = AssertExistsAndLoadBean(t, &Review{ID: 9}).(*Review)
- requestReviewExample = AssertExistsAndLoadBean(t, &Review{ID: 11}).(*Review)
+ rejectReviewExample = db.AssertExistsAndLoadBean(t, &Review{ID: 9}).(*Review)
+ requestReviewExample = db.AssertExistsAndLoadBean(t, &Review{ID: 11}).(*Review)
assert.True(t, rejectReviewExample.Dismissed)
assert.False(t, requestReviewExample.Dismissed)
assert.False(t, approveReviewExample.Dismissed)
assert.NoError(t, DismissReview(requestReviewExample, false))
- rejectReviewExample = AssertExistsAndLoadBean(t, &Review{ID: 9}).(*Review)
- requestReviewExample = AssertExistsAndLoadBean(t, &Review{ID: 11}).(*Review)
+ rejectReviewExample = db.AssertExistsAndLoadBean(t, &Review{ID: 9}).(*Review)
+ requestReviewExample = db.AssertExistsAndLoadBean(t, &Review{ID: 11}).(*Review)
assert.True(t, rejectReviewExample.Dismissed)
assert.False(t, requestReviewExample.Dismissed)
assert.False(t, approveReviewExample.Dismissed)
assert.NoError(t, DismissReview(requestReviewExample, false))
- rejectReviewExample = AssertExistsAndLoadBean(t, &Review{ID: 9}).(*Review)
- requestReviewExample = AssertExistsAndLoadBean(t, &Review{ID: 11}).(*Review)
+ rejectReviewExample = db.AssertExistsAndLoadBean(t, &Review{ID: 9}).(*Review)
+ requestReviewExample = db.AssertExistsAndLoadBean(t, &Review{ID: 11}).(*Review)
assert.True(t, rejectReviewExample.Dismissed)
assert.False(t, requestReviewExample.Dismissed)
assert.False(t, approveReviewExample.Dismissed)