diff options
Diffstat (limited to 'models/issue_reaction_test.go')
-rw-r--r-- | models/issue_reaction_test.go | 75 |
1 files changed, 38 insertions, 37 deletions
diff --git a/models/issue_reaction_test.go b/models/issue_reaction_test.go index e7aa45e4c3..b74d0ce9b8 100644 --- a/models/issue_reaction_test.go +++ b/models/issue_reaction_test.go @@ -6,6 +6,7 @@ package models import ( "testing" + "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/modules/setting" "github.com/stretchr/testify/assert" @@ -24,23 +25,23 @@ func addReaction(t *testing.T, doer *User, issue *Issue, comment *Comment, conte } func TestIssueAddReaction(t *testing.T) { - assert.NoError(t, PrepareTestDatabase()) + assert.NoError(t, db.PrepareTestDatabase()) - user1 := AssertExistsAndLoadBean(t, &User{ID: 1}).(*User) + user1 := db.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User) - issue1 := AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue) + issue1 := db.AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue) addReaction(t, user1, issue1, nil, "heart") - AssertExistsAndLoadBean(t, &Reaction{Type: "heart", UserID: user1.ID, IssueID: issue1.ID}) + db.AssertExistsAndLoadBean(t, &Reaction{Type: "heart", UserID: user1.ID, IssueID: issue1.ID}) } func TestIssueAddDuplicateReaction(t *testing.T) { - assert.NoError(t, PrepareTestDatabase()) + assert.NoError(t, db.PrepareTestDatabase()) - user1 := AssertExistsAndLoadBean(t, &User{ID: 1}).(*User) + user1 := db.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User) - issue1 := AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue) + issue1 := db.AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue) addReaction(t, user1, issue1, nil, "heart") @@ -52,37 +53,37 @@ func TestIssueAddDuplicateReaction(t *testing.T) { assert.Error(t, err) assert.Equal(t, ErrReactionAlreadyExist{Reaction: "heart"}, err) - existingR := AssertExistsAndLoadBean(t, &Reaction{Type: "heart", UserID: user1.ID, IssueID: issue1.ID}).(*Reaction) + existingR := db.AssertExistsAndLoadBean(t, &Reaction{Type: "heart", UserID: user1.ID, IssueID: issue1.ID}).(*Reaction) assert.Equal(t, existingR.ID, reaction.ID) } func TestIssueDeleteReaction(t *testing.T) { - assert.NoError(t, PrepareTestDatabase()) + assert.NoError(t, db.PrepareTestDatabase()) - user1 := AssertExistsAndLoadBean(t, &User{ID: 1}).(*User) + user1 := db.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User) - issue1 := AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue) + issue1 := db.AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue) addReaction(t, user1, issue1, nil, "heart") err := DeleteIssueReaction(user1, issue1, "heart") assert.NoError(t, err) - AssertNotExistsBean(t, &Reaction{Type: "heart", UserID: user1.ID, IssueID: issue1.ID}) + db.AssertNotExistsBean(t, &Reaction{Type: "heart", UserID: user1.ID, IssueID: issue1.ID}) } func TestIssueReactionCount(t *testing.T) { - assert.NoError(t, PrepareTestDatabase()) + assert.NoError(t, db.PrepareTestDatabase()) setting.UI.ReactionMaxUserNum = 2 - user1 := AssertExistsAndLoadBean(t, &User{ID: 1}).(*User) - user2 := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User) - user3 := AssertExistsAndLoadBean(t, &User{ID: 3}).(*User) - user4 := AssertExistsAndLoadBean(t, &User{ID: 4}).(*User) + user1 := db.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User) + user2 := db.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User) + user3 := db.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User) + user4 := db.AssertExistsAndLoadBean(t, &User{ID: 4}).(*User) ghost := NewGhostUser() - issue := AssertExistsAndLoadBean(t, &Issue{ID: 2}).(*Issue) + issue := db.AssertExistsAndLoadBean(t, &Issue{ID: 2}).(*Issue) addReaction(t, user1, issue, nil, "heart") addReaction(t, user2, issue, nil, "heart") @@ -92,7 +93,7 @@ func TestIssueReactionCount(t *testing.T) { addReaction(t, user4, issue, nil, "heart") addReaction(t, ghost, issue, nil, "-1") - err := issue.loadReactions(x) + err := issue.loadReactions(db.DefaultContext().Engine()) assert.NoError(t, err) assert.Len(t, issue.Reactions, 7) @@ -110,31 +111,31 @@ func TestIssueReactionCount(t *testing.T) { } func TestIssueCommentAddReaction(t *testing.T) { - assert.NoError(t, PrepareTestDatabase()) + assert.NoError(t, db.PrepareTestDatabase()) - user1 := AssertExistsAndLoadBean(t, &User{ID: 1}).(*User) + user1 := db.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User) - issue1 := AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue) + issue1 := db.AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue) - comment1 := AssertExistsAndLoadBean(t, &Comment{ID: 1}).(*Comment) + comment1 := db.AssertExistsAndLoadBean(t, &Comment{ID: 1}).(*Comment) addReaction(t, user1, issue1, comment1, "heart") - AssertExistsAndLoadBean(t, &Reaction{Type: "heart", UserID: user1.ID, IssueID: issue1.ID, CommentID: comment1.ID}) + db.AssertExistsAndLoadBean(t, &Reaction{Type: "heart", UserID: user1.ID, IssueID: issue1.ID, CommentID: comment1.ID}) } func TestIssueCommentDeleteReaction(t *testing.T) { - assert.NoError(t, PrepareTestDatabase()) + assert.NoError(t, db.PrepareTestDatabase()) - user1 := AssertExistsAndLoadBean(t, &User{ID: 1}).(*User) - user2 := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User) - user3 := AssertExistsAndLoadBean(t, &User{ID: 3}).(*User) - user4 := AssertExistsAndLoadBean(t, &User{ID: 4}).(*User) + user1 := db.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User) + user2 := db.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User) + user3 := db.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User) + user4 := db.AssertExistsAndLoadBean(t, &User{ID: 4}).(*User) - issue1 := AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue) - repo1 := AssertExistsAndLoadBean(t, &Repository{ID: issue1.RepoID}).(*Repository) + issue1 := db.AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue) + repo1 := db.AssertExistsAndLoadBean(t, &Repository{ID: issue1.RepoID}).(*Repository) - comment1 := AssertExistsAndLoadBean(t, &Comment{ID: 1}).(*Comment) + comment1 := db.AssertExistsAndLoadBean(t, &Comment{ID: 1}).(*Comment) addReaction(t, user1, issue1, comment1, "heart") addReaction(t, user2, issue1, comment1, "heart") @@ -151,16 +152,16 @@ func TestIssueCommentDeleteReaction(t *testing.T) { } func TestIssueCommentReactionCount(t *testing.T) { - assert.NoError(t, PrepareTestDatabase()) + assert.NoError(t, db.PrepareTestDatabase()) - user1 := AssertExistsAndLoadBean(t, &User{ID: 1}).(*User) + user1 := db.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User) - issue1 := AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue) + issue1 := db.AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue) - comment1 := AssertExistsAndLoadBean(t, &Comment{ID: 1}).(*Comment) + comment1 := db.AssertExistsAndLoadBean(t, &Comment{ID: 1}).(*Comment) addReaction(t, user1, issue1, comment1, "heart") assert.NoError(t, DeleteCommentReaction(user1, issue1, comment1, "heart")) - AssertNotExistsBean(t, &Reaction{Type: "heart", UserID: user1.ID, IssueID: issue1.ID, CommentID: comment1.ID}) + db.AssertNotExistsBean(t, &Reaction{Type: "heart", UserID: user1.ID, IssueID: issue1.ID, CommentID: comment1.ID}) } |