refactor: introduce clock to make tests reproducible
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/wotra/wotra/internal/clock"
|
||||
"github.com/wotra/wotra/internal/domain"
|
||||
"github.com/wotra/wotra/internal/store"
|
||||
)
|
||||
@@ -31,6 +32,7 @@ type EntryService struct {
|
||||
settings *store.SettingsStore
|
||||
syncStore *store.SyncStore
|
||||
tz *time.Location
|
||||
clock clock.Clock
|
||||
}
|
||||
|
||||
func NewEntryService(
|
||||
@@ -39,6 +41,7 @@ func NewEntryService(
|
||||
settings *store.SettingsStore,
|
||||
syncStore *store.SyncStore,
|
||||
tz *time.Location,
|
||||
clk clock.Clock,
|
||||
) *EntryService {
|
||||
return &EntryService{
|
||||
entries: entries,
|
||||
@@ -46,11 +49,12 @@ func NewEntryService(
|
||||
settings: settings,
|
||||
syncStore: syncStore,
|
||||
tz: tz,
|
||||
clock: clk,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *EntryService) nowMs() int64 {
|
||||
return time.Now().UnixMilli()
|
||||
return s.clock.Now().UnixMilli()
|
||||
}
|
||||
|
||||
func (s *EntryService) dayKeyForMs(ms int64) string {
|
||||
|
||||
Reference in New Issue
Block a user