diff options
Diffstat (limited to 'internal/store/native_tasks_test.go')
| -rw-r--r-- | internal/store/native_tasks_test.go | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/internal/store/native_tasks_test.go b/internal/store/native_tasks_test.go index 9453c86..70b775e 100644 --- a/internal/store/native_tasks_test.go +++ b/internal/store/native_tasks_test.go @@ -50,7 +50,8 @@ func newNativeTasksTestStore(t *testing.T) *Store { bucket_id TEXT DEFAULT '', bucket_state TEXT DEFAULT '', bucket_last_active_at DATETIME, - abandoned BOOLEAN DEFAULT 0 + abandoned BOOLEAN DEFAULT 0, + committed_date DATE ) `); err != nil { t.Fatal(err) @@ -798,3 +799,47 @@ func TestCompleteNativeTask_DoesNotAbandonAnything(t *testing.T) { t.Errorf("abandoned = %d, want 0 -- a completed occurrence was done, not skipped", abandoned) } } + +func TestSetTaskCommitted_RoundTrips(t *testing.T) { + s := newNativeTasksTestStore(t) + + today := config.Now() + if err := s.SetTaskCommitted("real-1", today); err != nil { + t.Fatalf("SetTaskCommitted: %v", err) + } + + committed, err := s.GetCommittedTasks(today) + if err != nil { + t.Fatalf("GetCommittedTasks: %v", err) + } + if len(committed) != 1 || committed[0].ID != "real-1" { + t.Fatalf("GetCommittedTasks = %v, want exactly real-1", committed) + } + + // A different day must not pick it up. + other, err := s.GetCommittedTasks(today.AddDate(0, 0, 1)) + if err != nil { + t.Fatal(err) + } + if len(other) != 0 { + t.Errorf("tomorrow's committed list = %d task(s), want 0", len(other)) + } + + if err := s.ClearTaskCommitted("real-1"); err != nil { + t.Fatalf("ClearTaskCommitted: %v", err) + } + after, err := s.GetCommittedTasks(today) + if err != nil { + t.Fatal(err) + } + if len(after) != 0 { + t.Errorf("after clearing, committed list = %d task(s), want 0", len(after)) + } +} + +func TestSetTaskCommitted_UnknownID_ReturnsErrNotFound(t *testing.T) { + s := newNativeTasksTestStore(t) + if err := s.SetTaskCommitted("nope", config.Now()); !errors.Is(err, ErrNativeTaskNotFound) { + t.Fatalf("err = %v, want ErrNativeTaskNotFound", err) + } +} |
