mirror of https://github.com/muety/wakapi.git
chore: adapt tests
This commit is contained in:
parent
490cca05eb
commit
1e4e530c21
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,35 @@
|
||||||
|
package mocks
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/muety/wakapi/models"
|
||||||
|
"github.com/stretchr/testify/mock"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ProjectLabelServiceMock struct {
|
||||||
|
mock.Mock
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ProjectLabelServiceMock) GetById(u uint) (*models.ProjectLabel, error) {
|
||||||
|
args := p.Called(u)
|
||||||
|
return args.Get(0).(*models.ProjectLabel), args.Error(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ProjectLabelServiceMock) GetByUser(s string) ([]*models.ProjectLabel, error) {
|
||||||
|
args := p.Called(s)
|
||||||
|
return args.Get(0).([]*models.ProjectLabel), args.Error(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ProjectLabelServiceMock) GetByUserGrouped(s string) (map[string][]*models.ProjectLabel, error) {
|
||||||
|
args := p.Called(s)
|
||||||
|
return args.Get(0).(map[string][]*models.ProjectLabel), args.Error(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ProjectLabelServiceMock) Create(l *models.ProjectLabel) (*models.ProjectLabel, error) {
|
||||||
|
args := p.Called(l)
|
||||||
|
return args.Get(0).(*models.ProjectLabel), args.Error(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ProjectLabelServiceMock) Delete(l *models.ProjectLabel) error {
|
||||||
|
args := p.Called(l)
|
||||||
|
return args.Error(0)
|
||||||
|
}
|
|
@ -148,8 +148,8 @@ func (s *Summary) FillMissing() {
|
||||||
// inplace!
|
// inplace!
|
||||||
func (s *Summary) FillBy(fromType uint8, toType uint8) {
|
func (s *Summary) FillBy(fromType uint8, toType uint8) {
|
||||||
typeItems := s.MappedItems()
|
typeItems := s.MappedItems()
|
||||||
totalWanted := s.TotalTimeBy(fromType) / time.Second
|
totalWanted := s.TotalTimeBy(fromType)
|
||||||
totalActual := s.TotalTimeBy(toType) / time.Second
|
totalActual := s.TotalTimeBy(toType)
|
||||||
|
|
||||||
key := UnknownSummaryKey
|
key := UnknownSummaryKey
|
||||||
if toType == SummaryLabel {
|
if toType == SummaryLabel {
|
||||||
|
@ -164,12 +164,12 @@ func (s *Summary) FillBy(fromType uint8, toType uint8) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if existingEntryIdx >= 0 {
|
if existingEntryIdx >= 0 {
|
||||||
(*typeItems[toType])[existingEntryIdx].Total = totalWanted - totalActual
|
(*typeItems[toType])[existingEntryIdx].Total = (totalWanted - totalActual) / time.Second // workaround
|
||||||
} else {
|
} else {
|
||||||
*typeItems[toType] = append(*typeItems[toType], &SummaryItem{
|
*typeItems[toType] = append(*typeItems[toType], &SummaryItem{
|
||||||
Type: toType,
|
Type: toType,
|
||||||
Key: key,
|
Key: key,
|
||||||
Total: totalWanted - totalActual,
|
Total: (totalWanted - totalActual) / time.Second, // workaround
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -189,15 +189,6 @@ func (s *Summary) TotalTime() time.Duration {
|
||||||
return timeSum * time.Second
|
return timeSum * time.Second
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Summary) findFirstPresentType() (uint8, error) {
|
|
||||||
for _, t := range s.Types() {
|
|
||||||
if s.TotalTimeBy(t) > 0 {
|
|
||||||
return t, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 127, errors.New("no type present")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Summary) TotalTimeBy(entityType uint8) (timeSum time.Duration) {
|
func (s *Summary) TotalTimeBy(entityType uint8) (timeSum time.Duration) {
|
||||||
mappedItems := s.MappedItems()
|
mappedItems := s.MappedItems()
|
||||||
if items := mappedItems[entityType]; len(*items) > 0 {
|
if items := mappedItems[entityType]; len(*items) > 0 {
|
||||||
|
@ -280,6 +271,15 @@ func (s *Summary) WithResolvedAliases(resolve AliasResolver) *Summary {
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Summary) findFirstPresentType() (uint8, error) {
|
||||||
|
for _, t := range s.Types() {
|
||||||
|
if s.TotalTimeBy(t) != 0 {
|
||||||
|
return t, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 127, errors.New("no type present")
|
||||||
|
}
|
||||||
|
|
||||||
func (s *SummaryItem) TotalFixed() time.Duration {
|
func (s *SummaryItem) TotalFixed() time.Duration {
|
||||||
// this is a workaround, since currently, the total time of a summary item is mistakenly represented in seconds
|
// this is a workaround, since currently, the total time of a summary item is mistakenly represented in seconds
|
||||||
// TODO: fix some day, while migrating persisted summary items
|
// TODO: fix some day, while migrating persisted summary items
|
||||||
|
|
|
@ -31,7 +31,7 @@ func TestSummary_FillUnknown(t *testing.T) {
|
||||||
for _, l := range itemLists {
|
for _, l := range itemLists {
|
||||||
assert.Len(t, l, 1)
|
assert.Len(t, l, 1)
|
||||||
assert.Equal(t, UnknownSummaryKey, l[0].Key)
|
assert.Equal(t, UnknownSummaryKey, l[0].Key)
|
||||||
assert.Equal(t, testDuration, l[0].Total)
|
assert.Equal(t, testDuration, l[0].TotalFixed())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ type IProjectLabelService interface {
|
||||||
GetByUser(string) ([]*models.ProjectLabel, error)
|
GetByUser(string) ([]*models.ProjectLabel, error)
|
||||||
GetByUserGrouped(string) (map[string][]*models.ProjectLabel, error)
|
GetByUserGrouped(string) (map[string][]*models.ProjectLabel, error)
|
||||||
Create(*models.ProjectLabel) (*models.ProjectLabel, error)
|
Create(*models.ProjectLabel) (*models.ProjectLabel, error)
|
||||||
Delete(mapping *models.ProjectLabel) error
|
Delete(*models.ProjectLabel) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type IMailService interface {
|
type IMailService interface {
|
||||||
|
|
|
@ -31,12 +31,13 @@ const (
|
||||||
|
|
||||||
type SummaryServiceTestSuite struct {
|
type SummaryServiceTestSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
TestUser *models.User
|
TestUser *models.User
|
||||||
TestStartTime time.Time
|
TestStartTime time.Time
|
||||||
TestHeartbeats []*models.Heartbeat
|
TestHeartbeats []*models.Heartbeat
|
||||||
SummaryRepository *mocks.SummaryRepositoryMock
|
SummaryRepository *mocks.SummaryRepositoryMock
|
||||||
HeartbeatService *mocks.HeartbeatServiceMock
|
HeartbeatService *mocks.HeartbeatServiceMock
|
||||||
AliasService *mocks.AliasServiceMock
|
AliasService *mocks.AliasServiceMock
|
||||||
|
ProjectLabelService *mocks.ProjectLabelServiceMock
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *SummaryServiceTestSuite) SetupSuite() {
|
func (suite *SummaryServiceTestSuite) SetupSuite() {
|
||||||
|
@ -81,6 +82,7 @@ func (suite *SummaryServiceTestSuite) BeforeTest(suiteName, testName string) {
|
||||||
suite.SummaryRepository = new(mocks.SummaryRepositoryMock)
|
suite.SummaryRepository = new(mocks.SummaryRepositoryMock)
|
||||||
suite.HeartbeatService = new(mocks.HeartbeatServiceMock)
|
suite.HeartbeatService = new(mocks.HeartbeatServiceMock)
|
||||||
suite.AliasService = new(mocks.AliasServiceMock)
|
suite.AliasService = new(mocks.AliasServiceMock)
|
||||||
|
suite.ProjectLabelService = new(mocks.ProjectLabelServiceMock)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSummaryServiceTestSuite(t *testing.T) {
|
func TestSummaryServiceTestSuite(t *testing.T) {
|
||||||
|
@ -88,7 +90,9 @@ func TestSummaryServiceTestSuite(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *SummaryServiceTestSuite) TestSummaryService_Summarize() {
|
func (suite *SummaryServiceTestSuite) TestSummaryService_Summarize() {
|
||||||
sut := NewSummaryService(suite.SummaryRepository, suite.HeartbeatService, suite.AliasService)
|
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
|
||||||
|
@ -141,7 +145,9 @@ func (suite *SummaryServiceTestSuite) TestSummaryService_Summarize() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *SummaryServiceTestSuite) TestSummaryService_Retrieve() {
|
func (suite *SummaryServiceTestSuite) TestSummaryService_Retrieve() {
|
||||||
sut := NewSummaryService(suite.SummaryRepository, suite.HeartbeatService, suite.AliasService)
|
sut := NewSummaryService(suite.SummaryRepository, suite.HeartbeatService, suite.AliasService, suite.ProjectLabelService)
|
||||||
|
|
||||||
|
suite.ProjectLabelService.On("GetByUser", suite.TestUser.ID).Return([]*models.ProjectLabel{}, nil)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
summaries []*models.Summary
|
summaries []*models.Summary
|
||||||
|
@ -292,7 +298,9 @@ func (suite *SummaryServiceTestSuite) TestSummaryService_Retrieve() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *SummaryServiceTestSuite) TestSummaryService_Retrieve_DuplicateSummaries() {
|
func (suite *SummaryServiceTestSuite) TestSummaryService_Retrieve_DuplicateSummaries() {
|
||||||
sut := NewSummaryService(suite.SummaryRepository, suite.HeartbeatService, suite.AliasService)
|
sut := NewSummaryService(suite.SummaryRepository, suite.HeartbeatService, suite.AliasService, suite.ProjectLabelService)
|
||||||
|
|
||||||
|
suite.ProjectLabelService.On("GetByUser", suite.TestUser.ID).Return([]*models.ProjectLabel{}, nil)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
summaries []*models.Summary
|
summaries []*models.Summary
|
||||||
|
@ -338,7 +346,9 @@ func (suite *SummaryServiceTestSuite) TestSummaryService_Retrieve_DuplicateSumma
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *SummaryServiceTestSuite) TestSummaryService_Aliased() {
|
func (suite *SummaryServiceTestSuite) TestSummaryService_Aliased() {
|
||||||
sut := NewSummaryService(suite.SummaryRepository, suite.HeartbeatService, suite.AliasService)
|
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
|
||||||
|
|
Loading…
Reference in New Issue