2017-02-09 06:39:26 +00:00
|
|
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
2022-11-27 18:20:29 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2017-02-09 06:39:26 +00:00
|
|
|
|
2022-06-13 09:37:59 +00:00
|
|
|
package issues_test
|
2017-02-09 06:39:26 +00:00
|
|
|
|
|
|
|
import (
|
2017-06-12 15:01:09 +00:00
|
|
|
"sort"
|
2017-02-09 06:39:26 +00:00
|
|
|
"testing"
|
|
|
|
|
2021-09-19 11:49:59 +00:00
|
|
|
"code.gitea.io/gitea/models/db"
|
2022-06-13 09:37:59 +00:00
|
|
|
issues_model "code.gitea.io/gitea/models/issues"
|
2021-12-10 01:27:50 +00:00
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2021-11-12 14:36:47 +00:00
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2020-07-28 11:30:40 +00:00
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2019-05-11 10:21:34 +00:00
|
|
|
api "code.gitea.io/gitea/modules/structs"
|
2022-06-13 09:37:59 +00:00
|
|
|
"code.gitea.io/gitea/modules/timeutil"
|
2017-02-09 06:39:26 +00:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2020-05-12 21:54:35 +00:00
|
|
|
"xorm.io/builder"
|
2017-02-09 06:39:26 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestMilestone_State(t *testing.T) {
|
2022-06-13 09:37:59 +00:00
|
|
|
assert.Equal(t, api.StateOpen, (&issues_model.Milestone{IsClosed: false}).State())
|
|
|
|
assert.Equal(t, api.StateClosed, (&issues_model.Milestone{IsClosed: true}).State())
|
2017-02-09 06:39:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetMilestoneByRepoID(t *testing.T) {
|
2021-11-12 14:36:47 +00:00
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2017-02-09 06:39:26 +00:00
|
|
|
|
2022-06-13 09:37:59 +00:00
|
|
|
milestone, err := issues_model.GetMilestoneByRepoID(db.DefaultContext, 1, 1)
|
2017-02-09 06:39:26 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.EqualValues(t, 1, milestone.ID)
|
|
|
|
assert.EqualValues(t, 1, milestone.RepoID)
|
|
|
|
|
2022-06-13 09:37:59 +00:00
|
|
|
_, err = issues_model.GetMilestoneByRepoID(db.DefaultContext, unittest.NonexistentID, unittest.NonexistentID)
|
|
|
|
assert.True(t, issues_model.IsErrMilestoneNotExist(err))
|
2017-02-09 06:39:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetMilestonesByRepoID(t *testing.T) {
|
2021-11-12 14:36:47 +00:00
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2019-06-06 00:37:45 +00:00
|
|
|
test := func(repoID int64, state api.StateType) {
|
2022-08-16 02:22:25 +00:00
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: repoID})
|
2023-10-11 04:24:07 +00:00
|
|
|
milestones, _, err := issues_model.GetMilestones(db.DefaultContext, issues_model.GetMilestonesOption{
|
2020-07-28 11:30:40 +00:00
|
|
|
RepoID: repo.ID,
|
|
|
|
State: state,
|
|
|
|
})
|
2017-02-09 06:39:26 +00:00
|
|
|
assert.NoError(t, err)
|
2019-06-06 00:37:45 +00:00
|
|
|
|
|
|
|
var n int
|
|
|
|
|
|
|
|
switch state {
|
|
|
|
case api.StateClosed:
|
|
|
|
n = repo.NumClosedMilestones
|
|
|
|
|
|
|
|
case api.StateAll:
|
|
|
|
n = repo.NumMilestones
|
|
|
|
|
|
|
|
case api.StateOpen:
|
|
|
|
fallthrough
|
|
|
|
|
|
|
|
default:
|
|
|
|
n = repo.NumOpenMilestones
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Len(t, milestones, n)
|
2017-02-09 06:39:26 +00:00
|
|
|
for _, milestone := range milestones {
|
|
|
|
assert.EqualValues(t, repoID, milestone.RepoID)
|
|
|
|
}
|
|
|
|
}
|
2019-06-06 00:37:45 +00:00
|
|
|
test(1, api.StateOpen)
|
|
|
|
test(1, api.StateAll)
|
|
|
|
test(1, api.StateClosed)
|
|
|
|
test(2, api.StateOpen)
|
|
|
|
test(2, api.StateAll)
|
|
|
|
test(2, api.StateClosed)
|
|
|
|
test(3, api.StateOpen)
|
|
|
|
test(3, api.StateClosed)
|
|
|
|
test(3, api.StateAll)
|
2017-02-09 06:39:26 +00:00
|
|
|
|
2023-10-11 04:24:07 +00:00
|
|
|
milestones, _, err := issues_model.GetMilestones(db.DefaultContext, issues_model.GetMilestonesOption{
|
2021-11-16 08:53:21 +00:00
|
|
|
RepoID: unittest.NonexistentID,
|
2020-07-28 11:30:40 +00:00
|
|
|
State: api.StateOpen,
|
|
|
|
})
|
2017-02-09 06:39:26 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Len(t, milestones, 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetMilestones(t *testing.T) {
|
2021-11-12 14:36:47 +00:00
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2022-08-16 02:22:25 +00:00
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
2022-06-13 09:37:59 +00:00
|
|
|
test := func(sortType string, sortCond func(*issues_model.Milestone) int) {
|
2017-02-09 06:39:26 +00:00
|
|
|
for _, page := range []int{0, 1} {
|
2023-10-11 04:24:07 +00:00
|
|
|
milestones, _, err := issues_model.GetMilestones(db.DefaultContext, issues_model.GetMilestonesOption{
|
2021-09-24 11:32:56 +00:00
|
|
|
ListOptions: db.ListOptions{
|
2020-07-28 11:30:40 +00:00
|
|
|
Page: page,
|
|
|
|
PageSize: setting.UI.IssuePagingNum,
|
|
|
|
},
|
|
|
|
RepoID: repo.ID,
|
|
|
|
State: api.StateOpen,
|
|
|
|
SortType: sortType,
|
|
|
|
})
|
2017-02-09 06:39:26 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Len(t, milestones, repo.NumMilestones-repo.NumClosedMilestones)
|
|
|
|
values := make([]int, len(milestones))
|
|
|
|
for i, milestone := range milestones {
|
|
|
|
values[i] = sortCond(milestone)
|
|
|
|
}
|
|
|
|
assert.True(t, sort.IntsAreSorted(values))
|
|
|
|
|
2023-10-11 04:24:07 +00:00
|
|
|
milestones, _, err = issues_model.GetMilestones(db.DefaultContext, issues_model.GetMilestonesOption{
|
2021-09-24 11:32:56 +00:00
|
|
|
ListOptions: db.ListOptions{
|
2020-07-28 11:30:40 +00:00
|
|
|
Page: page,
|
|
|
|
PageSize: setting.UI.IssuePagingNum,
|
|
|
|
},
|
|
|
|
RepoID: repo.ID,
|
|
|
|
State: api.StateClosed,
|
|
|
|
Name: "",
|
|
|
|
SortType: sortType,
|
|
|
|
})
|
2017-02-09 06:39:26 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Len(t, milestones, repo.NumClosedMilestones)
|
|
|
|
values = make([]int, len(milestones))
|
|
|
|
for i, milestone := range milestones {
|
|
|
|
values[i] = sortCond(milestone)
|
|
|
|
}
|
|
|
|
assert.True(t, sort.IntsAreSorted(values))
|
|
|
|
}
|
|
|
|
}
|
2022-06-13 09:37:59 +00:00
|
|
|
test("furthestduedate", func(milestone *issues_model.Milestone) int {
|
2017-02-09 06:39:26 +00:00
|
|
|
return -int(milestone.DeadlineUnix)
|
|
|
|
})
|
2022-06-13 09:37:59 +00:00
|
|
|
test("leastcomplete", func(milestone *issues_model.Milestone) int {
|
2017-02-09 06:39:26 +00:00
|
|
|
return milestone.Completeness
|
|
|
|
})
|
2022-06-13 09:37:59 +00:00
|
|
|
test("mostcomplete", func(milestone *issues_model.Milestone) int {
|
2017-02-09 06:39:26 +00:00
|
|
|
return -milestone.Completeness
|
|
|
|
})
|
2022-06-13 09:37:59 +00:00
|
|
|
test("leastissues", func(milestone *issues_model.Milestone) int {
|
2017-02-09 06:39:26 +00:00
|
|
|
return milestone.NumIssues
|
|
|
|
})
|
2022-06-13 09:37:59 +00:00
|
|
|
test("mostissues", func(milestone *issues_model.Milestone) int {
|
2017-02-09 06:39:26 +00:00
|
|
|
return -milestone.NumIssues
|
|
|
|
})
|
2022-06-13 09:37:59 +00:00
|
|
|
test("soonestduedate", func(milestone *issues_model.Milestone) int {
|
2017-02-09 06:39:26 +00:00
|
|
|
return int(milestone.DeadlineUnix)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCountRepoMilestones(t *testing.T) {
|
2021-11-12 14:36:47 +00:00
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2017-02-09 06:39:26 +00:00
|
|
|
test := func(repoID int64) {
|
2022-08-16 02:22:25 +00:00
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: repoID})
|
2022-06-13 09:37:59 +00:00
|
|
|
count, err := issues_model.CountMilestones(db.DefaultContext, issues_model.GetMilestonesOption{
|
|
|
|
RepoID: repoID,
|
|
|
|
State: api.StateAll,
|
|
|
|
})
|
2017-12-18 14:06:51 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.EqualValues(t, repo.NumMilestones, count)
|
2017-02-09 06:39:26 +00:00
|
|
|
}
|
|
|
|
test(1)
|
|
|
|
test(2)
|
|
|
|
test(3)
|
2017-12-18 14:06:51 +00:00
|
|
|
|
2022-06-13 09:37:59 +00:00
|
|
|
count, err := issues_model.CountMilestones(db.DefaultContext, issues_model.GetMilestonesOption{
|
|
|
|
RepoID: unittest.NonexistentID,
|
|
|
|
State: api.StateAll,
|
|
|
|
})
|
2017-12-18 14:06:51 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.EqualValues(t, 0, count)
|
2017-02-09 06:39:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCountRepoClosedMilestones(t *testing.T) {
|
2021-11-12 14:36:47 +00:00
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2017-02-09 06:39:26 +00:00
|
|
|
test := func(repoID int64) {
|
2022-08-16 02:22:25 +00:00
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: repoID})
|
2022-06-13 09:37:59 +00:00
|
|
|
count, err := issues_model.CountMilestones(db.DefaultContext, issues_model.GetMilestonesOption{
|
|
|
|
RepoID: repoID,
|
|
|
|
State: api.StateClosed,
|
|
|
|
})
|
2017-12-18 14:06:51 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.EqualValues(t, repo.NumClosedMilestones, count)
|
2017-02-09 06:39:26 +00:00
|
|
|
}
|
|
|
|
test(1)
|
|
|
|
test(2)
|
|
|
|
test(3)
|
2017-12-18 14:06:51 +00:00
|
|
|
|
2022-06-13 09:37:59 +00:00
|
|
|
count, err := issues_model.CountMilestones(db.DefaultContext, issues_model.GetMilestonesOption{
|
|
|
|
RepoID: unittest.NonexistentID,
|
|
|
|
State: api.StateClosed,
|
|
|
|
})
|
2017-12-18 14:06:51 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.EqualValues(t, 0, count)
|
2017-02-09 06:39:26 +00:00
|
|
|
}
|
|
|
|
|
2019-12-15 14:20:08 +00:00
|
|
|
func TestCountMilestonesByRepoIDs(t *testing.T) {
|
2021-11-12 14:36:47 +00:00
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2019-12-15 14:20:08 +00:00
|
|
|
milestonesCount := func(repoID int64) (int, int) {
|
2022-08-16 02:22:25 +00:00
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: repoID})
|
2019-12-15 14:20:08 +00:00
|
|
|
return repo.NumOpenMilestones, repo.NumClosedMilestones
|
|
|
|
}
|
|
|
|
repo1OpenCount, repo1ClosedCount := milestonesCount(1)
|
|
|
|
repo2OpenCount, repo2ClosedCount := milestonesCount(2)
|
|
|
|
|
2023-09-16 14:39:12 +00:00
|
|
|
openCounts, err := issues_model.CountMilestonesByRepoCond(db.DefaultContext, builder.In("repo_id", []int64{1, 2}), false)
|
2019-12-15 14:20:08 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.EqualValues(t, repo1OpenCount, openCounts[1])
|
|
|
|
assert.EqualValues(t, repo2OpenCount, openCounts[2])
|
|
|
|
|
2023-09-16 14:39:12 +00:00
|
|
|
closedCounts, err := issues_model.CountMilestonesByRepoCond(db.DefaultContext, builder.In("repo_id", []int64{1, 2}), true)
|
2019-12-15 14:20:08 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.EqualValues(t, repo1ClosedCount, closedCounts[1])
|
|
|
|
assert.EqualValues(t, repo2ClosedCount, closedCounts[2])
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetMilestonesByRepoIDs(t *testing.T) {
|
2021-11-12 14:36:47 +00:00
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2022-08-16 02:22:25 +00:00
|
|
|
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
|
|
|
repo2 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2})
|
2022-06-13 09:37:59 +00:00
|
|
|
test := func(sortType string, sortCond func(*issues_model.Milestone) int) {
|
2019-12-15 14:20:08 +00:00
|
|
|
for _, page := range []int{0, 1} {
|
2023-09-16 14:39:12 +00:00
|
|
|
openMilestones, err := issues_model.GetMilestonesByRepoIDs(db.DefaultContext, []int64{repo1.ID, repo2.ID}, page, false, sortType)
|
2019-12-15 14:20:08 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Len(t, openMilestones, repo1.NumOpenMilestones+repo2.NumOpenMilestones)
|
|
|
|
values := make([]int, len(openMilestones))
|
|
|
|
for i, milestone := range openMilestones {
|
|
|
|
values[i] = sortCond(milestone)
|
|
|
|
}
|
|
|
|
assert.True(t, sort.IntsAreSorted(values))
|
|
|
|
|
2023-09-16 14:39:12 +00:00
|
|
|
closedMilestones, err := issues_model.GetMilestonesByRepoIDs(db.DefaultContext, []int64{repo1.ID, repo2.ID}, page, true, sortType)
|
2019-12-15 14:20:08 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Len(t, closedMilestones, repo1.NumClosedMilestones+repo2.NumClosedMilestones)
|
|
|
|
values = make([]int, len(closedMilestones))
|
|
|
|
for i, milestone := range closedMilestones {
|
|
|
|
values[i] = sortCond(milestone)
|
|
|
|
}
|
|
|
|
assert.True(t, sort.IntsAreSorted(values))
|
|
|
|
}
|
|
|
|
}
|
2022-06-13 09:37:59 +00:00
|
|
|
test("furthestduedate", func(milestone *issues_model.Milestone) int {
|
2019-12-15 14:20:08 +00:00
|
|
|
return -int(milestone.DeadlineUnix)
|
|
|
|
})
|
2022-06-13 09:37:59 +00:00
|
|
|
test("leastcomplete", func(milestone *issues_model.Milestone) int {
|
2019-12-15 14:20:08 +00:00
|
|
|
return milestone.Completeness
|
|
|
|
})
|
2022-06-13 09:37:59 +00:00
|
|
|
test("mostcomplete", func(milestone *issues_model.Milestone) int {
|
2019-12-15 14:20:08 +00:00
|
|
|
return -milestone.Completeness
|
|
|
|
})
|
2022-06-13 09:37:59 +00:00
|
|
|
test("leastissues", func(milestone *issues_model.Milestone) int {
|
2019-12-15 14:20:08 +00:00
|
|
|
return milestone.NumIssues
|
|
|
|
})
|
2022-06-13 09:37:59 +00:00
|
|
|
test("mostissues", func(milestone *issues_model.Milestone) int {
|
2019-12-15 14:20:08 +00:00
|
|
|
return -milestone.NumIssues
|
|
|
|
})
|
2022-06-13 09:37:59 +00:00
|
|
|
test("soonestduedate", func(milestone *issues_model.Milestone) int {
|
2019-12-15 14:20:08 +00:00
|
|
|
return int(milestone.DeadlineUnix)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetMilestonesStats(t *testing.T) {
|
2021-11-12 14:36:47 +00:00
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2020-05-12 21:54:35 +00:00
|
|
|
|
|
|
|
test := func(repoID int64) {
|
2022-08-16 02:22:25 +00:00
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: repoID})
|
2023-09-16 14:39:12 +00:00
|
|
|
stats, err := issues_model.GetMilestonesStatsByRepoCond(db.DefaultContext, builder.And(builder.Eq{"repo_id": repoID}))
|
2020-05-12 21:54:35 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.EqualValues(t, repo.NumMilestones-repo.NumClosedMilestones, stats.OpenCount)
|
|
|
|
assert.EqualValues(t, repo.NumClosedMilestones, stats.ClosedCount)
|
|
|
|
}
|
|
|
|
test(1)
|
|
|
|
test(2)
|
|
|
|
test(3)
|
|
|
|
|
2023-09-16 14:39:12 +00:00
|
|
|
stats, err := issues_model.GetMilestonesStatsByRepoCond(db.DefaultContext, builder.And(builder.Eq{"repo_id": unittest.NonexistentID}))
|
2020-05-12 21:54:35 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.EqualValues(t, 0, stats.OpenCount)
|
|
|
|
assert.EqualValues(t, 0, stats.ClosedCount)
|
|
|
|
|
2022-08-16 02:22:25 +00:00
|
|
|
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
|
|
|
repo2 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2})
|
2019-12-15 14:20:08 +00:00
|
|
|
|
2023-09-16 14:39:12 +00:00
|
|
|
milestoneStats, err := issues_model.GetMilestonesStatsByRepoCond(db.DefaultContext, builder.In("repo_id", []int64{repo1.ID, repo2.ID}))
|
2019-12-15 14:20:08 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.EqualValues(t, repo1.NumOpenMilestones+repo2.NumOpenMilestones, milestoneStats.OpenCount)
|
|
|
|
assert.EqualValues(t, repo1.NumClosedMilestones+repo2.NumClosedMilestones, milestoneStats.ClosedCount)
|
|
|
|
}
|
2022-06-13 09:37:59 +00:00
|
|
|
|
|
|
|
func TestNewMilestone(t *testing.T) {
|
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
|
|
milestone := &issues_model.Milestone{
|
|
|
|
RepoID: 1,
|
|
|
|
Name: "milestoneName",
|
|
|
|
Content: "milestoneContent",
|
|
|
|
}
|
|
|
|
|
2023-09-16 14:39:12 +00:00
|
|
|
assert.NoError(t, issues_model.NewMilestone(db.DefaultContext, milestone))
|
2022-06-13 09:37:59 +00:00
|
|
|
unittest.AssertExistsAndLoadBean(t, milestone)
|
|
|
|
unittest.CheckConsistencyFor(t, &repo_model.Repository{ID: milestone.RepoID}, &issues_model.Milestone{})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestChangeMilestoneStatus(t *testing.T) {
|
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2022-08-16 02:22:25 +00:00
|
|
|
milestone := unittest.AssertExistsAndLoadBean(t, &issues_model.Milestone{ID: 1})
|
2022-06-13 09:37:59 +00:00
|
|
|
|
2023-09-16 14:39:12 +00:00
|
|
|
assert.NoError(t, issues_model.ChangeMilestoneStatus(db.DefaultContext, milestone, true))
|
2022-06-13 09:37:59 +00:00
|
|
|
unittest.AssertExistsAndLoadBean(t, &issues_model.Milestone{ID: 1}, "is_closed=1")
|
|
|
|
unittest.CheckConsistencyFor(t, &repo_model.Repository{ID: milestone.RepoID}, &issues_model.Milestone{})
|
|
|
|
|
2023-09-16 14:39:12 +00:00
|
|
|
assert.NoError(t, issues_model.ChangeMilestoneStatus(db.DefaultContext, milestone, false))
|
2022-06-13 09:37:59 +00:00
|
|
|
unittest.AssertExistsAndLoadBean(t, &issues_model.Milestone{ID: 1}, "is_closed=0")
|
|
|
|
unittest.CheckConsistencyFor(t, &repo_model.Repository{ID: milestone.RepoID}, &issues_model.Milestone{})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDeleteMilestoneByRepoID(t *testing.T) {
|
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2023-09-16 14:39:12 +00:00
|
|
|
assert.NoError(t, issues_model.DeleteMilestoneByRepoID(db.DefaultContext, 1, 1))
|
2022-06-13 09:37:59 +00:00
|
|
|
unittest.AssertNotExistsBean(t, &issues_model.Milestone{ID: 1})
|
|
|
|
unittest.CheckConsistencyFor(t, &repo_model.Repository{ID: 1})
|
|
|
|
|
2023-09-16 14:39:12 +00:00
|
|
|
assert.NoError(t, issues_model.DeleteMilestoneByRepoID(db.DefaultContext, unittest.NonexistentID, unittest.NonexistentID))
|
2022-06-13 09:37:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdateMilestone(t *testing.T) {
|
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
|
|
|
2022-08-16 02:22:25 +00:00
|
|
|
milestone := unittest.AssertExistsAndLoadBean(t, &issues_model.Milestone{ID: 1})
|
2022-06-13 09:37:59 +00:00
|
|
|
milestone.Name = " newMilestoneName "
|
|
|
|
milestone.Content = "newMilestoneContent"
|
2023-09-16 14:39:12 +00:00
|
|
|
assert.NoError(t, issues_model.UpdateMilestone(db.DefaultContext, milestone, milestone.IsClosed))
|
2022-08-16 02:22:25 +00:00
|
|
|
milestone = unittest.AssertExistsAndLoadBean(t, &issues_model.Milestone{ID: 1})
|
2022-06-13 09:37:59 +00:00
|
|
|
assert.EqualValues(t, "newMilestoneName", milestone.Name)
|
|
|
|
unittest.CheckConsistencyFor(t, &issues_model.Milestone{})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdateMilestoneCounters(t *testing.T) {
|
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
|
|
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{MilestoneID: 1},
|
2022-08-16 02:22:25 +00:00
|
|
|
"is_closed=0")
|
2022-06-13 09:37:59 +00:00
|
|
|
|
|
|
|
issue.IsClosed = true
|
|
|
|
issue.ClosedUnix = timeutil.TimeStampNow()
|
|
|
|
_, err := db.GetEngine(db.DefaultContext).ID(issue.ID).Cols("is_closed", "closed_unix").Update(issue)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NoError(t, issues_model.UpdateMilestoneCounters(db.DefaultContext, issue.MilestoneID))
|
|
|
|
unittest.CheckConsistencyFor(t, &issues_model.Milestone{})
|
|
|
|
|
|
|
|
issue.IsClosed = false
|
|
|
|
issue.ClosedUnix = 0
|
|
|
|
_, err = db.GetEngine(db.DefaultContext).ID(issue.ID).Cols("is_closed", "closed_unix").Update(issue)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NoError(t, issues_model.UpdateMilestoneCounters(db.DefaultContext, issue.MilestoneID))
|
|
|
|
unittest.CheckConsistencyFor(t, &issues_model.Milestone{})
|
|
|
|
}
|
2023-09-08 21:09:23 +00:00
|
|
|
|
|
|
|
func TestMigrate_InsertMilestones(t *testing.T) {
|
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
|
|
reponame := "repo1"
|
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{Name: reponame})
|
|
|
|
name := "milestonetest1"
|
|
|
|
ms := &issues_model.Milestone{
|
|
|
|
RepoID: repo.ID,
|
|
|
|
Name: name,
|
|
|
|
}
|
2023-09-16 14:39:12 +00:00
|
|
|
err := issues_model.InsertMilestones(db.DefaultContext, ms)
|
2023-09-08 21:09:23 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
unittest.AssertExistsAndLoadBean(t, ms)
|
|
|
|
repoModified := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: repo.ID})
|
|
|
|
assert.EqualValues(t, repo.NumMilestones+1, repoModified.NumMilestones)
|
|
|
|
|
|
|
|
unittest.CheckConsistencyFor(t, &issues_model.Milestone{})
|
|
|
|
}
|