1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

chore: adapt tests and bump version

This commit is contained in:
Ferdinand Mütsch 2021-06-12 11:26:15 +02:00
parent 1e4e530c21
commit 7bcd6890d1
4 changed files with 557 additions and 532 deletions

File diff suppressed because it is too large Load Diff

View File

@ -6,7 +6,7 @@ import (
"time" "time"
) )
func TestSummary_FillUnknown(t *testing.T) { func TestSummary_FillMissing(t *testing.T) {
testDuration := 10 * time.Minute testDuration := 10 * time.Minute
sut := &Summary{ sut := &Summary{
@ -33,6 +33,10 @@ func TestSummary_FillUnknown(t *testing.T) {
assert.Equal(t, UnknownSummaryKey, l[0].Key) assert.Equal(t, UnknownSummaryKey, l[0].Key)
assert.Equal(t, testDuration, l[0].TotalFixed()) assert.Equal(t, testDuration, l[0].TotalFixed())
} }
assert.Len(t, sut.Labels, 1)
assert.Equal(t, DefaultProjectLabel, sut.Labels[0].Key)
assert.Equal(t, testDuration, sut.Labels[0].TotalFixed())
} }
func TestSummary_TotalTimeBy(t *testing.T) { func TestSummary_TotalTimeBy(t *testing.T) {

View File

@ -16,6 +16,9 @@ const (
TestUserId = "muety" TestUserId = "muety"
TestProject1 = "test-project-1" TestProject1 = "test-project-1"
TestProject2 = "test-project-2" TestProject2 = "test-project-2"
TestProjectLabel1 = "private"
TestProjectLabel2 = "work"
TestProjectLabel3 = "non-existing"
TestLanguageGo = "Go" TestLanguageGo = "Go"
TestLanguageJava = "Java" TestLanguageJava = "Java"
TestLanguagePython = "Python" TestLanguagePython = "Python"
@ -34,6 +37,7 @@ type SummaryServiceTestSuite struct {
TestUser *models.User TestUser *models.User
TestStartTime time.Time TestStartTime time.Time
TestHeartbeats []*models.Heartbeat TestHeartbeats []*models.Heartbeat
TestLabels []*models.ProjectLabel
SummaryRepository *mocks.SummaryRepositoryMock SummaryRepository *mocks.SummaryRepositoryMock
HeartbeatService *mocks.HeartbeatServiceMock HeartbeatService *mocks.HeartbeatServiceMock
AliasService *mocks.AliasServiceMock AliasService *mocks.AliasServiceMock
@ -76,6 +80,20 @@ func (suite *SummaryServiceTestSuite) SetupSuite() {
Time: models.CustomTime(suite.TestStartTime.Add(3 * time.Minute)), Time: models.CustomTime(suite.TestStartTime.Add(3 * time.Minute)),
}, },
} }
suite.TestLabels = []*models.ProjectLabel{
{
ID: uint(rand.Uint32()),
UserID: TestUserId,
ProjectKey: TestProject1,
Label: TestProjectLabel1,
},
{
ID: uint(rand.Uint32()),
UserID: TestUserId,
ProjectKey: TestProjectLabel3,
Label: "blaahh",
},
}
} }
func (suite *SummaryServiceTestSuite) BeforeTest(suiteName, testName string) { func (suite *SummaryServiceTestSuite) BeforeTest(suiteName, testName string) {
@ -92,8 +110,6 @@ func TestSummaryServiceTestSuite(t *testing.T) {
func (suite *SummaryServiceTestSuite) TestSummaryService_Summarize() { func (suite *SummaryServiceTestSuite) TestSummaryService_Summarize() {
sut := NewSummaryService(suite.SummaryRepository, suite.HeartbeatService, suite.AliasService, suite.ProjectLabelService) sut := NewSummaryService(suite.SummaryRepository, suite.HeartbeatService, suite.AliasService, suite.ProjectLabelService)
suite.ProjectLabelService.On("GetByUser", suite.TestUser.ID).Return([]*models.ProjectLabel{}, nil)
var ( var (
from time.Time from time.Time
to time.Time to time.Time
@ -104,6 +120,7 @@ func (suite *SummaryServiceTestSuite) TestSummaryService_Summarize() {
/* TEST 1 */ /* TEST 1 */
from, to = suite.TestStartTime.Add(-1*time.Hour), suite.TestStartTime.Add(-1*time.Minute) from, to = suite.TestStartTime.Add(-1*time.Hour), suite.TestStartTime.Add(-1*time.Minute)
suite.HeartbeatService.On("GetAllWithin", from, to, suite.TestUser).Return(filter(from, to, suite.TestHeartbeats), nil) suite.HeartbeatService.On("GetAllWithin", from, to, suite.TestUser).Return(filter(from, to, suite.TestHeartbeats), nil)
suite.ProjectLabelService.On("GetByUser", suite.TestUser.ID).Return([]*models.ProjectLabel{}, nil).Once()
result, err = sut.Summarize(from, to, suite.TestUser) result, err = sut.Summarize(from, to, suite.TestUser)
@ -117,6 +134,7 @@ func (suite *SummaryServiceTestSuite) TestSummaryService_Summarize() {
/* TEST 2 */ /* TEST 2 */
from, to = suite.TestStartTime.Add(-1*time.Hour), suite.TestStartTime.Add(1*time.Second) from, to = suite.TestStartTime.Add(-1*time.Hour), suite.TestStartTime.Add(1*time.Second)
suite.HeartbeatService.On("GetAllWithin", from, to, suite.TestUser).Return(filter(from, to, suite.TestHeartbeats), nil) suite.HeartbeatService.On("GetAllWithin", from, to, suite.TestUser).Return(filter(from, to, suite.TestHeartbeats), nil)
suite.ProjectLabelService.On("GetByUser", suite.TestUser.ID).Return([]*models.ProjectLabel{}, nil).Once()
result, err = sut.Summarize(from, to, suite.TestUser) result, err = sut.Summarize(from, to, suite.TestUser)
@ -130,6 +148,7 @@ func (suite *SummaryServiceTestSuite) TestSummaryService_Summarize() {
/* TEST 3 */ /* TEST 3 */
from, to = suite.TestStartTime, suite.TestStartTime.Add(1*time.Hour) from, to = suite.TestStartTime, suite.TestStartTime.Add(1*time.Hour)
suite.HeartbeatService.On("GetAllWithin", from, to, suite.TestUser).Return(filter(from, to, suite.TestHeartbeats), nil) suite.HeartbeatService.On("GetAllWithin", from, to, suite.TestUser).Return(filter(from, to, suite.TestHeartbeats), nil)
suite.ProjectLabelService.On("GetByUser", suite.TestUser.ID).Return(suite.TestLabels, nil).Once()
result, err = sut.Summarize(from, to, suite.TestUser) result, err = sut.Summarize(from, to, suite.TestUser)
@ -140,6 +159,8 @@ func (suite *SummaryServiceTestSuite) TestSummaryService_Summarize() {
assert.Equal(suite.T(), 150*time.Second, result.TotalTime()) assert.Equal(suite.T(), 150*time.Second, result.TotalTime())
assert.Equal(suite.T(), 30*time.Second, result.TotalTimeByKey(models.SummaryEditor, TestEditorGoland)) assert.Equal(suite.T(), 30*time.Second, result.TotalTimeByKey(models.SummaryEditor, TestEditorGoland))
assert.Equal(suite.T(), 120*time.Second, result.TotalTimeByKey(models.SummaryEditor, TestEditorVscode)) assert.Equal(suite.T(), 120*time.Second, result.TotalTimeByKey(models.SummaryEditor, TestEditorVscode))
assert.Equal(suite.T(), 150*time.Second, result.TotalTimeByKey(models.SummaryLabel, TestProjectLabel1))
assert.Zero(suite.T(), result.TotalTimeByKey(models.SummaryLabel, TestProjectLabel3))
assert.Len(suite.T(), result.Editors, 2) assert.Len(suite.T(), result.Editors, 2)
assertNumAllItems(suite.T(), 1, result, "e") assertNumAllItems(suite.T(), 1, result, "e")
} }

View File

@ -1 +1 @@
1.27.4 1.28.0