forked from forgejo/forgejo
Move issues related files into models/issues (#19931)
* Move access and repo permission to models/perm/access * fix test * fix git test * Move functions sequence * Some improvements per @KN4CK3R and @delvh * Move issues related code to models/issues * Move some issues related sub package * Merge * Fix test * Fix test * Fix test * Fix test * Rename some files
This commit is contained in:
parent
3708ca8e28
commit
1a9821f57a
180 changed files with 3667 additions and 3677 deletions
|
@ -2,12 +2,13 @@
|
|||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package issues
|
||||
package issues_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
|
||||
|
@ -20,20 +21,20 @@ func TestContentHistory(t *testing.T) {
|
|||
dbCtx := db.DefaultContext
|
||||
timeStampNow := timeutil.TimeStampNow()
|
||||
|
||||
_ = SaveIssueContentHistory(dbCtx, 1, 10, 0, timeStampNow, "i-a", true)
|
||||
_ = SaveIssueContentHistory(dbCtx, 1, 10, 0, timeStampNow.Add(2), "i-b", false)
|
||||
_ = SaveIssueContentHistory(dbCtx, 1, 10, 0, timeStampNow.Add(7), "i-c", false)
|
||||
_ = issues_model.SaveIssueContentHistory(dbCtx, 1, 10, 0, timeStampNow, "i-a", true)
|
||||
_ = issues_model.SaveIssueContentHistory(dbCtx, 1, 10, 0, timeStampNow.Add(2), "i-b", false)
|
||||
_ = issues_model.SaveIssueContentHistory(dbCtx, 1, 10, 0, timeStampNow.Add(7), "i-c", false)
|
||||
|
||||
_ = SaveIssueContentHistory(dbCtx, 1, 10, 100, timeStampNow, "c-a", true)
|
||||
_ = SaveIssueContentHistory(dbCtx, 1, 10, 100, timeStampNow.Add(5), "c-b", false)
|
||||
_ = SaveIssueContentHistory(dbCtx, 1, 10, 100, timeStampNow.Add(20), "c-c", false)
|
||||
_ = SaveIssueContentHistory(dbCtx, 1, 10, 100, timeStampNow.Add(50), "c-d", false)
|
||||
_ = SaveIssueContentHistory(dbCtx, 1, 10, 100, timeStampNow.Add(51), "c-e", false)
|
||||
_ = issues_model.SaveIssueContentHistory(dbCtx, 1, 10, 100, timeStampNow, "c-a", true)
|
||||
_ = issues_model.SaveIssueContentHistory(dbCtx, 1, 10, 100, timeStampNow.Add(5), "c-b", false)
|
||||
_ = issues_model.SaveIssueContentHistory(dbCtx, 1, 10, 100, timeStampNow.Add(20), "c-c", false)
|
||||
_ = issues_model.SaveIssueContentHistory(dbCtx, 1, 10, 100, timeStampNow.Add(50), "c-d", false)
|
||||
_ = issues_model.SaveIssueContentHistory(dbCtx, 1, 10, 100, timeStampNow.Add(51), "c-e", false)
|
||||
|
||||
h1, _ := GetIssueContentHistoryByID(dbCtx, 1)
|
||||
h1, _ := issues_model.GetIssueContentHistoryByID(dbCtx, 1)
|
||||
assert.EqualValues(t, 1, h1.ID)
|
||||
|
||||
m, _ := QueryIssueContentHistoryEditedCountMap(dbCtx, 10)
|
||||
m, _ := issues_model.QueryIssueContentHistoryEditedCountMap(dbCtx, 10)
|
||||
assert.Equal(t, 3, m[0])
|
||||
assert.Equal(t, 5, m[100])
|
||||
|
||||
|
@ -48,31 +49,31 @@ func TestContentHistory(t *testing.T) {
|
|||
}
|
||||
_ = db.GetEngine(dbCtx).Sync2(&User{})
|
||||
|
||||
list1, _ := FetchIssueContentHistoryList(dbCtx, 10, 0)
|
||||
list1, _ := issues_model.FetchIssueContentHistoryList(dbCtx, 10, 0)
|
||||
assert.Len(t, list1, 3)
|
||||
list2, _ := FetchIssueContentHistoryList(dbCtx, 10, 100)
|
||||
list2, _ := issues_model.FetchIssueContentHistoryList(dbCtx, 10, 100)
|
||||
assert.Len(t, list2, 5)
|
||||
|
||||
hasHistory1, _ := HasIssueContentHistory(dbCtx, 10, 0)
|
||||
hasHistory1, _ := issues_model.HasIssueContentHistory(dbCtx, 10, 0)
|
||||
assert.True(t, hasHistory1)
|
||||
hasHistory2, _ := HasIssueContentHistory(dbCtx, 10, 1)
|
||||
hasHistory2, _ := issues_model.HasIssueContentHistory(dbCtx, 10, 1)
|
||||
assert.False(t, hasHistory2)
|
||||
|
||||
h6, h6Prev, _ := GetIssueContentHistoryAndPrev(dbCtx, 6)
|
||||
h6, h6Prev, _ := issues_model.GetIssueContentHistoryAndPrev(dbCtx, 6)
|
||||
assert.EqualValues(t, 6, h6.ID)
|
||||
assert.EqualValues(t, 5, h6Prev.ID)
|
||||
|
||||
// soft-delete
|
||||
_ = SoftDeleteIssueContentHistory(dbCtx, 5)
|
||||
h6, h6Prev, _ = GetIssueContentHistoryAndPrev(dbCtx, 6)
|
||||
_ = issues_model.SoftDeleteIssueContentHistory(dbCtx, 5)
|
||||
h6, h6Prev, _ = issues_model.GetIssueContentHistoryAndPrev(dbCtx, 6)
|
||||
assert.EqualValues(t, 6, h6.ID)
|
||||
assert.EqualValues(t, 4, h6Prev.ID)
|
||||
|
||||
// only keep 3 history revisions for comment_id=100, the first and the last should never be deleted
|
||||
keepLimitedContentHistory(dbCtx, 10, 100, 3)
|
||||
list1, _ = FetchIssueContentHistoryList(dbCtx, 10, 0)
|
||||
issues_model.KeepLimitedContentHistory(dbCtx, 10, 100, 3)
|
||||
list1, _ = issues_model.FetchIssueContentHistoryList(dbCtx, 10, 0)
|
||||
assert.Len(t, list1, 3)
|
||||
list2, _ = FetchIssueContentHistoryList(dbCtx, 10, 100)
|
||||
list2, _ = issues_model.FetchIssueContentHistoryList(dbCtx, 10, 100)
|
||||
assert.Len(t, list2, 3)
|
||||
assert.EqualValues(t, 8, list2[0].HistoryID)
|
||||
assert.EqualValues(t, 7, list2[1].HistoryID)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue