mirror of https://github.com/go-gitea/gitea
Git with a cup of tea, painless self-hosted git service
Mirror for internal git.with.parts use
https://git.with.parts
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
119 lines
3.9 KiB
119 lines
3.9 KiB
5 years ago
|
// Copyright 2019 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.
|
||
|
|
||
2 years ago
|
package issues_test
|
||
7 years ago
|
|
||
|
import (
|
||
|
"testing"
|
||
5 years ago
|
"time"
|
||
7 years ago
|
|
||
3 years ago
|
"code.gitea.io/gitea/models/db"
|
||
2 years ago
|
issues_model "code.gitea.io/gitea/models/issues"
|
||
3 years ago
|
"code.gitea.io/gitea/models/unittest"
|
||
3 years ago
|
user_model "code.gitea.io/gitea/models/user"
|
||
3 years ago
|
|
||
7 years ago
|
"github.com/stretchr/testify/assert"
|
||
|
)
|
||
|
|
||
|
func TestAddTime(t *testing.T) {
|
||
3 years ago
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||
7 years ago
|
|
||
3 years ago
|
user3, err := user_model.GetUserByID(3)
|
||
7 years ago
|
assert.NoError(t, err)
|
||
|
|
||
2 years ago
|
issue1, err := issues_model.GetIssueByID(db.DefaultContext, 1)
|
||
7 years ago
|
assert.NoError(t, err)
|
||
|
|
||
4 years ago
|
// 3661 = 1h 1min 1s
|
||
2 years ago
|
trackedTime, err := issues_model.AddTime(user3, issue1, 3661, time.Now())
|
||
7 years ago
|
assert.NoError(t, err)
|
||
|
assert.Equal(t, int64(3), trackedTime.UserID)
|
||
|
assert.Equal(t, int64(1), trackedTime.IssueID)
|
||
|
assert.Equal(t, int64(3661), trackedTime.Time)
|
||
|
|
||
2 years ago
|
tt := unittest.AssertExistsAndLoadBean(t, &issues_model.TrackedTime{UserID: 3, IssueID: 1}).(*issues_model.TrackedTime)
|
||
5 years ago
|
assert.Equal(t, int64(3661), tt.Time)
|
||
7 years ago
|
|
||
2 years ago
|
comment := unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{Type: issues_model.CommentTypeAddTimeManual, PosterID: 3, IssueID: 1}).(*issues_model.Comment)
|
||
3 years ago
|
assert.Equal(t, comment.Content, "1 hour 1 minute")
|
||
7 years ago
|
}
|
||
|
|
||
|
func TestGetTrackedTimes(t *testing.T) {
|
||
3 years ago
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||
7 years ago
|
|
||
|
// by Issue
|
||
2 years ago
|
times, err := issues_model.GetTrackedTimes(db.DefaultContext, &issues_model.FindTrackedTimesOptions{IssueID: 1})
|
||
7 years ago
|
assert.NoError(t, err)
|
||
|
assert.Len(t, times, 1)
|
||
5 years ago
|
assert.Equal(t, int64(400), times[0].Time)
|
||
7 years ago
|
|
||
2 years ago
|
times, err = issues_model.GetTrackedTimes(db.DefaultContext, &issues_model.FindTrackedTimesOptions{IssueID: -1})
|
||
7 years ago
|
assert.NoError(t, err)
|
||
|
assert.Len(t, times, 0)
|
||
|
|
||
|
// by User
|
||
2 years ago
|
times, err = issues_model.GetTrackedTimes(db.DefaultContext, &issues_model.FindTrackedTimesOptions{UserID: 1})
|
||
7 years ago
|
assert.NoError(t, err)
|
||
5 years ago
|
assert.Len(t, times, 3)
|
||
|
assert.Equal(t, int64(400), times[0].Time)
|
||
7 years ago
|
|
||
2 years ago
|
times, err = issues_model.GetTrackedTimes(db.DefaultContext, &issues_model.FindTrackedTimesOptions{UserID: 3})
|
||
7 years ago
|
assert.NoError(t, err)
|
||
|
assert.Len(t, times, 0)
|
||
|
|
||
|
// by Repo
|
||
2 years ago
|
times, err = issues_model.GetTrackedTimes(db.DefaultContext, &issues_model.FindTrackedTimesOptions{RepositoryID: 2})
|
||
7 years ago
|
assert.NoError(t, err)
|
||
5 years ago
|
assert.Len(t, times, 3)
|
||
|
assert.Equal(t, int64(1), times[0].Time)
|
||
2 years ago
|
issue, err := issues_model.GetIssueByID(db.DefaultContext, times[0].IssueID)
|
||
7 years ago
|
assert.NoError(t, err)
|
||
|
assert.Equal(t, issue.RepoID, int64(2))
|
||
|
|
||
2 years ago
|
times, err = issues_model.GetTrackedTimes(db.DefaultContext, &issues_model.FindTrackedTimesOptions{RepositoryID: 1})
|
||
7 years ago
|
assert.NoError(t, err)
|
||
5 years ago
|
assert.Len(t, times, 5)
|
||
7 years ago
|
|
||
2 years ago
|
times, err = issues_model.GetTrackedTimes(db.DefaultContext, &issues_model.FindTrackedTimesOptions{RepositoryID: 10})
|
||
7 years ago
|
assert.NoError(t, err)
|
||
|
assert.Len(t, times, 0)
|
||
|
}
|
||
|
|
||
|
func TestTotalTimes(t *testing.T) {
|
||
3 years ago
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||
7 years ago
|
|
||
2 years ago
|
total, err := issues_model.TotalTimes(&issues_model.FindTrackedTimesOptions{IssueID: 1})
|
||
7 years ago
|
assert.NoError(t, err)
|
||
|
assert.Len(t, total, 1)
|
||
|
for user, time := range total {
|
||
|
assert.Equal(t, int64(1), user.ID)
|
||
3 years ago
|
assert.Equal(t, "6 minutes 40 seconds", time)
|
||
7 years ago
|
}
|
||
|
|
||
2 years ago
|
total, err = issues_model.TotalTimes(&issues_model.FindTrackedTimesOptions{IssueID: 2})
|
||
7 years ago
|
assert.NoError(t, err)
|
||
5 years ago
|
assert.Len(t, total, 2)
|
||
7 years ago
|
for user, time := range total {
|
||
5 years ago
|
if user.ID == 2 {
|
||
3 years ago
|
assert.Equal(t, "1 hour 1 minute", time)
|
||
5 years ago
|
} else if user.ID == 1 {
|
||
3 years ago
|
assert.Equal(t, "20 seconds", time)
|
||
5 years ago
|
} else {
|
||
|
assert.Error(t, assert.AnError)
|
||
|
}
|
||
7 years ago
|
}
|
||
|
|
||
2 years ago
|
total, err = issues_model.TotalTimes(&issues_model.FindTrackedTimesOptions{IssueID: 5})
|
||
7 years ago
|
assert.NoError(t, err)
|
||
|
assert.Len(t, total, 1)
|
||
|
for user, time := range total {
|
||
|
assert.Equal(t, int64(2), user.ID)
|
||
3 years ago
|
assert.Equal(t, "1 second", time)
|
||
7 years ago
|
}
|
||
|
|
||
2 years ago
|
total, err = issues_model.TotalTimes(&issues_model.FindTrackedTimesOptions{IssueID: 4})
|
||
7 years ago
|
assert.NoError(t, err)
|
||
5 years ago
|
assert.Len(t, total, 2)
|
||
7 years ago
|
}
|