mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
chore: add more filtering unit tests
This commit is contained in:
parent
fe3ba79d54
commit
bf82935849
File diff suppressed because it is too large
Load Diff
@ -14,6 +14,7 @@ const (
|
||||
TestUserId = "muety"
|
||||
TestProject1 = "test-project-1"
|
||||
TestProject2 = "test-project-2"
|
||||
TestProject3 = "test-project-3"
|
||||
TestLanguageGo = "Go"
|
||||
TestLanguageJava = "Java"
|
||||
TestLanguagePython = "Python"
|
||||
@ -161,6 +162,27 @@ func (suite *DurationServiceTestSuite) TestDurationService_Get() {
|
||||
assert.Equal(suite.T(), 3, durations[2].NumHeartbeats)
|
||||
}
|
||||
|
||||
func (suite *DurationServiceTestSuite) TestDurationService_Get_Filtered() {
|
||||
sut := NewDurationService(suite.HeartbeatService)
|
||||
|
||||
var (
|
||||
from time.Time
|
||||
to time.Time
|
||||
durations models.Durations
|
||||
err error
|
||||
)
|
||||
|
||||
from, to = suite.TestStartTime.Add(-1*time.Hour), suite.TestStartTime.Add(1*time.Hour)
|
||||
suite.HeartbeatService.On("GetAllWithin", from, to, suite.TestUser).Return(filterHeartbeats(from, to, suite.TestHeartbeats), nil)
|
||||
|
||||
durations, err = sut.Get(from, to, suite.TestUser, models.NewFiltersWith(models.SummaryEditor, TestEditorGoland))
|
||||
assert.Nil(suite.T(), err)
|
||||
assert.Len(suite.T(), durations, 2)
|
||||
for _, d := range durations {
|
||||
assert.Equal(suite.T(), TestEditorGoland, d.Editor)
|
||||
}
|
||||
}
|
||||
|
||||
func filterHeartbeats(from, to time.Time, heartbeats []*models.Heartbeat) []*models.Heartbeat {
|
||||
filtered := make([]*models.Heartbeat, 0, len(heartbeats))
|
||||
for _, h := range heartbeats {
|
||||
|
@ -79,8 +79,8 @@ func (suite *SummaryServiceTestSuite) SetupSuite() {
|
||||
{
|
||||
ID: uint(rand.Uint32()),
|
||||
UserID: TestUserId,
|
||||
ProjectKey: TestProjectLabel3,
|
||||
Label: "blaahh",
|
||||
ProjectKey: TestProject3,
|
||||
Label: TestProjectLabel3,
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -386,7 +386,7 @@ func (suite *SummaryServiceTestSuite) TestSummaryService_Aliased() {
|
||||
Duration: 0, // not relevant here
|
||||
})
|
||||
|
||||
suite.DurationService.On("Get", from, to, suite.TestUser, mock.Anything).Return(models.Durations(durations), nil)
|
||||
suite.DurationService.On("Get", from, to, suite.TestUser, mock.Anything).Return(durations, nil)
|
||||
suite.AliasService.On("InitializeUser", TestUserId).Return(nil)
|
||||
suite.AliasService.On("GetAliasOrDefault", TestUserId, mock.Anything, TestProject1).Return(TestProject2, nil)
|
||||
suite.AliasService.On("GetAliasOrDefault", TestUserId, mock.Anything, TestProject2).Return(TestProject2, nil)
|
||||
@ -441,6 +441,38 @@ func (suite *SummaryServiceTestSuite) TestSummaryService_Aliased_ProjectLabels()
|
||||
assert.Equal(suite.T(), 6, result.NumHeartbeats)
|
||||
}
|
||||
|
||||
func (suite *SummaryServiceTestSuite) TestSummaryService_Filters() {
|
||||
sut := NewSummaryService(suite.SummaryRepository, suite.DurationService, suite.AliasService, suite.ProjectLabelService)
|
||||
|
||||
suite.AliasService.On("InitializeUser", suite.TestUser.ID).Return(nil)
|
||||
suite.ProjectLabelService.On("GetByUser", suite.TestUser.ID).Return([]*models.ProjectLabel{}, nil)
|
||||
|
||||
from, to := suite.TestStartTime, suite.TestStartTime.Add(1*time.Hour)
|
||||
filters := models.NewFiltersWith(models.SummaryProject, TestProject1).With(models.SummaryLabel, TestProjectLabel3)
|
||||
|
||||
suite.DurationService.On("Get", from, to, suite.TestUser, mock.Anything).Return(models.Durations{}, nil)
|
||||
suite.AliasService.On("InitializeUser", TestUserId).Return(nil)
|
||||
suite.AliasService.On("GetByUserAndKeyAndType", TestUserId, TestProject1, models.SummaryProject).Return([]*models.Alias{
|
||||
{
|
||||
Type: models.SummaryProject,
|
||||
Key: TestProject1,
|
||||
Value: TestProject2,
|
||||
},
|
||||
}, nil)
|
||||
suite.ProjectLabelService.On("GetByUserGroupedInverted", suite.TestUser.ID).Return(map[string][]*models.ProjectLabel{
|
||||
suite.TestLabels[0].Label: suite.TestLabels[0:1],
|
||||
suite.TestLabels[1].Label: suite.TestLabels[1:2],
|
||||
}, nil).Once()
|
||||
|
||||
sut.Aliased(from, to, suite.TestUser, sut.Summarize, filters, false)
|
||||
|
||||
effectiveFilters := suite.DurationService.Calls[0].Arguments[3].(*models.Filters)
|
||||
assert.Contains(suite.T(), effectiveFilters.Project, TestProject1) // because actually requested
|
||||
assert.Contains(suite.T(), effectiveFilters.Project, TestProject2) // because of alias
|
||||
assert.Contains(suite.T(), effectiveFilters.Project, TestProject3) // because of label
|
||||
assert.Contains(suite.T(), effectiveFilters.Label, TestProjectLabel3)
|
||||
}
|
||||
|
||||
func filterDurations(from, to time.Time, durations models.Durations) models.Durations {
|
||||
filtered := make([]*models.Duration, 0, len(durations))
|
||||
for _, d := range durations {
|
||||
|
Loading…
Reference in New Issue
Block a user