Fix TaskBuilder parameters not sent to API

- Add createTaskWrapper and updateTaskWrapper structs to wrap request
  bodies in nested JSON format expected by Checkvist API
- Change JSON tag from "due" to "due_date" as required by API
- Update DueDate constants to use valid Checkvist smart syntax values
  (^Today, ^Tomorrow, ^ASAP, ^Monday)
- Update tests to verify nested format and correct field names

Fixes checkvist-api-a5b
This commit is contained in:
Oliver Jakoubek 2026-01-14 19:02:34 +01:00
commit 895b76d9e1
4 changed files with 61 additions and 41 deletions

View file

@ -13,7 +13,7 @@
{"id":"checkvist-api-8q3","title":"Set up Mage build targets","description":"Create magefiles/magefile.go with:\n- Test() - run go test -v ./...\n- Coverage() - run go test -coverprofile=coverage.out ./...\n- Lint() - run staticcheck ./...\n- Fmt() - run gofmt -w .\n- Check() - run all quality checks (fmt, vet, staticcheck, test)\nEnsure magefiles has its own go.mod importing magefile.org/mage","status":"closed","priority":0,"issue_type":"task","owner":"mail@oliverjakoubek.de","created_at":"2026-01-14T12:31:09.228450637+01:00","created_by":"Oliver Jakoubek","updated_at":"2026-01-14T13:33:08.511791793+01:00","closed_at":"2026-01-14T13:33:08.511791793+01:00","close_reason":"Closed","dependencies":[{"issue_id":"checkvist-api-8q3","depends_on_id":"checkvist-api-5wr","type":"blocks","created_at":"2026-01-14T12:32:48.556022687+01:00","created_by":"Oliver Jakoubek"}]} {"id":"checkvist-api-8q3","title":"Set up Mage build targets","description":"Create magefiles/magefile.go with:\n- Test() - run go test -v ./...\n- Coverage() - run go test -coverprofile=coverage.out ./...\n- Lint() - run staticcheck ./...\n- Fmt() - run gofmt -w .\n- Check() - run all quality checks (fmt, vet, staticcheck, test)\nEnsure magefiles has its own go.mod importing magefile.org/mage","status":"closed","priority":0,"issue_type":"task","owner":"mail@oliverjakoubek.de","created_at":"2026-01-14T12:31:09.228450637+01:00","created_by":"Oliver Jakoubek","updated_at":"2026-01-14T13:33:08.511791793+01:00","closed_at":"2026-01-14T13:33:08.511791793+01:00","close_reason":"Closed","dependencies":[{"issue_id":"checkvist-api-8q3","depends_on_id":"checkvist-api-5wr","type":"blocks","created_at":"2026-01-14T12:32:48.556022687+01:00","created_by":"Oliver Jakoubek"}]}
{"id":"checkvist-api-8u6","title":"Implement HTTP request helper with retry logic","description":"Add internal HTTP helper to client.go:\n- doRequest(ctx, method, path, body) helper for all API calls\n- Automatic authentication check before requests\n- JSON marshaling/unmarshaling\n- Exponential backoff retry for:\n - HTTP 429 (Too Many Requests)\n - HTTP 5xx (Server Errors)\n - Network errors (timeout, connection reset)\n- Respect context cancellation\n- Optional debug logging of requests/responses via slog","status":"closed","priority":0,"issue_type":"task","owner":"mail@oliverjakoubek.de","created_at":"2026-01-14T12:31:08.780244392+01:00","created_by":"Oliver Jakoubek","updated_at":"2026-01-14T13:27:52.914675409+01:00","closed_at":"2026-01-14T13:27:52.914675409+01:00","close_reason":"Closed","dependencies":[{"issue_id":"checkvist-api-8u6","depends_on_id":"checkvist-api-ymg","type":"blocks","created_at":"2026-01-14T12:32:47.973194416+01:00","created_by":"Oliver Jakoubek"},{"issue_id":"checkvist-api-8u6","depends_on_id":"checkvist-api-mnh","type":"blocks","created_at":"2026-01-14T12:32:48.268500727+01:00","created_by":"Oliver Jakoubek"}]} {"id":"checkvist-api-8u6","title":"Implement HTTP request helper with retry logic","description":"Add internal HTTP helper to client.go:\n- doRequest(ctx, method, path, body) helper for all API calls\n- Automatic authentication check before requests\n- JSON marshaling/unmarshaling\n- Exponential backoff retry for:\n - HTTP 429 (Too Many Requests)\n - HTTP 5xx (Server Errors)\n - Network errors (timeout, connection reset)\n- Respect context cancellation\n- Optional debug logging of requests/responses via slog","status":"closed","priority":0,"issue_type":"task","owner":"mail@oliverjakoubek.de","created_at":"2026-01-14T12:31:08.780244392+01:00","created_by":"Oliver Jakoubek","updated_at":"2026-01-14T13:27:52.914675409+01:00","closed_at":"2026-01-14T13:27:52.914675409+01:00","close_reason":"Closed","dependencies":[{"issue_id":"checkvist-api-8u6","depends_on_id":"checkvist-api-ymg","type":"blocks","created_at":"2026-01-14T12:32:47.973194416+01:00","created_by":"Oliver Jakoubek"},{"issue_id":"checkvist-api-8u6","depends_on_id":"checkvist-api-mnh","type":"blocks","created_at":"2026-01-14T12:32:48.268500727+01:00","created_by":"Oliver Jakoubek"}]}
{"id":"checkvist-api-93m","title":"Create CHANGELOG","description":"Create CHANGELOG.md following Keep a Changelog format:\n- [Unreleased] section for ongoing work\n- Initial release preparation notes\n- Document all features implemented","status":"closed","priority":0,"issue_type":"task","owner":"mail@oliverjakoubek.de","created_at":"2026-01-14T12:31:39.009748936+01:00","created_by":"Oliver Jakoubek","updated_at":"2026-01-14T13:37:00.644317886+01:00","closed_at":"2026-01-14T13:37:00.644317886+01:00","close_reason":"Closed"} {"id":"checkvist-api-93m","title":"Create CHANGELOG","description":"Create CHANGELOG.md following Keep a Changelog format:\n- [Unreleased] section for ongoing work\n- Initial release preparation notes\n- Document all features implemented","status":"closed","priority":0,"issue_type":"task","owner":"mail@oliverjakoubek.de","created_at":"2026-01-14T12:31:39.009748936+01:00","created_by":"Oliver Jakoubek","updated_at":"2026-01-14T13:37:00.644317886+01:00","closed_at":"2026-01-14T13:37:00.644317886+01:00","close_reason":"Closed"}
{"id":"checkvist-api-a5b","title":"Fix TaskBuilder parameters not sent to API","description":"## Problem\n\nWhen creating tasks with `TaskBuilder`, the task is created but additional parameters (due date, priority, tags) are not applied. Only the task content is saved.\n\n## Reproduction\n\n```go\ntask, err := client.Tasks(checklist.ID).Create(ctx,\n checkvist.NewTask(\"Test-Task\").\n WithDueDate(checkvist.DueTomorrow).\n WithPriority(1).\n WithTags(\"OLI\", \"Test\"),\n)\n// Task is created, but due date, priority, and tags are missing\n```\n\n## Likely Root Cause\n\nSimilar to the Notes API issue (checkvist-api-awg), the Checkvist API likely expects nested parameters in the format `task[content]`, `task[due]`, etc. instead of flat JSON.\n\n**Current (likely incorrect):**\n```json\n{\"content\": \"text\", \"due\": \"^tomorrow\", \"priority\": 1, \"tags\": \"OLI, Test\"}\n```\n\n**Expected by API (likely):**\n```json\n{\"task\": {\"content\": \"text\", \"due\": \"^tomorrow\", \"priority\": 1, \"tags\": \"OLI, Test\"}}\n```\n\n## Affected Code\n\n`tasks.go`:\n- `CreateTaskRequest` struct (lines 55-64)\n- `build()` method (lines 127-146)\n- `Create()` method (lines 148-159)\n\n## Solution\n\nWrap `CreateTaskRequest` in a `task` field similar to how we fixed Notes:\n\n```go\ntype taskWrapper struct {\n Task CreateTaskRequest `json:\"task\"`\n}\n```\n\n## Acceptance Criteria\n\n- Task created with `WithDueDate()` has due date set\n- Task created with `WithPriority()` has priority set\n- Task created with `WithTags()` has tags set\n- All combinations work together","status":"open","priority":1,"issue_type":"bug","owner":"mail@oliverjakoubek.de","created_at":"2026-01-14T18:20:41.761840004+01:00","created_by":"Oliver Jakoubek","updated_at":"2026-01-14T18:20:41.761840004+01:00"} {"id":"checkvist-api-a5b","title":"Fix TaskBuilder parameters not sent to API","description":"## Problem\n\nWhen creating tasks with `TaskBuilder`, the task is created but additional parameters (due date, priority, tags) are not applied. Only the task content is saved.\n\n## Reproduction\n\n```go\ntask, err := client.Tasks(checklist.ID).Create(ctx,\n checkvist.NewTask(\"Test-Task\").\n WithDueDate(checkvist.DueTomorrow).\n WithPriority(1).\n WithTags(\"OLI\", \"Test\"),\n)\n// Task is created, but due date, priority, and tags are missing\n```\n\n## Likely Root Cause\n\nSimilar to the Notes API issue (checkvist-api-awg), the Checkvist API likely expects nested parameters in the format `task[content]`, `task[due]`, etc. instead of flat JSON.\n\n**Current (likely incorrect):**\n```json\n{\"content\": \"text\", \"due\": \"^tomorrow\", \"priority\": 1, \"tags\": \"OLI, Test\"}\n```\n\n**Expected by API (likely):**\n```json\n{\"task\": {\"content\": \"text\", \"due\": \"^tomorrow\", \"priority\": 1, \"tags\": \"OLI, Test\"}}\n```\n\n## Affected Code\n\n`tasks.go`:\n- `CreateTaskRequest` struct (lines 55-64)\n- `build()` method (lines 127-146)\n- `Create()` method (lines 148-159)\n\n## Solution\n\nWrap `CreateTaskRequest` in a `task` field similar to how we fixed Notes:\n\n```go\ntype taskWrapper struct {\n Task CreateTaskRequest `json:\"task\"`\n}\n```\n\n## Acceptance Criteria\n\n- Task created with `WithDueDate()` has due date set\n- Task created with `WithPriority()` has priority set\n- Task created with `WithTags()` has tags set\n- All combinations work together","status":"closed","priority":1,"issue_type":"bug","owner":"mail@oliverjakoubek.de","created_at":"2026-01-14T18:20:41.761840004+01:00","created_by":"Oliver Jakoubek","updated_at":"2026-01-14T19:02:24.902832354+01:00","closed_at":"2026-01-14T19:02:24.902832354+01:00","close_reason":"Closed"}
{"id":"checkvist-api-awg","title":"Fix Notes.Create API parameter format","description":"## Problem\n\nThe `NoteService.Create` method fails with a 400 Bad Request error:\n\n```\ncheckvist API error (status 400): {\"message\":\"comment[comment] parameter is required\"}\n```\n\n## Root Cause\n\nThe Checkvist API expects nested parameters in the format `comment[comment]`, but the current implementation sends a flat JSON structure:\n\n**Current (incorrect):**\n```json\n{\"comment\": \"Note text\"}\n```\n\n**Expected by API:**\n```json\n{\"comment\": {\"comment\": \"Note text\"}}\n```\n\n## Affected Code\n\n`notes.go` lines 37-51:\n```go\ntype createNoteRequest struct {\n Comment string `json:\"comment\"`\n}\n\nfunc (s *NoteService) Create(ctx context.Context, comment string) (*Note, error) {\n path := fmt.Sprintf(\"/checklists/%d/tasks/%d/comments.json\", s.checklistID, s.taskID)\n body := createNoteRequest{Comment: comment}\n // ...\n}\n```\n\n## Solution\n\nChange `createNoteRequest` to use nested structure:\n\n```go\ntype createNoteRequest struct {\n Comment struct {\n Comment string `json:\"comment\"`\n } `json:\"comment\"`\n}\n```\n\nOr create a wrapper struct for clarity.\n\n## Likely Affected Methods\n\n- `NoteService.Create` - confirmed broken\n- `NoteService.Update` - likely same issue (uses `updateNoteRequest`)\n\n## Reproduction\n\n```go\nnote, err := client.Notes(checklistID, taskID).Create(ctx, \"Test note\")\n// Returns: API error 400, \"comment[comment] parameter is required\"\n```","status":"closed","priority":1,"issue_type":"bug","owner":"mail@oliverjakoubek.de","created_at":"2026-01-14T18:12:27.03448075+01:00","created_by":"Oliver Jakoubek","updated_at":"2026-01-14T18:18:20.446447325+01:00","closed_at":"2026-01-14T18:18:20.446447325+01:00","close_reason":"Fixed nested JSON parameter format for Create and Update methods"} {"id":"checkvist-api-awg","title":"Fix Notes.Create API parameter format","description":"## Problem\n\nThe `NoteService.Create` method fails with a 400 Bad Request error:\n\n```\ncheckvist API error (status 400): {\"message\":\"comment[comment] parameter is required\"}\n```\n\n## Root Cause\n\nThe Checkvist API expects nested parameters in the format `comment[comment]`, but the current implementation sends a flat JSON structure:\n\n**Current (incorrect):**\n```json\n{\"comment\": \"Note text\"}\n```\n\n**Expected by API:**\n```json\n{\"comment\": {\"comment\": \"Note text\"}}\n```\n\n## Affected Code\n\n`notes.go` lines 37-51:\n```go\ntype createNoteRequest struct {\n Comment string `json:\"comment\"`\n}\n\nfunc (s *NoteService) Create(ctx context.Context, comment string) (*Note, error) {\n path := fmt.Sprintf(\"/checklists/%d/tasks/%d/comments.json\", s.checklistID, s.taskID)\n body := createNoteRequest{Comment: comment}\n // ...\n}\n```\n\n## Solution\n\nChange `createNoteRequest` to use nested structure:\n\n```go\ntype createNoteRequest struct {\n Comment struct {\n Comment string `json:\"comment\"`\n } `json:\"comment\"`\n}\n```\n\nOr create a wrapper struct for clarity.\n\n## Likely Affected Methods\n\n- `NoteService.Create` - confirmed broken\n- `NoteService.Update` - likely same issue (uses `updateNoteRequest`)\n\n## Reproduction\n\n```go\nnote, err := client.Notes(checklistID, taskID).Create(ctx, \"Test note\")\n// Returns: API error 400, \"comment[comment] parameter is required\"\n```","status":"closed","priority":1,"issue_type":"bug","owner":"mail@oliverjakoubek.de","created_at":"2026-01-14T18:12:27.03448075+01:00","created_by":"Oliver Jakoubek","updated_at":"2026-01-14T18:18:20.446447325+01:00","closed_at":"2026-01-14T18:18:20.446447325+01:00","close_reason":"Fixed nested JSON parameter format for Create and Update methods"}
{"id":"checkvist-api-bbx","title":"Write unit tests for Notes","description":"Create notes_test.go with tests:\n- TestNotes_List\n- TestNotes_Create\n- TestNotes_Update\n- TestNotes_Delete\nUse table-driven tests. Create testdata/notes/ fixtures.","status":"closed","priority":0,"issue_type":"task","owner":"mail@oliverjakoubek.de","created_at":"2026-01-14T12:31:37.829382141+01:00","created_by":"Oliver Jakoubek","updated_at":"2026-01-14T13:47:17.141162679+01:00","closed_at":"2026-01-14T13:47:17.141162679+01:00","close_reason":"Closed","dependencies":[{"issue_id":"checkvist-api-bbx","depends_on_id":"checkvist-api-5ab","type":"blocks","created_at":"2026-01-14T12:33:14.119755191+01:00","created_by":"Oliver Jakoubek"}]} {"id":"checkvist-api-bbx","title":"Write unit tests for Notes","description":"Create notes_test.go with tests:\n- TestNotes_List\n- TestNotes_Create\n- TestNotes_Update\n- TestNotes_Delete\nUse table-driven tests. Create testdata/notes/ fixtures.","status":"closed","priority":0,"issue_type":"task","owner":"mail@oliverjakoubek.de","created_at":"2026-01-14T12:31:37.829382141+01:00","created_by":"Oliver Jakoubek","updated_at":"2026-01-14T13:47:17.141162679+01:00","closed_at":"2026-01-14T13:47:17.141162679+01:00","close_reason":"Closed","dependencies":[{"issue_id":"checkvist-api-bbx","depends_on_id":"checkvist-api-5ab","type":"blocks","created_at":"2026-01-14T12:33:14.119755191+01:00","created_by":"Oliver Jakoubek"}]}
{"id":"checkvist-api-br3","title":"Core API Operations","description":"Phase 2: Implement CRUD operations for Checklists, Tasks, and Notes. All P0 (must-have) features for the library.","status":"closed","priority":0,"issue_type":"epic","owner":"mail@oliverjakoubek.de","created_at":"2026-01-14T12:30:53.20627925+01:00","created_by":"Oliver Jakoubek","updated_at":"2026-01-14T14:29:26.991139668+01:00","closed_at":"2026-01-14T14:29:26.991139668+01:00","close_reason":"Alle zugehörigen Tasks abgeschlossen"} {"id":"checkvist-api-br3","title":"Core API Operations","description":"Phase 2: Implement CRUD operations for Checklists, Tasks, and Notes. All P0 (must-have) features for the library.","status":"closed","priority":0,"issue_type":"epic","owner":"mail@oliverjakoubek.de","created_at":"2026-01-14T12:30:53.20627925+01:00","created_by":"Oliver Jakoubek","updated_at":"2026-01-14T14:29:26.991139668+01:00","closed_at":"2026-01-14T14:29:26.991139668+01:00","close_reason":"Alle zugehörigen Tasks abgeschlossen"}

View file

@ -178,13 +178,13 @@ type DueDate struct {
// Common due date constants using Checkvist's smart syntax. // Common due date constants using Checkvist's smart syntax.
var ( var (
// DueToday sets the due date to today. // DueToday sets the due date to today.
DueToday = DueDate{value: "^today"} DueToday = DueDate{value: "^Today"}
// DueTomorrow sets the due date to tomorrow. // DueTomorrow sets the due date to tomorrow.
DueTomorrow = DueDate{value: "^tomorrow"} DueTomorrow = DueDate{value: "^Tomorrow"}
// DueNextWeek sets the due date to next week. // DueASAP sets the due date to ASAP.
DueNextWeek = DueDate{value: "^next week"} DueASAP = DueDate{value: "^ASAP"}
// DueNextMonth sets the due date to next month. // DueMonday sets the due date to next Monday.
DueNextMonth = DueDate{value: "^next month"} DueMonday = DueDate{value: "^Monday"}
) )
// DueAt creates a DueDate from a Go time.Time value. // DueAt creates a DueDate from a Go time.Time value.
@ -193,7 +193,7 @@ func DueAt(t time.Time) DueDate {
} }
// DueString creates a DueDate from a raw smart syntax string. // DueString creates a DueDate from a raw smart syntax string.
// The string should use Checkvist's smart syntax (e.g., "^2026-02-01", "^friday"). // The string should use Checkvist's smart syntax (e.g., "^2026-02-01", "^friday", "^next week").
func DueString(s string) DueDate { func DueString(s string) DueDate {
return DueDate{value: s} return DueDate{value: s}
} }

View file

@ -57,12 +57,18 @@ type CreateTaskRequest struct {
Content string `json:"content"` Content string `json:"content"`
ParentID int `json:"parent_id,omitempty"` ParentID int `json:"parent_id,omitempty"`
Position int `json:"position,omitempty"` Position int `json:"position,omitempty"`
Due string `json:"due,omitempty"` Due string `json:"due_date,omitempty"`
Priority int `json:"priority,omitempty"` Priority int `json:"priority,omitempty"`
Tags string `json:"tags,omitempty"` Tags string `json:"tags,omitempty"`
Repeat string `json:"repeat,omitempty"` Repeat string `json:"repeat,omitempty"`
} }
// createTaskWrapper wraps the task fields for the nested JSON format
// expected by the Checkvist API: {"task": {"content": "...", ...}}
type createTaskWrapper struct {
Task CreateTaskRequest `json:"task"`
}
// TaskBuilder provides a fluent interface for building task creation requests. // TaskBuilder provides a fluent interface for building task creation requests.
type TaskBuilder struct { type TaskBuilder struct {
content string content string
@ -148,7 +154,7 @@ func (b *TaskBuilder) build() CreateTaskRequest {
// Create creates a new task using a TaskBuilder. // Create creates a new task using a TaskBuilder.
func (s *TaskService) Create(ctx context.Context, builder *TaskBuilder) (*Task, error) { func (s *TaskService) Create(ctx context.Context, builder *TaskBuilder) (*Task, error) {
path := fmt.Sprintf("/checklists/%d/tasks.json", s.checklistID) path := fmt.Sprintf("/checklists/%d/tasks.json", s.checklistID)
body := builder.build() body := createTaskWrapper{Task: builder.build()}
var task Task var task Task
if err := s.client.doPost(ctx, path, body, &task); err != nil { if err := s.client.doPost(ctx, path, body, &task); err != nil {
@ -164,17 +170,23 @@ type UpdateTaskRequest struct {
Content *string `json:"content,omitempty"` Content *string `json:"content,omitempty"`
ParentID *int `json:"parent_id,omitempty"` ParentID *int `json:"parent_id,omitempty"`
Position *int `json:"position,omitempty"` Position *int `json:"position,omitempty"`
Due *string `json:"due,omitempty"` Due *string `json:"due_date,omitempty"`
Priority *int `json:"priority,omitempty"` Priority *int `json:"priority,omitempty"`
Tags *string `json:"tags,omitempty"` Tags *string `json:"tags,omitempty"`
} }
// updateTaskWrapper wraps the task fields for PUT requests
type updateTaskWrapper struct {
Task UpdateTaskRequest `json:"task"`
}
// Update updates an existing task. // Update updates an existing task.
func (s *TaskService) Update(ctx context.Context, taskID int, req UpdateTaskRequest) (*Task, error) { func (s *TaskService) Update(ctx context.Context, taskID int, req UpdateTaskRequest) (*Task, error) {
path := fmt.Sprintf("/checklists/%d/tasks/%d.json", s.checklistID, taskID) path := fmt.Sprintf("/checklists/%d/tasks/%d.json", s.checklistID, taskID)
body := updateTaskWrapper{Task: req}
var task Task var task Task
if err := s.client.doPut(ctx, path, req, &task); err != nil { if err := s.client.doPut(ctx, path, body, &task); err != nil {
return nil, err return nil, err
} }

View file

@ -85,18 +85,18 @@ func TestTasks_Create(t *testing.T) {
t.Errorf("expected POST, got %s", r.Method) t.Errorf("expected POST, got %s", r.Method)
} }
var req CreateTaskRequest var req createTaskWrapper
if err := json.NewDecoder(r.Body).Decode(&req); err != nil { if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
t.Fatalf("failed to decode request: %v", err) t.Fatalf("failed to decode request: %v", err)
} }
if req.Content != "New task" { if req.Task.Content != "New task" {
t.Errorf("expected content 'New task', got %s", req.Content) t.Errorf("expected content 'New task', got %s", req.Task.Content)
} }
response := Task{ response := Task{
ID: 200, ID: 200,
ChecklistID: 1, ChecklistID: 1,
Content: req.Content, Content: req.Task.Content,
Status: StatusOpen, Status: StatusOpen,
CreatedAt: NewAPITime(time.Now()), CreatedAt: NewAPITime(time.Now()),
UpdatedAt: NewAPITime(time.Now()), UpdatedAt: NewAPITime(time.Now()),
@ -130,35 +130,35 @@ func TestTasks_Create_WithBuilder(t *testing.T) {
case "/auth/login.json": case "/auth/login.json":
json.NewEncoder(w).Encode(map[string]string{"token": "test-token"}) json.NewEncoder(w).Encode(map[string]string{"token": "test-token"})
case "/checklists/1/tasks.json": case "/checklists/1/tasks.json":
var req CreateTaskRequest var req createTaskWrapper
if err := json.NewDecoder(r.Body).Decode(&req); err != nil { if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
t.Fatalf("failed to decode request: %v", err) t.Fatalf("failed to decode request: %v", err)
} }
if req.Content != "Task with options" { if req.Task.Content != "Task with options" {
t.Errorf("expected content 'Task with options', got %s", req.Content) t.Errorf("expected content 'Task with options', got %s", req.Task.Content)
} }
if req.Priority != 1 { if req.Task.Priority != 1 {
t.Errorf("expected priority 1, got %d", req.Priority) t.Errorf("expected priority 1, got %d", req.Task.Priority)
} }
if req.Due != "^tomorrow" { if req.Task.Due != "^tomorrow" {
t.Errorf("expected due '^tomorrow', got %s", req.Due) t.Errorf("expected due '^tomorrow', got %s", req.Task.Due)
} }
if req.Tags != "tag1, tag2" { if req.Task.Tags != "tag1, tag2" {
t.Errorf("expected tags 'tag1, tag2', got %s", req.Tags) t.Errorf("expected tags 'tag1, tag2', got %s", req.Task.Tags)
} }
if req.ParentID != 100 { if req.Task.ParentID != 100 {
t.Errorf("expected parent_id 100, got %d", req.ParentID) t.Errorf("expected parent_id 100, got %d", req.Task.ParentID)
} }
response := Task{ response := Task{
ID: 201, ID: 201,
ChecklistID: 1, ChecklistID: 1,
ParentID: req.ParentID, ParentID: req.Task.ParentID,
Content: req.Content, Content: req.Task.Content,
Priority: req.Priority, Priority: req.Task.Priority,
DueDateRaw: "2026-01-15", DueDateRaw: "2026-01-15",
TagsAsText: req.Tags, TagsAsText: req.Task.Tags,
} }
json.NewEncoder(w).Encode(response) json.NewEncoder(w).Encode(response)
default: default:
@ -199,10 +199,18 @@ func TestTasks_Update(t *testing.T) {
t.Errorf("expected PUT, got %s", r.Method) t.Errorf("expected PUT, got %s", r.Method)
} }
var req updateTaskWrapper
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
t.Fatalf("failed to decode request: %v", err)
}
if req.Task.Content == nil || *req.Task.Content != "Updated content" {
t.Errorf("expected content 'Updated content', got %v", req.Task.Content)
}
response := Task{ response := Task{
ID: 101, ID: 101,
ChecklistID: 1, ChecklistID: 1,
Content: "Updated content", Content: *req.Task.Content,
UpdatedAt: NewAPITime(time.Now()), UpdatedAt: NewAPITime(time.Now()),
} }
json.NewEncoder(w).Encode(response) json.NewEncoder(w).Encode(response)
@ -420,8 +428,8 @@ func TestTaskBuilder(t *testing.T) {
if req.Position != 3 { if req.Position != 3 {
t.Errorf("expected Position 3, got %d", req.Position) t.Errorf("expected Position 3, got %d", req.Position)
} }
if req.Due != "^next week" { if req.Due != "^Next Monday" {
t.Errorf("expected Due '^next week', got %s", req.Due) t.Errorf("expected Due '^Next Monday', got %s", req.Due)
} }
if req.Priority != 2 { if req.Priority != 2 {
t.Errorf("expected Priority 2, got %d", req.Priority) t.Errorf("expected Priority 2, got %d", req.Priority)
@ -437,8 +445,8 @@ func timePtr(t time.Time) *time.Time {
// TestTasks_Create_RealAPIFormat tests that the client sends the correct // TestTasks_Create_RealAPIFormat tests that the client sends the correct
// nested parameter format expected by the real Checkvist API. // nested parameter format expected by the real Checkvist API.
// The API expects: {"task": {"content": "text", "due": "...", ...}} // The API expects: {"task": {"content": "text", "due_date": "...", ...}}
// Not the flat format: {"content": "text", "due": "...", ...} // Not the flat format: {"content": "text", "due_date": "...", ...}
// //
// This test documents the current FAILING behavior - it should pass once // This test documents the current FAILING behavior - it should pass once
// the parameter format is fixed. // the parameter format is fixed.
@ -490,7 +498,7 @@ func TestTasks_Create_RealAPIFormat(t *testing.T) {
} }
content, _ := taskMap["content"].(string) content, _ := taskMap["content"].(string)
due, _ := taskMap["due"].(string) due, _ := taskMap["due_date"].(string)
priority, _ := taskMap["priority"].(float64) priority, _ := taskMap["priority"].(float64)
tags, _ := taskMap["tags"].(string) tags, _ := taskMap["tags"].(string)
@ -565,10 +573,10 @@ func TestTasks_Create_WithDueDate_RealAPIFormat(t *testing.T) {
if hasTaskWrapper { if hasTaskWrapper {
taskMap := taskField.(map[string]interface{}) taskMap := taskField.(map[string]interface{})
content, _ = taskMap["content"].(string) content, _ = taskMap["content"].(string)
due, _ = taskMap["due"].(string) due, _ = taskMap["due_date"].(string)
} else { } else {
content, _ = rawBody["content"].(string) content, _ = rawBody["content"].(string)
due, _ = rawBody["due"].(string) due, _ = rawBody["due_date"].(string)
} }
// Simulate API behavior: only process due if in task wrapper // Simulate API behavior: only process due if in task wrapper