- Priority 1: Test NewSendEmailTask + NewSendPushTask (5 tests) - Priority 2: Test customHTTPErrorHandler — all 15+ branches (21 tests) - Priority 3: Extract Enqueuer interface + payload builders in worker pkg (5 tests) - Priority 4: Extract ClassifyFile/ComputeRelPath in migrate-encrypt (6 tests) - Priority 5: Define Handler interfaces, refactor to accept them, mock-based tests (14 tests) - Fix .gitignore: /worker instead of worker to stop ignoring internal/worker/ Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
62 lines
2.1 KiB
Go
62 lines
2.1 KiB
Go
package main
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestClassifyCompletion_CompletedAfterDue_ReturnsOverdue(t *testing.T) {
|
|
due := time.Date(2025, 6, 1, 0, 0, 0, 0, time.UTC)
|
|
completed := time.Date(2025, 6, 5, 14, 0, 0, 0, time.UTC)
|
|
got := classifyCompletion(completed, due, 7)
|
|
if got != "overdue_tasks" {
|
|
t.Errorf("got %q, want overdue_tasks", got)
|
|
}
|
|
}
|
|
|
|
func TestClassifyCompletion_CompletedOnDueDate_ReturnsDueSoon(t *testing.T) {
|
|
due := time.Date(2025, 6, 1, 0, 0, 0, 0, time.UTC)
|
|
completed := time.Date(2025, 6, 1, 10, 0, 0, 0, time.UTC)
|
|
got := classifyCompletion(completed, due, 7)
|
|
if got != "due_soon_tasks" {
|
|
t.Errorf("got %q, want due_soon_tasks", got)
|
|
}
|
|
}
|
|
|
|
func TestClassifyCompletion_CompletedWithinThreshold_ReturnsDueSoon(t *testing.T) {
|
|
due := time.Date(2025, 6, 10, 0, 0, 0, 0, time.UTC)
|
|
completed := time.Date(2025, 6, 5, 0, 0, 0, 0, time.UTC) // 5 days before due, threshold 7
|
|
got := classifyCompletion(completed, due, 7)
|
|
if got != "due_soon_tasks" {
|
|
t.Errorf("got %q, want due_soon_tasks", got)
|
|
}
|
|
}
|
|
|
|
func TestClassifyCompletion_CompletedAtExactThreshold_ReturnsDueSoon(t *testing.T) {
|
|
due := time.Date(2025, 6, 10, 0, 0, 0, 0, time.UTC)
|
|
completed := time.Date(2025, 6, 3, 0, 0, 0, 0, time.UTC) // exactly 7 days before due
|
|
got := classifyCompletion(completed, due, 7)
|
|
if got != "due_soon_tasks" {
|
|
t.Errorf("got %q, want due_soon_tasks", got)
|
|
}
|
|
}
|
|
|
|
func TestClassifyCompletion_CompletedBeyondThreshold_ReturnsUpcoming(t *testing.T) {
|
|
due := time.Date(2025, 6, 30, 0, 0, 0, 0, time.UTC)
|
|
completed := time.Date(2025, 6, 1, 0, 0, 0, 0, time.UTC) // 29 days before due, threshold 7
|
|
got := classifyCompletion(completed, due, 7)
|
|
if got != "upcoming_tasks" {
|
|
t.Errorf("got %q, want upcoming_tasks", got)
|
|
}
|
|
}
|
|
|
|
func TestClassifyCompletion_TimeNormalization_SameDayDifferentTimes(t *testing.T) {
|
|
due := time.Date(2025, 6, 1, 23, 59, 59, 0, time.UTC)
|
|
completed := time.Date(2025, 6, 1, 0, 0, 1, 0, time.UTC) // same day, different times
|
|
got := classifyCompletion(completed, due, 7)
|
|
// Same day → daysBefore == 0 → within threshold → due_soon
|
|
if got != "due_soon_tasks" {
|
|
t.Errorf("got %q, want due_soon_tasks", got)
|
|
}
|
|
}
|