|
| 1 | +package fizzy |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "net/http" |
| 6 | + "net/http/httptest" |
| 7 | + "testing" |
| 8 | +) |
| 9 | + |
| 10 | +// TestGetColumnDecodesColorObject pins the Column.color schema as a structured |
| 11 | +// object (Color{name, value}) rather than a string. The live API returns |
| 12 | +// "color": {"name": "Blue", "value": "var(--color-card-1)"}, which previously |
| 13 | +// failed to unmarshal because the SDK typed it as a string. |
| 14 | +func TestGetColumnDecodesColorObject(t *testing.T) { |
| 15 | + body := `{ |
| 16 | + "id": "abc123", |
| 17 | + "name": "In Progress", |
| 18 | + "color": {"name": "Blue", "value": "var(--color-card-1)"}, |
| 19 | + "created_at": "2026-04-30T00:00:00Z", |
| 20 | + "cards_url": "https://example.com/cards" |
| 21 | + }` |
| 22 | + |
| 23 | + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 24 | + w.Header().Set("Content-Type", "application/json") |
| 25 | + w.WriteHeader(http.StatusOK) |
| 26 | + _, _ = w.Write([]byte(body)) |
| 27 | + })) |
| 28 | + defer server.Close() |
| 29 | + |
| 30 | + client := NewClient(&Config{BaseURL: server.URL}, &StaticTokenProvider{Token: "test"}) |
| 31 | + col, _, err := client.ForAccount("999").Columns().Get(context.Background(), "board1", "abc123") |
| 32 | + if err != nil { |
| 33 | + t.Fatalf("Get: %v", err) |
| 34 | + } |
| 35 | + if col.Color.Name != "Blue" { |
| 36 | + t.Errorf("Color.Name = %q, want Blue", col.Color.Name) |
| 37 | + } |
| 38 | + if col.Color.Value != "var(--color-card-1)" { |
| 39 | + t.Errorf("Color.Value = %q, want var(--color-card-1)", col.Color.Value) |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +// TestListColumnsDecodesColorObject mirrors the Get test for the list endpoint. |
| 44 | +func TestListColumnsDecodesColorObject(t *testing.T) { |
| 45 | + body := `[ |
| 46 | + {"id": "c1", "name": "Triage", "color": {"name": "Gray", "value": "var(--color-card-1)"}, "created_at": "2026-04-30T00:00:00Z"}, |
| 47 | + {"id": "c2", "name": "Done", "color": {"name": "Lime", "value": "var(--color-card-4)"}, "created_at": "2026-04-30T00:00:00Z"} |
| 48 | + ]` |
| 49 | + |
| 50 | + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 51 | + w.Header().Set("Content-Type", "application/json") |
| 52 | + w.WriteHeader(http.StatusOK) |
| 53 | + _, _ = w.Write([]byte(body)) |
| 54 | + })) |
| 55 | + defer server.Close() |
| 56 | + |
| 57 | + client := NewClient(&Config{BaseURL: server.URL}, &StaticTokenProvider{Token: "test"}) |
| 58 | + cols, _, err := client.ForAccount("999").Columns().List(context.Background(), "board1") |
| 59 | + if err != nil { |
| 60 | + t.Fatalf("List: %v", err) |
| 61 | + } |
| 62 | + if len(cols) != 2 { |
| 63 | + t.Fatalf("len(cols) = %d, want 2", len(cols)) |
| 64 | + } |
| 65 | + if cols[0].Color.Name != "Gray" || cols[1].Color.Value != "var(--color-card-4)" { |
| 66 | + t.Errorf("unexpected colors: %+v / %+v", cols[0].Color, cols[1].Color) |
| 67 | + } |
| 68 | +} |
0 commit comments