Add IntOrFalse type to handle polymorphic API responses

Kanboard API returns int (ID) on success and false (bool) on failure
for create operations. Add IntOrFalse type that handles both cases
and update CreateTask, CreateComment, CreateTag, CreateTaskFile, and
CreateTaskLink to use it.
This commit is contained in:
Oliver Jakoubek 2026-01-15 20:23:53 +01:00
commit a34a40cb12
7 changed files with 63 additions and 10 deletions

View file

@ -97,6 +97,31 @@ func TestStringInt64_UnmarshalJSON(t *testing.T) {
}
}
func TestIntOrFalse_UnmarshalJSON(t *testing.T) {
tests := []struct {
name string
input string
expected int
}{
{"int value", `42`, 42},
{"int zero", `0`, 0},
{"false", `false`, 0},
{"true", `true`, 1},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var i IntOrFalse
if err := json.Unmarshal([]byte(tt.input), &i); err != nil {
t.Fatalf("unmarshal error: %v", err)
}
if int(i) != tt.expected {
t.Errorf("expected %v, got %v", tt.expected, i)
}
})
}
}
func TestProject_UnmarshalJSON(t *testing.T) {
jsonData := `{
"id": "1",