Add tests documenting TaskBuilder parameters bug
This commit is contained in:
parent
c95825dc88
commit
762b4daf8d
2 changed files with 298 additions and 0 deletions
|
|
@ -13,6 +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-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"}
|
||||||
|
|
|
||||||
297
tasks_test.go
297
tasks_test.go
|
|
@ -434,3 +434,300 @@ func TestTaskBuilder(t *testing.T) {
|
||||||
func timePtr(t time.Time) *time.Time {
|
func timePtr(t time.Time) *time.Time {
|
||||||
return &t
|
return &t
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestTasks_Create_RealAPIFormat tests that the client sends the correct
|
||||||
|
// nested parameter format expected by the real Checkvist API.
|
||||||
|
// The API expects: {"task": {"content": "text", "due": "...", ...}}
|
||||||
|
// Not the flat format: {"content": "text", "due": "...", ...}
|
||||||
|
//
|
||||||
|
// This test documents the current FAILING behavior - it should pass once
|
||||||
|
// the parameter format is fixed.
|
||||||
|
func TestTasks_Create_RealAPIFormat(t *testing.T) {
|
||||||
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
|
||||||
|
switch r.URL.Path {
|
||||||
|
case "/auth/login.json":
|
||||||
|
json.NewEncoder(w).Encode(map[string]string{"token": "test-token"})
|
||||||
|
case "/checklists/1/tasks.json":
|
||||||
|
if r.Method != http.MethodPost {
|
||||||
|
t.Errorf("expected POST, got %s", r.Method)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse the request body as raw JSON to check structure
|
||||||
|
var rawBody map[string]interface{}
|
||||||
|
if err := json.NewDecoder(r.Body).Decode(&rawBody); err != nil {
|
||||||
|
t.Fatalf("failed to decode request: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// The real API expects nested format: {"task": {"content": "...", ...}}
|
||||||
|
taskField, hasTaskWrapper := rawBody["task"]
|
||||||
|
if !hasTaskWrapper {
|
||||||
|
// Flat format received - this is what the current code sends
|
||||||
|
// The API would accept it for content-only, but ignores other fields
|
||||||
|
// Simulate this behavior: create task with content only, ignore rest
|
||||||
|
content, _ := rawBody["content"].(string)
|
||||||
|
response := Task{
|
||||||
|
ID: 200,
|
||||||
|
ChecklistID: 1,
|
||||||
|
Content: content,
|
||||||
|
Status: StatusOpen,
|
||||||
|
Priority: 0, // Priority NOT set (ignored)
|
||||||
|
DueDateRaw: "", // Due date NOT set (ignored)
|
||||||
|
TagsAsText: "", // Tags NOT set (ignored)
|
||||||
|
CreatedAt: NewAPITime(time.Now()),
|
||||||
|
UpdatedAt: NewAPITime(time.Now()),
|
||||||
|
}
|
||||||
|
json.NewEncoder(w).Encode(response)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Nested format received - extract values from task wrapper
|
||||||
|
taskMap, ok := taskField.(map[string]interface{})
|
||||||
|
if !ok {
|
||||||
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
content, _ := taskMap["content"].(string)
|
||||||
|
due, _ := taskMap["due"].(string)
|
||||||
|
priority, _ := taskMap["priority"].(float64)
|
||||||
|
tags, _ := taskMap["tags"].(string)
|
||||||
|
|
||||||
|
response := Task{
|
||||||
|
ID: 200,
|
||||||
|
ChecklistID: 1,
|
||||||
|
Content: content,
|
||||||
|
Status: StatusOpen,
|
||||||
|
Priority: int(priority),
|
||||||
|
DueDateRaw: due,
|
||||||
|
TagsAsText: tags,
|
||||||
|
CreatedAt: NewAPITime(time.Now()),
|
||||||
|
UpdatedAt: NewAPITime(time.Now()),
|
||||||
|
}
|
||||||
|
json.NewEncoder(w).Encode(response)
|
||||||
|
default:
|
||||||
|
t.Errorf("unexpected path: %s", r.URL.Path)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
defer server.Close()
|
||||||
|
|
||||||
|
client := NewClient("user@example.com", "api-key", WithBaseURL(server.URL))
|
||||||
|
task, err := client.Tasks(1).Create(context.Background(),
|
||||||
|
NewTask("Test task with options").
|
||||||
|
WithDueDate(DueTomorrow).
|
||||||
|
WithPriority(1).
|
||||||
|
WithTags("tag1", "tag2"),
|
||||||
|
)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if parameters were actually applied
|
||||||
|
var failures []string
|
||||||
|
|
||||||
|
if task.Priority != 1 {
|
||||||
|
failures = append(failures, "priority not set (expected 1, got 0)")
|
||||||
|
}
|
||||||
|
if task.DueDateRaw == "" {
|
||||||
|
failures = append(failures, "due date not set")
|
||||||
|
}
|
||||||
|
if task.TagsAsText == "" {
|
||||||
|
failures = append(failures, "tags not set")
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(failures) > 0 {
|
||||||
|
t.Skipf("KNOWN BUG: TaskBuilder parameters not sent to API: %v", failures)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestTasks_Create_WithDueDate_RealAPIFormat specifically tests due date handling
|
||||||
|
func TestTasks_Create_WithDueDate_RealAPIFormat(t *testing.T) {
|
||||||
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
|
||||||
|
switch r.URL.Path {
|
||||||
|
case "/auth/login.json":
|
||||||
|
json.NewEncoder(w).Encode(map[string]string{"token": "test-token"})
|
||||||
|
case "/checklists/1/tasks.json":
|
||||||
|
var rawBody map[string]interface{}
|
||||||
|
if err := json.NewDecoder(r.Body).Decode(&rawBody); err != nil {
|
||||||
|
t.Fatalf("failed to decode request: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if task wrapper exists
|
||||||
|
taskField, hasTaskWrapper := rawBody["task"]
|
||||||
|
|
||||||
|
var due string
|
||||||
|
var content string
|
||||||
|
|
||||||
|
if hasTaskWrapper {
|
||||||
|
taskMap := taskField.(map[string]interface{})
|
||||||
|
content, _ = taskMap["content"].(string)
|
||||||
|
due, _ = taskMap["due"].(string)
|
||||||
|
} else {
|
||||||
|
content, _ = rawBody["content"].(string)
|
||||||
|
due, _ = rawBody["due"].(string)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Simulate API behavior: only process due if in task wrapper
|
||||||
|
responseDue := ""
|
||||||
|
if hasTaskWrapper && due != "" {
|
||||||
|
responseDue = "2026-01-15" // Simulated parsed date
|
||||||
|
}
|
||||||
|
|
||||||
|
response := Task{
|
||||||
|
ID: 200,
|
||||||
|
ChecklistID: 1,
|
||||||
|
Content: content,
|
||||||
|
DueDateRaw: responseDue,
|
||||||
|
CreatedAt: NewAPITime(time.Now()),
|
||||||
|
UpdatedAt: NewAPITime(time.Now()),
|
||||||
|
}
|
||||||
|
json.NewEncoder(w).Encode(response)
|
||||||
|
default:
|
||||||
|
t.Errorf("unexpected path: %s", r.URL.Path)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
defer server.Close()
|
||||||
|
|
||||||
|
client := NewClient("user@example.com", "api-key", WithBaseURL(server.URL))
|
||||||
|
task, err := client.Tasks(1).Create(context.Background(),
|
||||||
|
NewTask("Task with due date").WithDueDate(DueTomorrow),
|
||||||
|
)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if task.DueDateRaw == "" {
|
||||||
|
t.Skip("KNOWN BUG: Due date not sent to API - task wrapper format required")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestTasks_Create_WithPriority_RealAPIFormat specifically tests priority handling
|
||||||
|
func TestTasks_Create_WithPriority_RealAPIFormat(t *testing.T) {
|
||||||
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
|
||||||
|
switch r.URL.Path {
|
||||||
|
case "/auth/login.json":
|
||||||
|
json.NewEncoder(w).Encode(map[string]string{"token": "test-token"})
|
||||||
|
case "/checklists/1/tasks.json":
|
||||||
|
var rawBody map[string]interface{}
|
||||||
|
if err := json.NewDecoder(r.Body).Decode(&rawBody); err != nil {
|
||||||
|
t.Fatalf("failed to decode request: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
taskField, hasTaskWrapper := rawBody["task"]
|
||||||
|
|
||||||
|
var priority float64
|
||||||
|
var content string
|
||||||
|
|
||||||
|
if hasTaskWrapper {
|
||||||
|
taskMap := taskField.(map[string]interface{})
|
||||||
|
content, _ = taskMap["content"].(string)
|
||||||
|
priority, _ = taskMap["priority"].(float64)
|
||||||
|
} else {
|
||||||
|
content, _ = rawBody["content"].(string)
|
||||||
|
priority, _ = rawBody["priority"].(float64)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Simulate API: only process priority if in task wrapper
|
||||||
|
responsePriority := 0
|
||||||
|
if hasTaskWrapper {
|
||||||
|
responsePriority = int(priority)
|
||||||
|
}
|
||||||
|
|
||||||
|
response := Task{
|
||||||
|
ID: 200,
|
||||||
|
ChecklistID: 1,
|
||||||
|
Content: content,
|
||||||
|
Priority: responsePriority,
|
||||||
|
CreatedAt: NewAPITime(time.Now()),
|
||||||
|
UpdatedAt: NewAPITime(time.Now()),
|
||||||
|
}
|
||||||
|
json.NewEncoder(w).Encode(response)
|
||||||
|
default:
|
||||||
|
t.Errorf("unexpected path: %s", r.URL.Path)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
defer server.Close()
|
||||||
|
|
||||||
|
client := NewClient("user@example.com", "api-key", WithBaseURL(server.URL))
|
||||||
|
task, err := client.Tasks(1).Create(context.Background(),
|
||||||
|
NewTask("Task with priority").WithPriority(1),
|
||||||
|
)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if task.Priority != 1 {
|
||||||
|
t.Skipf("KNOWN BUG: Priority not sent to API - expected 1, got %d", task.Priority)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestTasks_Create_WithTags_RealAPIFormat specifically tests tags handling
|
||||||
|
func TestTasks_Create_WithTags_RealAPIFormat(t *testing.T) {
|
||||||
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
|
||||||
|
switch r.URL.Path {
|
||||||
|
case "/auth/login.json":
|
||||||
|
json.NewEncoder(w).Encode(map[string]string{"token": "test-token"})
|
||||||
|
case "/checklists/1/tasks.json":
|
||||||
|
var rawBody map[string]interface{}
|
||||||
|
if err := json.NewDecoder(r.Body).Decode(&rawBody); err != nil {
|
||||||
|
t.Fatalf("failed to decode request: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
taskField, hasTaskWrapper := rawBody["task"]
|
||||||
|
|
||||||
|
var tags string
|
||||||
|
var content string
|
||||||
|
|
||||||
|
if hasTaskWrapper {
|
||||||
|
taskMap := taskField.(map[string]interface{})
|
||||||
|
content, _ = taskMap["content"].(string)
|
||||||
|
tags, _ = taskMap["tags"].(string)
|
||||||
|
} else {
|
||||||
|
content, _ = rawBody["content"].(string)
|
||||||
|
tags, _ = rawBody["tags"].(string)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Simulate API: only process tags if in task wrapper
|
||||||
|
responseTags := ""
|
||||||
|
if hasTaskWrapper {
|
||||||
|
responseTags = tags
|
||||||
|
}
|
||||||
|
|
||||||
|
response := Task{
|
||||||
|
ID: 200,
|
||||||
|
ChecklistID: 1,
|
||||||
|
Content: content,
|
||||||
|
TagsAsText: responseTags,
|
||||||
|
CreatedAt: NewAPITime(time.Now()),
|
||||||
|
UpdatedAt: NewAPITime(time.Now()),
|
||||||
|
}
|
||||||
|
json.NewEncoder(w).Encode(response)
|
||||||
|
default:
|
||||||
|
t.Errorf("unexpected path: %s", r.URL.Path)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
defer server.Close()
|
||||||
|
|
||||||
|
client := NewClient("user@example.com", "api-key", WithBaseURL(server.URL))
|
||||||
|
task, err := client.Tasks(1).Create(context.Background(),
|
||||||
|
NewTask("Task with tags").WithTags("OLI", "Test"),
|
||||||
|
)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if task.TagsAsText == "" {
|
||||||
|
t.Skip("KNOWN BUG: Tags not sent to API - task wrapper format required")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue