mirror of
https://codeberg.org/davrot/forgejo.git
synced 2025-05-20 14:00:04 +02:00
Move db related basic functions to models/db (#17075)
* Move db related basic functions to models/db * Fix lint * Fix lint * Fix test * Fix lint * Fix lint * revert unnecessary change * Fix test * Fix wrong replace string * Use *Context * Correct committer spelling and fix wrong replaced words Co-authored-by: zeripath <art27@cantab.net>
This commit is contained in:
parent
462306e263
commit
a4bfef265d
335 changed files with 4191 additions and 3654 deletions
|
@ -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})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue