mirror of
https://github.com/go-gitea/gitea
synced 2024-12-22 15:47:55 +01:00
Add unit tests for Review
Signed-off-by: Jonas Franz <info@jonasfranz.software>
This commit is contained in:
parent
36d6631957
commit
9c6bb4b1e9
@ -20,3 +20,13 @@
|
||||
issue_id: 1 # in repo_id 1
|
||||
content: "meh..."
|
||||
created_unix: 946684812
|
||||
-
|
||||
id: 4
|
||||
type: 19 # code comment
|
||||
poster_id: 1
|
||||
issue_id: 2
|
||||
content: "meh..."
|
||||
review_id: 1
|
||||
line: 4
|
||||
tree_path: "README.md"
|
||||
created_unix: 946684812
|
||||
|
32
models/fixtures/review.yml
Normal file
32
models/fixtures/review.yml
Normal file
@ -0,0 +1,32 @@
|
||||
-
|
||||
id: 1
|
||||
type: 1
|
||||
reviewer_id: 1
|
||||
issue_id: 2
|
||||
content: "Demo Review"
|
||||
updated_unix: 946684810
|
||||
created_unix: 946684810
|
||||
-
|
||||
id: 2
|
||||
type: 1
|
||||
reviewer_id: 534543
|
||||
issue_id: 534543
|
||||
content: "Invalid Review #1"
|
||||
updated_unix: 946684810
|
||||
created_unix: 946684810
|
||||
-
|
||||
id: 3
|
||||
type: 1
|
||||
reviewer_id: 1
|
||||
issue_id: 343545
|
||||
content: "Invalid Review #2"
|
||||
updated_unix: 946684810
|
||||
created_unix: 946684810
|
||||
-
|
||||
id: 4
|
||||
type: 0 # Pending review
|
||||
reviewer_id: 1
|
||||
issue_id: 2
|
||||
content: "Pending Review"
|
||||
updated_unix: 946684810
|
||||
created_unix: 946684810
|
@ -60,7 +60,7 @@ type Review struct {
|
||||
}
|
||||
|
||||
func (r *Review) loadCodeComments(e Engine) (err error) {
|
||||
r.CodeComments, err = findComments(e, FindCommentsOptions{IssueID: r.IssueID, ReviewID: r.ID})
|
||||
r.CodeComments, err = findComments(e, FindCommentsOptions{IssueID: r.IssueID, ReviewID: r.ID, Type: CommentTypeCode})
|
||||
return
|
||||
}
|
||||
|
||||
|
106
models/review_test.go
Normal file
106
models/review_test.go
Normal file
@ -0,0 +1,106 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestGetReviewByID(t *testing.T) {
|
||||
assert.NoError(t, PrepareTestDatabase())
|
||||
review, err := GetReviewByID(1)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "Demo Review", review.Content)
|
||||
assert.Equal(t, ReviewTypeApprove, review.Type)
|
||||
|
||||
_, err = GetReviewByID(23892)
|
||||
assert.Error(t, err)
|
||||
assert.True(t, IsErrReviewNotExist(err), "IsErrReviewNotExist")
|
||||
}
|
||||
|
||||
func TestReview_LoadAttributes(t *testing.T) {
|
||||
assert.NoError(t, PrepareTestDatabase())
|
||||
review := 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)
|
||||
assert.Error(t, invalidReview1.LoadAttributes())
|
||||
|
||||
invalidReview2 := AssertExistsAndLoadBean(t, &Review{ID: 3}).(*Review)
|
||||
assert.Error(t, invalidReview2.LoadAttributes())
|
||||
|
||||
}
|
||||
|
||||
func TestReview_LoadCodeComments(t *testing.T) {
|
||||
assert.NoError(t, PrepareTestDatabase())
|
||||
|
||||
review := AssertExistsAndLoadBean(t, &Review{ID: 1}).(*Review)
|
||||
assert.NoError(t, review.LoadCodeComments())
|
||||
assert.Len(t, review.CodeComments, 1)
|
||||
assert.Equal(t, int64(4), review.CodeComments[0].Line)
|
||||
}
|
||||
|
||||
func TestReviewType_Icon(t *testing.T) {
|
||||
assert.Equal(t, "eye", ReviewTypeApprove.Icon())
|
||||
assert.Equal(t, "x", ReviewTypeReject.Icon())
|
||||
assert.Equal(t, "comment", ReviewTypeComment.Icon())
|
||||
assert.Equal(t, "comment", ReviewTypeUnknown.Icon())
|
||||
assert.Equal(t, "comment", ReviewType(4).Icon())
|
||||
}
|
||||
|
||||
func TestFindReviews(t *testing.T) {
|
||||
assert.NoError(t, PrepareTestDatabase())
|
||||
reviews, err := FindReviews(FindReviewOptions{
|
||||
Type: ReviewTypeApprove,
|
||||
IssueID: 2,
|
||||
ReviewerID: 1,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, reviews, 1)
|
||||
assert.Equal(t, "Demo Review", reviews[0].Content)
|
||||
}
|
||||
|
||||
func TestGetCurrentReview(t *testing.T) {
|
||||
assert.NoError(t, PrepareTestDatabase())
|
||||
issue := AssertExistsAndLoadBean(t, &Issue{ID: 2}).(*Issue)
|
||||
user := AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
|
||||
|
||||
review, err := GetCurrentReview(user, issue)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, review)
|
||||
assert.Equal(t, ReviewTypePending, review.Type)
|
||||
assert.Equal(t, "Pending Review", review.Content )
|
||||
|
||||
user2 := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
|
||||
review2, err := GetCurrentReview(user2, issue)
|
||||
assert.Error(t, err)
|
||||
assert.True(t, IsErrReviewNotExist(err))
|
||||
assert.Nil(t, review2)
|
||||
}
|
||||
|
||||
func TestCreateReview(t *testing.T) {
|
||||
assert.NoError(t, PrepareTestDatabase())
|
||||
|
||||
issue := AssertExistsAndLoadBean(t, &Issue{ID: 2}).(*Issue)
|
||||
user := AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
|
||||
|
||||
review, err := CreateReview(CreateReviewOptions{
|
||||
Content: "New Review",
|
||||
Type: ReviewTypePending,
|
||||
Issue: issue,
|
||||
Reviewer: user,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "New Review", review.Content)
|
||||
AssertExistsAndLoadBean(t, &Review{Content: "New Review"})
|
||||
}
|
||||
|
||||
func TestUpdateReview(t *testing.T) {
|
||||
assert.NoError(t, PrepareTestDatabase())
|
||||
review := AssertExistsAndLoadBean(t, &Review{ID: 1}).(*Review)
|
||||
review.Content = "Updated Review"
|
||||
assert.NoError(t, UpdateReview(review))
|
||||
AssertExistsAndLoadBean(t, &Review{ID: 1, Content: "Updated Review"})
|
||||
}
|
Loading…
Reference in New Issue
Block a user