package model import ( "database/sql" "testing" "time" ) func TestTask_ProcessForJSON(t *testing.T) { t.Run("task with HH:MM:SS reminder and all fields", func(t *testing.T) { task := &Task{ DueDate: sql.NullTime{Time: time.Date(2025, 3, 15, 0, 0, 0, 0, time.UTC), Valid: true}, ReminderTime: sql.NullString{String: "14:30:00", Valid: true}, CompletedAt: sql.NullTime{Time: time.Now(), Valid: true}, RecurrenceType: sql.NullString{String: "weekly", Valid: true}, RecurrenceEndDate: sql.NullTime{Time: time.Date(2025, 12, 31, 0, 0, 0, 0, time.UTC), Valid: true}, ParentTaskID: sql.NullInt64{Int64: 5, Valid: true}, } task.ProcessForJSON() if task.DueDateStr == nil || *task.DueDateStr != "2025-03-15" { t.Errorf("expected due_date 2025-03-15, got %v", task.DueDateStr) } if task.ReminderTimeStr == nil || *task.ReminderTimeStr != "14:30" { t.Errorf("expected reminder 14:30, got %v", task.ReminderTimeStr) } if !task.Completed { t.Error("expected completed to be true") } if task.RecurrenceTypeStr == nil || *task.RecurrenceTypeStr != "weekly" { t.Errorf("expected recurrence_type weekly, got %v", task.RecurrenceTypeStr) } if task.RecurrenceEndStr == nil || *task.RecurrenceEndStr != "2025-12-31" { t.Errorf("expected recurrence_end 2025-12-31, got %v", task.RecurrenceEndStr) } if task.ParentTaskIDPtr == nil || *task.ParentTaskIDPtr != 5 { t.Errorf("expected parent_task_id 5, got %v", task.ParentTaskIDPtr) } }) t.Run("task with RFC3339 reminder", func(t *testing.T) { task := &Task{ ReminderTime: sql.NullString{String: "0000-01-01T09:00:00Z", Valid: true}, } task.ProcessForJSON() if task.ReminderTimeStr == nil || *task.ReminderTimeStr != "09:00" { t.Errorf("expected 09:00, got %v", task.ReminderTimeStr) } }) t.Run("incomplete task with null fields", func(t *testing.T) { task := &Task{ DueDate: sql.NullTime{Valid: false}, CompletedAt: sql.NullTime{Valid: false}, } task.ProcessForJSON() if task.DueDateStr != nil { t.Error("expected due_date nil") } if task.Completed { t.Error("expected completed to be false") } }) }