refactor: introduce clock to make tests reproducible

This commit is contained in:
2026-05-13 20:24:56 +00:00
parent 7e6c47a50e
commit ca5f5f95e2
9 changed files with 140 additions and 84 deletions

View File

@@ -10,6 +10,7 @@ import (
"time"
assets "github.com/wotra/wotra"
"github.com/wotra/wotra/internal/clock"
"github.com/wotra/wotra/internal/config"
"github.com/wotra/wotra/internal/handler"
"github.com/wotra/wotra/internal/service"
@@ -46,10 +47,12 @@ func main() {
settingsStore := store.NewSettingsStore(db)
syncStore := store.NewSyncStore(db)
entrySvc := service.NewEntryService(entryStore, closedDayStore, settingsStore, syncStore, tz)
daySvc := service.NewDayService(entryStore, closedDayStore, closedWeekStore, settingsStore, syncStore, tz)
settingsSvc := service.NewSettingsService(settingsStore, syncStore)
weekSvc := service.NewWeekService(closedDayStore, closedWeekStore, entryStore, settingsStore, adjustmentStore, syncStore, db, tz)
clk := clock.Real()
entrySvc := service.NewEntryService(entryStore, closedDayStore, settingsStore, syncStore, tz, clk)
daySvc := service.NewDayService(entryStore, closedDayStore, closedWeekStore, settingsStore, syncStore, tz, clk)
settingsSvc := service.NewSettingsService(settingsStore, syncStore, clk)
weekSvc := service.NewWeekService(closedDayStore, closedWeekStore, entryStore, settingsStore, adjustmentStore, syncStore, db, tz, clk)
// Background goroutine: auto-stop entries that cross midnight
ctx, cancel := context.WithCancel(context.Background())