diff options
Diffstat (limited to 'models/issue_milestone_test.go')
-rw-r--r-- | models/issue_milestone_test.go | 67 |
1 files changed, 21 insertions, 46 deletions
diff --git a/models/issue_milestone_test.go b/models/issue_milestone_test.go index da4e77ffeb..07dd8d57c5 100644 --- a/models/issue_milestone_test.go +++ b/models/issue_milestone_test.go @@ -7,13 +7,12 @@ package models import ( "sort" "testing" - "time" api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/timeutil" - "xorm.io/builder" "github.com/stretchr/testify/assert" + "xorm.io/builder" ) func TestMilestone_State(t *testing.T) { @@ -21,28 +20,6 @@ func TestMilestone_State(t *testing.T) { assert.Equal(t, api.StateClosed, (&Milestone{IsClosed: true}).State()) } -func TestMilestone_APIFormat(t *testing.T) { - milestone := &Milestone{ - ID: 3, - RepoID: 4, - Name: "milestoneName", - Content: "milestoneContent", - IsClosed: false, - NumOpenIssues: 5, - NumClosedIssues: 6, - DeadlineUnix: timeutil.TimeStamp(time.Date(2000, time.January, 1, 0, 0, 0, 0, time.UTC).Unix()), - } - assert.Equal(t, api.Milestone{ - ID: milestone.ID, - State: api.StateOpen, - Title: milestone.Name, - Description: milestone.Content, - OpenIssues: milestone.NumOpenIssues, - ClosedIssues: milestone.NumClosedIssues, - Deadline: milestone.DeadlineUnix.AsTimePtr(), - }, *milestone.APIFormat()) -} - func TestNewMilestone(t *testing.T) { assert.NoError(t, PrepareTestDatabase()) milestone := &Milestone{ @@ -201,25 +178,6 @@ func TestCountRepoClosedMilestones(t *testing.T) { assert.EqualValues(t, 0, count) } -func TestMilestoneStats(t *testing.T) { - assert.NoError(t, PrepareTestDatabase()) - test := func(repoID int64) { - repo := AssertExistsAndLoadBean(t, &Repository{ID: repoID}).(*Repository) - open, closed, err := MilestoneStats(repoID) - assert.NoError(t, err) - assert.EqualValues(t, repo.NumMilestones-repo.NumClosedMilestones, open) - assert.EqualValues(t, repo.NumClosedMilestones, closed) - } - test(1) - test(2) - test(3) - - open, closed, err := MilestoneStats(NonexistentID) - assert.NoError(t, err) - assert.EqualValues(t, 0, open) - assert.EqualValues(t, 0, closed) -} - func TestChangeMilestoneStatus(t *testing.T) { assert.NoError(t, PrepareTestDatabase()) milestone := AssertExistsAndLoadBean(t, &Milestone{ID: 1}).(*Milestone) @@ -301,12 +259,12 @@ func TestCountMilestonesByRepoIDs(t *testing.T) { repo1OpenCount, repo1ClosedCount := milestonesCount(1) repo2OpenCount, repo2ClosedCount := milestonesCount(2) - openCounts, err := CountMilestonesByRepoIDs([]int64{1, 2}, false) + openCounts, err := CountMilestonesByRepoCond(builder.In("repo_id", []int64{1, 2}), false) assert.NoError(t, err) assert.EqualValues(t, repo1OpenCount, openCounts[1]) assert.EqualValues(t, repo2OpenCount, openCounts[2]) - closedCounts, err := CountMilestonesByRepoIDs([]int64{1, 2}, true) + closedCounts, err := CountMilestonesByRepoCond(builder.In("repo_id", []int64{1, 2}), true) assert.NoError(t, err) assert.EqualValues(t, repo1ClosedCount, closedCounts[1]) assert.EqualValues(t, repo2ClosedCount, closedCounts[2]) @@ -368,10 +326,27 @@ func TestLoadTotalTrackedTime(t *testing.T) { func TestGetMilestonesStats(t *testing.T) { assert.NoError(t, PrepareTestDatabase()) + + test := func(repoID int64) { + repo := AssertExistsAndLoadBean(t, &Repository{ID: repoID}).(*Repository) + 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) + + stats, err := GetMilestonesStatsByRepoCond(builder.And(builder.Eq{"repo_id": NonexistentID})) + assert.NoError(t, err) + assert.EqualValues(t, 0, stats.OpenCount) + assert.EqualValues(t, 0, stats.ClosedCount) + repo1 := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository) repo2 := AssertExistsAndLoadBean(t, &Repository{ID: 2}).(*Repository) - milestoneStats, err := GetMilestonesStats(builder.In("repo_id", []int64{repo1.ID, repo2.ID})) + milestoneStats, err := GetMilestonesStatsByRepoCond(builder.In("repo_id", []int64{repo1.ID, repo2.ID})) assert.NoError(t, err) assert.EqualValues(t, repo1.NumOpenMilestones+repo2.NumOpenMilestones, milestoneStats.OpenCount) assert.EqualValues(t, repo1.NumClosedMilestones+repo2.NumClosedMilestones, milestoneStats.ClosedCount) |