fix: skip untracked workdays when closing a week
Previously any past workday without a closed_days record blocked week close. Now only days that actually have entries require an explicit close. Empty workdays count as 0h worked, which is reflected in the weekly delta automatically. - WeekService.CloseWeek: after finding no closed_days record, check whether the day has any entries; only error if it does - NewWeekService: takes EntryStore to support the above check - Updated TestCloseWeekMissingDayFails to reflect the new semantic (test now creates entries on Friday but leaves it unclosed)
This commit is contained in:
@@ -27,7 +27,7 @@ func newFullServices(t *testing.T) (*service.EntryService, *service.DayService,
|
||||
|
||||
entrySvc := service.NewEntryService(entryStore, closedDayStore, settingsStore, tz)
|
||||
daySvc := service.NewDayService(entryStore, closedDayStore, settingsStore, tz)
|
||||
weekSvc := service.NewWeekService(closedDayStore, closedWeekStore, settingsStore, db, tz)
|
||||
weekSvc := service.NewWeekService(closedDayStore, closedWeekStore, entryStore, settingsStore, db, tz)
|
||||
settingsSvc := service.NewSettingsService(settingsStore)
|
||||
return entrySvc, daySvc, weekSvc, settingsSvc
|
||||
}
|
||||
@@ -88,19 +88,32 @@ func TestCloseWeekBasic(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCloseWeekMissingDayFails(t *testing.T) {
|
||||
// A past workday that HAS entries but was never closed should still block week close.
|
||||
ctx := context.Background()
|
||||
_, daySvc, weekSvc, _ := newFullServices(t)
|
||||
entrySvc, daySvc, weekSvc, _ := newFullServices(t)
|
||||
|
||||
// Only close Mon-Thu, leave Friday open — all are in the past
|
||||
// Use a fixed past week: 2024-W03 (Mon 2024-01-15 .. Sun 2024-01-21)
|
||||
monday := time.Date(2024, 1, 15, 0, 0, 0, 0, time.UTC)
|
||||
|
||||
// Close Mon–Thu as holiday.
|
||||
for i := 0; i < 4; i++ {
|
||||
dk := monday.AddDate(0, 0, i).Format("2006-01-02")
|
||||
daySvc.MarkDay(ctx, dk, domain.DayKindHoliday)
|
||||
}
|
||||
|
||||
// Friday (2024-01-19): add a completed entry but do NOT close the day.
|
||||
fridayStart := time.Date(2024, 1, 19, 9, 0, 0, 0, time.UTC).UnixMilli()
|
||||
fridayEnd := time.Date(2024, 1, 19, 17, 0, 0, 0, time.UTC).UnixMilli()
|
||||
if _, err := entrySvc.CreateInterval(ctx, service.CreateIntervalInput{
|
||||
StartTime: fridayStart,
|
||||
EndTime: fridayEnd,
|
||||
}); err != nil {
|
||||
t.Fatalf("CreateInterval: %v", err)
|
||||
}
|
||||
|
||||
_, err := weekSvc.CloseWeek(ctx, "2024-W03")
|
||||
if err == nil {
|
||||
t.Fatal("expected error closing week with unclosed past day")
|
||||
t.Fatal("expected error: friday has entries but is not closed")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user