2017-02-09 06:39:26 +00:00
|
|
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package models
|
|
|
|
|
|
|
|
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"
|
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"
|
2019-08-15 14:46:21 +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) {
|
|
|
|
assert.Equal(t, api.StateOpen, (&Milestone{IsClosed: false}).State())
|
|
|
|
assert.Equal(t, api.StateClosed, (&Milestone{IsClosed: true}).State())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewMilestone(t *testing.T) {
|
2021-09-19 11:49:59 +00:00
|
|
|
assert.NoError(t, db.PrepareTestDatabase())
|
2017-02-09 06:39:26 +00:00
|
|
|
milestone := &Milestone{
|
|
|
|
RepoID: 1,
|
|
|
|
Name: "milestoneName",
|
|
|
|
Content: "milestoneContent",
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.NoError(t, NewMilestone(milestone))
|
2021-09-19 11:49:59 +00:00
|
|
|
db.AssertExistsAndLoadBean(t, milestone)
|
2017-02-09 06:39:26 +00:00
|
|
|
CheckConsistencyFor(t, &Repository{ID: milestone.RepoID}, &Milestone{})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetMilestoneByRepoID(t *testing.T) {
|
2021-09-19 11:49:59 +00:00
|
|
|
assert.NoError(t, db.PrepareTestDatabase())
|
2017-02-09 06:39:26 +00:00
|
|
|
|
|
|
|
milestone, err := GetMilestoneByRepoID(1, 1)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.EqualValues(t, 1, milestone.ID)
|
|
|
|
assert.EqualValues(t, 1, milestone.RepoID)
|
|
|
|
|
2021-09-19 11:49:59 +00:00
|
|
|
_, err = GetMilestoneByRepoID(db.NonexistentID, db.NonexistentID)
|
2017-02-09 06:39:26 +00:00
|
|
|
assert.True(t, IsErrMilestoneNotExist(err))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetMilestonesByRepoID(t *testing.T) {
|
2021-09-19 11:49:59 +00:00
|
|
|
assert.NoError(t, db.PrepareTestDatabase())
|
2019-06-06 00:37:45 +00:00
|
|
|
test := func(repoID int64, state api.StateType) {
|
2021-09-19 11:49:59 +00:00
|
|
|
repo := db.AssertExistsAndLoadBean(t, &Repository{ID: repoID}).(*Repository)
|
2021-08-12 12:43:08 +00:00
|
|
|
milestones, _, err := GetMilestones(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
|
|
|
|
2021-08-12 12:43:08 +00:00
|
|
|
milestones, _, err := GetMilestones(GetMilestonesOption{
|
2021-09-19 11:49:59 +00:00
|
|
|
RepoID: db.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-09-19 11:49:59 +00:00
|
|
|
assert.NoError(t, db.PrepareTestDatabase())
|
|
|
|
repo := db.AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
|
2017-02-09 06:39:26 +00:00
|
|
|
test := func(sortType string, sortCond func(*Milestone) int) {
|
|
|
|
for _, page := range []int{0, 1} {
|
2021-08-12 12:43:08 +00:00
|
|
|
milestones, _, err := GetMilestones(GetMilestonesOption{
|
2020-07-28 11:30:40 +00:00
|
|
|
ListOptions: ListOptions{
|
|
|
|
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))
|
|
|
|
|
2021-08-12 12:43:08 +00:00
|
|
|
milestones, _, err = GetMilestones(GetMilestonesOption{
|
2020-07-28 11:30:40 +00:00
|
|
|
ListOptions: ListOptions{
|
|
|
|
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))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
test("furthestduedate", func(milestone *Milestone) int {
|
|
|
|
return -int(milestone.DeadlineUnix)
|
|
|
|
})
|
|
|
|
test("leastcomplete", func(milestone *Milestone) int {
|
|
|
|
return milestone.Completeness
|
|
|
|
})
|
|
|
|
test("mostcomplete", func(milestone *Milestone) int {
|
|
|
|
return -milestone.Completeness
|
|
|
|
})
|
|
|
|
test("leastissues", func(milestone *Milestone) int {
|
|
|
|
return milestone.NumIssues
|
|
|
|
})
|
|
|
|
test("mostissues", func(milestone *Milestone) int {
|
|
|
|
return -milestone.NumIssues
|
|
|
|
})
|
|
|
|
test("soonestduedate", func(milestone *Milestone) int {
|
|
|
|
return int(milestone.DeadlineUnix)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdateMilestone(t *testing.T) {
|
2021-09-19 11:49:59 +00:00
|
|
|
assert.NoError(t, db.PrepareTestDatabase())
|
2017-02-09 06:39:26 +00:00
|
|
|
|
2021-09-19 11:49:59 +00:00
|
|
|
milestone := db.AssertExistsAndLoadBean(t, &Milestone{ID: 1}).(*Milestone)
|
2020-01-27 16:23:21 +00:00
|
|
|
milestone.Name = " newMilestoneName "
|
2017-02-09 06:39:26 +00:00
|
|
|
milestone.Content = "newMilestoneContent"
|
2020-01-29 06:36:32 +00:00
|
|
|
assert.NoError(t, UpdateMilestone(milestone, milestone.IsClosed))
|
2021-09-19 11:49:59 +00:00
|
|
|
milestone = db.AssertExistsAndLoadBean(t, &Milestone{ID: 1}).(*Milestone)
|
2020-01-27 16:23:21 +00:00
|
|
|
assert.EqualValues(t, "newMilestoneName", milestone.Name)
|
2017-02-09 06:39:26 +00:00
|
|
|
CheckConsistencyFor(t, &Milestone{})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCountRepoMilestones(t *testing.T) {
|
2021-09-19 11:49:59 +00:00
|
|
|
assert.NoError(t, db.PrepareTestDatabase())
|
2017-02-09 06:39:26 +00:00
|
|
|
test := func(repoID int64) {
|
2021-09-19 11:49:59 +00:00
|
|
|
repo := db.AssertExistsAndLoadBean(t, &Repository{ID: repoID}).(*Repository)
|
2021-09-23 15:45:36 +00:00
|
|
|
count, err := countRepoMilestones(db.GetEngine(db.DefaultContext), repoID)
|
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
|
|
|
|
2021-09-23 15:45:36 +00:00
|
|
|
count, err := countRepoMilestones(db.GetEngine(db.DefaultContext), db.NonexistentID)
|
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-09-19 11:49:59 +00:00
|
|
|
assert.NoError(t, db.PrepareTestDatabase())
|
2017-02-09 06:39:26 +00:00
|
|
|
test := func(repoID int64) {
|
2021-09-19 11:49:59 +00:00
|
|
|
repo := db.AssertExistsAndLoadBean(t, &Repository{ID: repoID}).(*Repository)
|
2017-12-18 14:06:51 +00:00
|
|
|
count, err := CountRepoClosedMilestones(repoID)
|
|
|
|
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
|
|
|
|
2021-09-19 11:49:59 +00:00
|
|
|
count, err := CountRepoClosedMilestones(db.NonexistentID)
|
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 TestChangeMilestoneStatus(t *testing.T) {
|
2021-09-19 11:49:59 +00:00
|
|
|
assert.NoError(t, db.PrepareTestDatabase())
|
|
|
|
milestone := db.AssertExistsAndLoadBean(t, &Milestone{ID: 1}).(*Milestone)
|
2017-02-09 06:39:26 +00:00
|
|
|
|
|
|
|
assert.NoError(t, ChangeMilestoneStatus(milestone, true))
|
2021-09-19 11:49:59 +00:00
|
|
|
db.AssertExistsAndLoadBean(t, &Milestone{ID: 1}, "is_closed=1")
|
2017-02-09 06:39:26 +00:00
|
|
|
CheckConsistencyFor(t, &Repository{ID: milestone.RepoID}, &Milestone{})
|
|
|
|
|
|
|
|
assert.NoError(t, ChangeMilestoneStatus(milestone, false))
|
2021-09-19 11:49:59 +00:00
|
|
|
db.AssertExistsAndLoadBean(t, &Milestone{ID: 1}, "is_closed=0")
|
2017-02-09 06:39:26 +00:00
|
|
|
CheckConsistencyFor(t, &Repository{ID: milestone.RepoID}, &Milestone{})
|
|
|
|
}
|
|
|
|
|
2021-06-21 18:34:58 +00:00
|
|
|
func TestUpdateMilestoneCounters(t *testing.T) {
|
2021-09-19 11:49:59 +00:00
|
|
|
assert.NoError(t, db.PrepareTestDatabase())
|
|
|
|
issue := db.AssertExistsAndLoadBean(t, &Issue{MilestoneID: 1},
|
2017-02-09 06:39:26 +00:00
|
|
|
"is_closed=0").(*Issue)
|
|
|
|
|
|
|
|
issue.IsClosed = true
|
2019-08-15 14:46:21 +00:00
|
|
|
issue.ClosedUnix = timeutil.TimeStampNow()
|
2021-09-23 15:45:36 +00:00
|
|
|
_, err := db.GetEngine(db.DefaultContext).ID(issue.ID).Cols("is_closed", "closed_unix").Update(issue)
|
2017-02-09 06:39:26 +00:00
|
|
|
assert.NoError(t, err)
|
2021-09-23 15:45:36 +00:00
|
|
|
assert.NoError(t, updateMilestoneCounters(db.GetEngine(db.DefaultContext), issue.MilestoneID))
|
2017-02-09 06:39:26 +00:00
|
|
|
CheckConsistencyFor(t, &Milestone{})
|
|
|
|
|
|
|
|
issue.IsClosed = false
|
2018-02-19 02:39:26 +00:00
|
|
|
issue.ClosedUnix = 0
|
2021-09-23 15:45:36 +00:00
|
|
|
_, err = db.GetEngine(db.DefaultContext).ID(issue.ID).Cols("is_closed", "closed_unix").Update(issue)
|
2017-02-09 06:39:26 +00:00
|
|
|
assert.NoError(t, err)
|
2021-09-23 15:45:36 +00:00
|
|
|
assert.NoError(t, updateMilestoneCounters(db.GetEngine(db.DefaultContext), issue.MilestoneID))
|
2017-02-09 06:39:26 +00:00
|
|
|
CheckConsistencyFor(t, &Milestone{})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestChangeMilestoneAssign(t *testing.T) {
|
2021-09-19 11:49:59 +00:00
|
|
|
assert.NoError(t, db.PrepareTestDatabase())
|
|
|
|
issue := db.AssertExistsAndLoadBean(t, &Issue{RepoID: 1}).(*Issue)
|
|
|
|
doer := db.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
|
2018-05-16 14:01:55 +00:00
|
|
|
assert.NotNil(t, issue)
|
|
|
|
assert.NotNil(t, doer)
|
2017-02-09 06:39:26 +00:00
|
|
|
|
|
|
|
oldMilestoneID := issue.MilestoneID
|
|
|
|
issue.MilestoneID = 2
|
|
|
|
assert.NoError(t, ChangeMilestoneAssign(issue, doer, oldMilestoneID))
|
2021-09-19 11:49:59 +00:00
|
|
|
db.AssertExistsAndLoadBean(t, &Comment{
|
2017-02-09 06:39:26 +00:00
|
|
|
IssueID: issue.ID,
|
|
|
|
Type: CommentTypeMilestone,
|
|
|
|
MilestoneID: issue.MilestoneID,
|
|
|
|
OldMilestoneID: oldMilestoneID,
|
|
|
|
})
|
|
|
|
CheckConsistencyFor(t, &Milestone{}, &Issue{})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDeleteMilestoneByRepoID(t *testing.T) {
|
2021-09-19 11:49:59 +00:00
|
|
|
assert.NoError(t, db.PrepareTestDatabase())
|
2017-02-09 06:39:26 +00:00
|
|
|
assert.NoError(t, DeleteMilestoneByRepoID(1, 1))
|
2021-09-19 11:49:59 +00:00
|
|
|
db.AssertNotExistsBean(t, &Milestone{ID: 1})
|
2017-02-09 06:39:26 +00:00
|
|
|
CheckConsistencyFor(t, &Repository{ID: 1})
|
|
|
|
|
2021-09-19 11:49:59 +00:00
|
|
|
assert.NoError(t, DeleteMilestoneByRepoID(db.NonexistentID, db.NonexistentID))
|
2017-02-09 06:39:26 +00:00
|
|
|
}
|
2018-04-29 05:58:47 +00:00
|
|
|
|
|
|
|
func TestMilestoneList_LoadTotalTrackedTimes(t *testing.T) {
|
2021-09-19 11:49:59 +00:00
|
|
|
assert.NoError(t, db.PrepareTestDatabase())
|
2018-04-29 05:58:47 +00:00
|
|
|
miles := MilestoneList{
|
2021-09-19 11:49:59 +00:00
|
|
|
db.AssertExistsAndLoadBean(t, &Milestone{ID: 1}).(*Milestone),
|
2018-04-29 05:58:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
assert.NoError(t, miles.LoadTotalTrackedTimes())
|
|
|
|
|
2019-12-27 20:30:58 +00:00
|
|
|
assert.Equal(t, int64(3682), miles[0].TotalTrackedTime)
|
2018-04-29 05:58:47 +00:00
|
|
|
}
|
2019-12-15 14:20:08 +00:00
|
|
|
|
|
|
|
func TestCountMilestonesByRepoIDs(t *testing.T) {
|
2021-09-19 11:49:59 +00:00
|
|
|
assert.NoError(t, db.PrepareTestDatabase())
|
2019-12-15 14:20:08 +00:00
|
|
|
milestonesCount := func(repoID int64) (int, int) {
|
2021-09-19 11:49:59 +00:00
|
|
|
repo := db.AssertExistsAndLoadBean(t, &Repository{ID: repoID}).(*Repository)
|
2019-12-15 14:20:08 +00:00
|
|
|
return repo.NumOpenMilestones, repo.NumClosedMilestones
|
|
|
|
}
|
|
|
|
repo1OpenCount, repo1ClosedCount := milestonesCount(1)
|
|
|
|
repo2OpenCount, repo2ClosedCount := milestonesCount(2)
|
|
|
|
|
2020-05-12 21:54:35 +00:00
|
|
|
openCounts, err := CountMilestonesByRepoCond(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])
|
|
|
|
|
2020-05-12 21:54:35 +00:00
|
|
|
closedCounts, err := CountMilestonesByRepoCond(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-09-19 11:49:59 +00:00
|
|
|
assert.NoError(t, db.PrepareTestDatabase())
|
|
|
|
repo1 := db.AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
|
|
|
|
repo2 := db.AssertExistsAndLoadBean(t, &Repository{ID: 2}).(*Repository)
|
2019-12-15 14:20:08 +00:00
|
|
|
test := func(sortType string, sortCond func(*Milestone) int) {
|
|
|
|
for _, page := range []int{0, 1} {
|
|
|
|
openMilestones, err := GetMilestonesByRepoIDs([]int64{repo1.ID, repo2.ID}, page, false, sortType)
|
|
|
|
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))
|
|
|
|
|
|
|
|
closedMilestones, err := GetMilestonesByRepoIDs([]int64{repo1.ID, repo2.ID}, page, true, sortType)
|
|
|
|
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))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
test("furthestduedate", func(milestone *Milestone) int {
|
|
|
|
return -int(milestone.DeadlineUnix)
|
|
|
|
})
|
|
|
|
test("leastcomplete", func(milestone *Milestone) int {
|
|
|
|
return milestone.Completeness
|
|
|
|
})
|
|
|
|
test("mostcomplete", func(milestone *Milestone) int {
|
|
|
|
return -milestone.Completeness
|
|
|
|
})
|
|
|
|
test("leastissues", func(milestone *Milestone) int {
|
|
|
|
return milestone.NumIssues
|
|
|
|
})
|
|
|
|
test("mostissues", func(milestone *Milestone) int {
|
|
|
|
return -milestone.NumIssues
|
|
|
|
})
|
|
|
|
test("soonestduedate", func(milestone *Milestone) int {
|
|
|
|
return int(milestone.DeadlineUnix)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLoadTotalTrackedTime(t *testing.T) {
|
2021-09-19 11:49:59 +00:00
|
|
|
assert.NoError(t, db.PrepareTestDatabase())
|
|
|
|
milestone := db.AssertExistsAndLoadBean(t, &Milestone{ID: 1}).(*Milestone)
|
2019-12-15 14:20:08 +00:00
|
|
|
|
|
|
|
assert.NoError(t, milestone.LoadTotalTrackedTime())
|
|
|
|
|
2019-12-27 20:30:58 +00:00
|
|
|
assert.Equal(t, int64(3682), milestone.TotalTrackedTime)
|
2019-12-15 14:20:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetMilestonesStats(t *testing.T) {
|
2021-09-19 11:49:59 +00:00
|
|
|
assert.NoError(t, db.PrepareTestDatabase())
|
2020-05-12 21:54:35 +00:00
|
|
|
|
|
|
|
test := func(repoID int64) {
|
2021-09-19 11:49:59 +00:00
|
|
|
repo := db.AssertExistsAndLoadBean(t, &Repository{ID: repoID}).(*Repository)
|
2020-05-12 21:54:35 +00:00
|
|
|
stats, err := GetMilestonesStatsByRepoCond(builder.And(builder.Eq{"repo_id": repoID}))
|
|
|
|
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)
|
|
|
|
|
2021-09-19 11:49:59 +00:00
|
|
|
stats, err := GetMilestonesStatsByRepoCond(builder.And(builder.Eq{"repo_id": db.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)
|
|
|
|
|
2021-09-19 11:49:59 +00:00
|
|
|
repo1 := db.AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
|
|
|
|
repo2 := db.AssertExistsAndLoadBean(t, &Repository{ID: 2}).(*Repository)
|
2019-12-15 14:20:08 +00:00
|
|
|
|
2020-05-12 21:54:35 +00:00
|
|
|
milestoneStats, err := GetMilestonesStatsByRepoCond(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)
|
|
|
|
}
|