summaryrefslogtreecommitdiff
path: root/internal/store/sqlite_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/store/sqlite_test.go')
-rw-r--r--internal/store/sqlite_test.go45
1 files changed, 39 insertions, 6 deletions
diff --git a/internal/store/sqlite_test.go b/internal/store/sqlite_test.go
index 4d3c8f8..e8af436 100644
--- a/internal/store/sqlite_test.go
+++ b/internal/store/sqlite_test.go
@@ -188,10 +188,12 @@ func setupTestStoreWithNativeTasks(t *testing.T) *Store {
return store
}
-// TestGetNativeTasksByDateRange_IncludesOverdue guards against a regression where a native task
-// due before the window's start (e.g. yesterday, still incomplete) silently dropped out of the
-// widget/timeline the moment the day rolled over, because the query required due_date >= start.
-func TestGetNativeTasksByDateRange_IncludesOverdue(t *testing.T) {
+// TestGetNativeTasksByDateRange_ExcludesOverdue documents the deliberate contract after
+// 2026-07-13's reconciliation: GetNativeTasksByDateRange is scoped to [start, end) only.
+// Overdue tasks (due before start) are BuildTimeline's job to fetch separately via
+// GetOverdueNativeTasks -- see that test below and timeline_logic.go's "6." section --
+// so this function must NOT also return them, or BuildTimeline would double them up.
+func TestGetNativeTasksByDateRange_ExcludesOverdue(t *testing.T) {
store := setupTestStoreWithNativeTasks(t)
now := time.Now()
@@ -221,8 +223,8 @@ func TestGetNativeTasksByDateRange_IncludesOverdue(t *testing.T) {
for _, r := range results {
ids[r.ID] = true
}
- if !ids["t-overdue"] {
- t.Error("expected overdue task to be included, but it was excluded")
+ if ids["t-overdue"] {
+ t.Error("expected overdue task to be excluded from the ranged fetch")
}
if !ids["t-today"] {
t.Error("expected today's task to be included")
@@ -232,6 +234,37 @@ func TestGetNativeTasksByDateRange_IncludesOverdue(t *testing.T) {
}
}
+// TestGetOverdueNativeTasks_IncludesOnlyPastDue is the store-level counterpart to
+// TestGetNativeTasksByDateRange_ExcludesOverdue: this is the function BuildTimeline relies on
+// to actually surface overdue tasks (see timeline_logic.go's "6." section and
+// TestBuildTimeline_IncludesOverdueNativeTasks for the integration-level proof).
+func TestGetOverdueNativeTasks_IncludesOnlyPastDue(t *testing.T) {
+ store := setupTestStoreWithNativeTasks(t)
+
+ now := time.Now()
+ overdue := now.Add(-48 * time.Hour)
+ today := now
+
+ for _, task := range []models.Task{
+ {ID: "t-overdue", Content: "Overdue task", DueDate: &overdue},
+ {ID: "t-today", Content: "Today task", DueDate: &today},
+ } {
+ if err := store.CreateNativeTask(task); err != nil {
+ t.Fatalf("CreateNativeTask(%s) failed: %v", task.ID, err)
+ }
+ }
+
+ start := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
+
+ results, err := store.GetOverdueNativeTasks(start)
+ if err != nil {
+ t.Fatalf("GetOverdueNativeTasks failed: %v", err)
+ }
+ if len(results) != 1 || results[0].ID != "t-overdue" {
+ t.Errorf("expected only the overdue task, got %+v", results)
+ }
+}
+
// TestSaveAndGetGoogleTasks_RoundTripsTimestamps guards against a regression where
// due_date/updated_at (TEXT columns, not DATETIME) failed to scan back into time.Time
// via sql.NullTime whenever a row had a non-null timestamp.