fizzy-cli 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/cmd/board_create.go +15 -16
  3. package/cmd/board_create_test.go +0 -17
  4. package/cmd/card_create.go +24 -25
  5. package/cmd/card_create_test.go +20 -40
  6. package/cmd/card_update.go +30 -21
  7. package/cmd/card_update_test.go +28 -24
  8. package/cmd/column_create.go +11 -12
  9. package/cmd/column_create_test.go +3 -21
  10. package/cmd/comment.go +14 -0
  11. package/cmd/comment_create.go +51 -0
  12. package/cmd/comment_create_test.go +129 -0
  13. package/cmd/comment_delete.go +46 -0
  14. package/cmd/comment_delete_test.go +92 -0
  15. package/cmd/comment_list.go +51 -0
  16. package/cmd/comment_list_test.go +132 -0
  17. package/cmd/comment_show.go +46 -0
  18. package/cmd/comment_show_test.go +104 -0
  19. package/cmd/comment_update.go +51 -0
  20. package/cmd/comment_update_test.go +130 -0
  21. package/cmd/reaction.go +13 -0
  22. package/cmd/reaction_create.go +46 -0
  23. package/cmd/reaction_create_test.go +113 -0
  24. package/cmd/reaction_delete.go +46 -0
  25. package/cmd/reaction_delete_test.go +92 -0
  26. package/cmd/reaction_list.go +51 -0
  27. package/cmd/reaction_list_test.go +125 -0
  28. package/cmd/step.go +14 -0
  29. package/cmd/step_create.go +53 -0
  30. package/cmd/step_create_test.go +171 -0
  31. package/cmd/step_delete.go +46 -0
  32. package/cmd/step_delete_test.go +92 -0
  33. package/cmd/step_update.go +66 -0
  34. package/cmd/step_update_test.go +190 -0
  35. package/internal/api/boards.go +59 -0
  36. package/internal/api/cards.go +288 -0
  37. package/internal/api/client.go +5 -644
  38. package/internal/api/columns.go +50 -0
  39. package/internal/api/comments.go +99 -0
  40. package/internal/api/identity.go +24 -0
  41. package/internal/api/notifications.go +89 -0
  42. package/internal/api/reactions.go +61 -0
  43. package/internal/api/steps.go +93 -0
  44. package/internal/api/tags.go +24 -0
  45. package/internal/api/types.go +178 -0
  46. package/internal/ui/comment_list.go +25 -0
  47. package/internal/ui/reaction_list.go +14 -0
  48. package/package.json +1 -1
  49. package/IMPLEMENTATION_PLAN.md +0 -338
@@ -0,0 +1,171 @@
1
+ package cmd
2
+
3
+ import (
4
+ "context"
5
+ "encoding/json"
6
+ "io"
7
+ "net/http"
8
+ "net/http/httptest"
9
+ "testing"
10
+
11
+ "github.com/rogeriopvl/fizzy/internal/api"
12
+ "github.com/rogeriopvl/fizzy/internal/app"
13
+ "github.com/rogeriopvl/fizzy/internal/testutil"
14
+ )
15
+
16
+ func TestStepCreateCommandSuccess(t *testing.T) {
17
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
18
+ if r.URL.Path != "/cards/123/steps" {
19
+ t.Errorf("expected /cards/123/steps, got %s", r.URL.Path)
20
+ }
21
+ if r.Method != http.MethodPost {
22
+ t.Errorf("expected POST, got %s", r.Method)
23
+ }
24
+
25
+ auth := r.Header.Get("Authorization")
26
+ if auth != "Bearer test-token" {
27
+ t.Errorf("expected Bearer test-token, got %s", auth)
28
+ }
29
+
30
+ if r.Header.Get("Content-Type") != "application/json" {
31
+ t.Errorf("expected Content-Type: application/json, got %s", r.Header.Get("Content-Type"))
32
+ }
33
+
34
+ body, _ := io.ReadAll(r.Body)
35
+ var payload map[string]map[string]any
36
+ if err := json.Unmarshal(body, &payload); err != nil {
37
+ t.Fatalf("failed to unmarshal request body: %v", err)
38
+ }
39
+
40
+ stepPayload := payload["step"]
41
+ if stepPayload["content"] != "Write tests" {
42
+ t.Errorf("expected content 'Write tests', got %v", stepPayload["content"])
43
+ }
44
+ if stepPayload["completed"] != false {
45
+ t.Errorf("expected completed false, got %v", stepPayload["completed"])
46
+ }
47
+
48
+ w.Header().Set("Content-Type", "application/json")
49
+ w.WriteHeader(http.StatusCreated)
50
+ response := api.Step{
51
+ ID: "step-789",
52
+ Content: "Write tests",
53
+ Completed: false,
54
+ }
55
+ json.NewEncoder(w).Encode(response)
56
+ }))
57
+ defer server.Close()
58
+
59
+ client := testutil.NewTestClient(server.URL, "", "", "test-token")
60
+ testApp := &app.App{Client: client}
61
+
62
+ cmd := stepCreateCmd
63
+ cmd.SetContext(testApp.ToContext(context.Background()))
64
+ cmd.ParseFlags([]string{
65
+ "--content", "Write tests",
66
+ })
67
+
68
+ if err := handleCreateStep(cmd, "123"); err != nil {
69
+ t.Fatalf("handleCreateStep failed: %v", err)
70
+ }
71
+ }
72
+
73
+ func TestStepCreateCommandWithCompleted(t *testing.T) {
74
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
75
+ body, _ := io.ReadAll(r.Body)
76
+ var payload map[string]map[string]any
77
+ if err := json.Unmarshal(body, &payload); err != nil {
78
+ t.Fatalf("failed to unmarshal request body: %v", err)
79
+ }
80
+
81
+ stepPayload := payload["step"]
82
+ if stepPayload["completed"] != true {
83
+ t.Errorf("expected completed true, got %v", stepPayload["completed"])
84
+ }
85
+
86
+ w.Header().Set("Content-Type", "application/json")
87
+ w.WriteHeader(http.StatusCreated)
88
+ response := api.Step{
89
+ ID: "step-789",
90
+ Content: "Already done",
91
+ Completed: true,
92
+ }
93
+ json.NewEncoder(w).Encode(response)
94
+ }))
95
+ defer server.Close()
96
+
97
+ client := testutil.NewTestClient(server.URL, "", "", "test-token")
98
+ testApp := &app.App{Client: client}
99
+
100
+ cmd := stepCreateCmd
101
+ cmd.SetContext(testApp.ToContext(context.Background()))
102
+ cmd.ParseFlags([]string{
103
+ "--content", "Already done",
104
+ "--completed",
105
+ })
106
+
107
+ if err := handleCreateStep(cmd, "123"); err != nil {
108
+ t.Fatalf("handleCreateStep failed: %v", err)
109
+ }
110
+ }
111
+
112
+ func TestStepCreateCommandInvalidCardNumber(t *testing.T) {
113
+ testApp := &app.App{}
114
+
115
+ cmd := stepCreateCmd
116
+ cmd.SetContext(testApp.ToContext(context.Background()))
117
+ cmd.ParseFlags([]string{
118
+ "--content", "Test step",
119
+ })
120
+
121
+ err := handleCreateStep(cmd, "not-a-number")
122
+ if err == nil {
123
+ t.Errorf("expected error for invalid card number")
124
+ }
125
+ if err.Error() != "invalid card number: strconv.Atoi: parsing \"not-a-number\": invalid syntax" {
126
+ t.Errorf("expected invalid card number error, got %v", err)
127
+ }
128
+ }
129
+
130
+ func TestStepCreateCommandNoClient(t *testing.T) {
131
+ testApp := &app.App{}
132
+
133
+ cmd := stepCreateCmd
134
+ cmd.SetContext(testApp.ToContext(context.Background()))
135
+ cmd.ParseFlags([]string{
136
+ "--content", "Test step",
137
+ })
138
+
139
+ err := handleCreateStep(cmd, "123")
140
+ if err == nil {
141
+ t.Errorf("expected error when client not available")
142
+ }
143
+ if err.Error() != "API client not available" {
144
+ t.Errorf("expected 'client not available' error, got %v", err)
145
+ }
146
+ }
147
+
148
+ func TestStepCreateCommandAPIError(t *testing.T) {
149
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
150
+ w.WriteHeader(http.StatusInternalServerError)
151
+ w.Write([]byte("Internal Server Error"))
152
+ }))
153
+ defer server.Close()
154
+
155
+ client := testutil.NewTestClient(server.URL, "", "", "test-token")
156
+ testApp := &app.App{Client: client}
157
+
158
+ cmd := stepCreateCmd
159
+ cmd.SetContext(testApp.ToContext(context.Background()))
160
+ cmd.ParseFlags([]string{
161
+ "--content", "Test step",
162
+ })
163
+
164
+ err := handleCreateStep(cmd, "123")
165
+ if err == nil {
166
+ t.Errorf("expected error for API failure")
167
+ }
168
+ if err.Error() != "creating step: unexpected status code 500: Internal Server Error" {
169
+ t.Errorf("expected API error, got %v", err)
170
+ }
171
+ }
@@ -0,0 +1,46 @@
1
+ package cmd
2
+
3
+ import (
4
+ "context"
5
+ "fmt"
6
+ "strconv"
7
+
8
+ "github.com/rogeriopvl/fizzy/internal/app"
9
+ "github.com/spf13/cobra"
10
+ )
11
+
12
+ var stepDeleteCmd = &cobra.Command{
13
+ Use: "delete <card_number> <step_id>",
14
+ Short: "Delete a step",
15
+ Long: `Delete a step from a card`,
16
+ Args: cobra.ExactArgs(2),
17
+ Run: func(cmd *cobra.Command, args []string) {
18
+ if err := handleDeleteStep(cmd, args[0], args[1]); err != nil {
19
+ fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
20
+ }
21
+ },
22
+ }
23
+
24
+ func handleDeleteStep(cmd *cobra.Command, cardNumber, stepID string) error {
25
+ cardNum, err := strconv.Atoi(cardNumber)
26
+ if err != nil {
27
+ return fmt.Errorf("invalid card number: %w", err)
28
+ }
29
+
30
+ a := app.FromContext(cmd.Context())
31
+ if a == nil || a.Client == nil {
32
+ return fmt.Errorf("API client not available")
33
+ }
34
+
35
+ _, err = a.Client.DeleteCardStep(context.Background(), cardNum, stepID)
36
+ if err != nil {
37
+ return fmt.Errorf("deleting step: %w", err)
38
+ }
39
+
40
+ fmt.Printf("✓ Step deleted successfully\n")
41
+ return nil
42
+ }
43
+
44
+ func init() {
45
+ stepCmd.AddCommand(stepDeleteCmd)
46
+ }
@@ -0,0 +1,92 @@
1
+ package cmd
2
+
3
+ import (
4
+ "context"
5
+ "net/http"
6
+ "net/http/httptest"
7
+ "testing"
8
+
9
+ "github.com/rogeriopvl/fizzy/internal/app"
10
+ "github.com/rogeriopvl/fizzy/internal/testutil"
11
+ )
12
+
13
+ func TestStepDeleteCommandSuccess(t *testing.T) {
14
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
15
+ if r.URL.Path != "/cards/123/steps/step-456" {
16
+ t.Errorf("expected /cards/123/steps/step-456, got %s", r.URL.Path)
17
+ }
18
+ if r.Method != http.MethodDelete {
19
+ t.Errorf("expected DELETE, got %s", r.Method)
20
+ }
21
+
22
+ auth := r.Header.Get("Authorization")
23
+ if auth != "Bearer test-token" {
24
+ t.Errorf("expected Bearer test-token, got %s", auth)
25
+ }
26
+
27
+ w.WriteHeader(http.StatusNoContent)
28
+ }))
29
+ defer server.Close()
30
+
31
+ client := testutil.NewTestClient(server.URL, "", "", "test-token")
32
+ testApp := &app.App{Client: client}
33
+
34
+ cmd := stepDeleteCmd
35
+ cmd.SetContext(testApp.ToContext(context.Background()))
36
+
37
+ if err := handleDeleteStep(cmd, "123", "step-456"); err != nil {
38
+ t.Fatalf("handleDeleteStep failed: %v", err)
39
+ }
40
+ }
41
+
42
+ func TestStepDeleteCommandInvalidCardNumber(t *testing.T) {
43
+ testApp := &app.App{}
44
+
45
+ cmd := stepDeleteCmd
46
+ cmd.SetContext(testApp.ToContext(context.Background()))
47
+
48
+ err := handleDeleteStep(cmd, "not-a-number", "step-456")
49
+ if err == nil {
50
+ t.Errorf("expected error for invalid card number")
51
+ }
52
+ if err.Error() != "invalid card number: strconv.Atoi: parsing \"not-a-number\": invalid syntax" {
53
+ t.Errorf("expected invalid card number error, got %v", err)
54
+ }
55
+ }
56
+
57
+ func TestStepDeleteCommandNoClient(t *testing.T) {
58
+ testApp := &app.App{}
59
+
60
+ cmd := stepDeleteCmd
61
+ cmd.SetContext(testApp.ToContext(context.Background()))
62
+
63
+ err := handleDeleteStep(cmd, "123", "step-456")
64
+ if err == nil {
65
+ t.Errorf("expected error when client not available")
66
+ }
67
+ if err.Error() != "API client not available" {
68
+ t.Errorf("expected 'client not available' error, got %v", err)
69
+ }
70
+ }
71
+
72
+ func TestStepDeleteCommandAPIError(t *testing.T) {
73
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
74
+ w.WriteHeader(http.StatusNotFound)
75
+ w.Write([]byte("Step not found"))
76
+ }))
77
+ defer server.Close()
78
+
79
+ client := testutil.NewTestClient(server.URL, "", "", "test-token")
80
+ testApp := &app.App{Client: client}
81
+
82
+ cmd := stepDeleteCmd
83
+ cmd.SetContext(testApp.ToContext(context.Background()))
84
+
85
+ err := handleDeleteStep(cmd, "123", "step-456")
86
+ if err == nil {
87
+ t.Errorf("expected error for API failure")
88
+ }
89
+ if err.Error() != "deleting step: unexpected status code 404: Step not found" {
90
+ t.Errorf("expected API error, got %v", err)
91
+ }
92
+ }
@@ -0,0 +1,66 @@
1
+ package cmd
2
+
3
+ import (
4
+ "context"
5
+ "fmt"
6
+ "strconv"
7
+
8
+ "github.com/rogeriopvl/fizzy/internal/app"
9
+ "github.com/spf13/cobra"
10
+ )
11
+
12
+ var stepUpdateCmd = &cobra.Command{
13
+ Use: "update <card_number> <step_id>",
14
+ Short: "Update an existing step",
15
+ Long: `Update the content or completion status of an existing step on a card`,
16
+ Args: cobra.ExactArgs(2),
17
+ Run: func(cmd *cobra.Command, args []string) {
18
+ if err := handleUpdateStep(cmd, args[0], args[1]); err != nil {
19
+ fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
20
+ }
21
+ },
22
+ }
23
+
24
+ func handleUpdateStep(cmd *cobra.Command, cardNumber, stepID string) error {
25
+ cardNum, err := strconv.Atoi(cardNumber)
26
+ if err != nil {
27
+ return fmt.Errorf("invalid card number: %w", err)
28
+ }
29
+
30
+ a := app.FromContext(cmd.Context())
31
+ if a == nil || a.Client == nil {
32
+ return fmt.Errorf("API client not available")
33
+ }
34
+
35
+ var contentPtr *string
36
+ var completedPtr *bool
37
+
38
+ if cmd.Flags().Changed("content") {
39
+ content, _ := cmd.Flags().GetString("content")
40
+ contentPtr = &content
41
+ }
42
+
43
+ if cmd.Flags().Changed("completed") {
44
+ completed, _ := cmd.Flags().GetBool("completed")
45
+ completedPtr = &completed
46
+ }
47
+
48
+ if contentPtr == nil && completedPtr == nil {
49
+ return fmt.Errorf("at least one of --content or --completed must be provided")
50
+ }
51
+
52
+ step, err := a.Client.PutCardStep(context.Background(), cardNum, stepID, contentPtr, completedPtr)
53
+ if err != nil {
54
+ return fmt.Errorf("updating step: %w", err)
55
+ }
56
+
57
+ fmt.Printf("✓ Step updated successfully (id: %s)\n", step.ID)
58
+ return nil
59
+ }
60
+
61
+ func init() {
62
+ stepUpdateCmd.Flags().StringP("content", "c", "", "New step content")
63
+ stepUpdateCmd.Flags().BoolP("completed", "d", false, "Mark step as completed")
64
+
65
+ stepCmd.AddCommand(stepUpdateCmd)
66
+ }
@@ -0,0 +1,190 @@
1
+ package cmd
2
+
3
+ import (
4
+ "context"
5
+ "encoding/json"
6
+ "io"
7
+ "net/http"
8
+ "net/http/httptest"
9
+ "testing"
10
+
11
+ "github.com/rogeriopvl/fizzy/internal/api"
12
+ "github.com/rogeriopvl/fizzy/internal/app"
13
+ "github.com/rogeriopvl/fizzy/internal/testutil"
14
+ "github.com/spf13/cobra"
15
+ )
16
+
17
+ func TestStepUpdateCommandSuccess(t *testing.T) {
18
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
19
+ if r.URL.Path != "/cards/123/steps/step-456" {
20
+ t.Errorf("expected /cards/123/steps/step-456, got %s", r.URL.Path)
21
+ }
22
+ if r.Method != http.MethodPut {
23
+ t.Errorf("expected PUT, got %s", r.Method)
24
+ }
25
+
26
+ auth := r.Header.Get("Authorization")
27
+ if auth != "Bearer test-token" {
28
+ t.Errorf("expected Bearer test-token, got %s", auth)
29
+ }
30
+
31
+ if r.Header.Get("Content-Type") != "application/json" {
32
+ t.Errorf("expected Content-Type: application/json, got %s", r.Header.Get("Content-Type"))
33
+ }
34
+
35
+ body, _ := io.ReadAll(r.Body)
36
+ var payload map[string]map[string]any
37
+ if err := json.Unmarshal(body, &payload); err != nil {
38
+ t.Fatalf("failed to unmarshal request body: %v", err)
39
+ }
40
+
41
+ stepPayload := payload["step"]
42
+ if stepPayload["content"] != "Updated step text" {
43
+ t.Errorf("expected content 'Updated step text', got %v", stepPayload["content"])
44
+ }
45
+
46
+ w.Header().Set("Content-Type", "application/json")
47
+ response := api.Step{
48
+ ID: "step-456",
49
+ Content: "Updated step text",
50
+ Completed: false,
51
+ }
52
+ json.NewEncoder(w).Encode(response)
53
+ }))
54
+ defer server.Close()
55
+
56
+ client := testutil.NewTestClient(server.URL, "", "", "test-token")
57
+ testApp := &app.App{Client: client}
58
+
59
+ cmd := stepUpdateCmd
60
+ cmd.SetContext(testApp.ToContext(context.Background()))
61
+ cmd.ParseFlags([]string{
62
+ "--content", "Updated step text",
63
+ })
64
+
65
+ if err := handleUpdateStep(cmd, "123", "step-456"); err != nil {
66
+ t.Fatalf("handleUpdateStep failed: %v", err)
67
+ }
68
+ }
69
+
70
+ func TestStepUpdateCommandWithCompleted(t *testing.T) {
71
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
72
+ body, _ := io.ReadAll(r.Body)
73
+ var payload map[string]map[string]any
74
+ if err := json.Unmarshal(body, &payload); err != nil {
75
+ t.Fatalf("failed to unmarshal request body: %v", err)
76
+ }
77
+
78
+ stepPayload := payload["step"]
79
+ if stepPayload["completed"] != true {
80
+ t.Errorf("expected completed true, got %v", stepPayload["completed"])
81
+ }
82
+
83
+ w.Header().Set("Content-Type", "application/json")
84
+ response := api.Step{
85
+ ID: "step-456",
86
+ Content: "Some step",
87
+ Completed: true,
88
+ }
89
+ json.NewEncoder(w).Encode(response)
90
+ }))
91
+ defer server.Close()
92
+
93
+ client := testutil.NewTestClient(server.URL, "", "", "test-token")
94
+ testApp := &app.App{Client: client}
95
+
96
+ cmd := stepUpdateCmd
97
+ cmd.SetContext(testApp.ToContext(context.Background()))
98
+ cmd.ParseFlags([]string{
99
+ "--completed",
100
+ })
101
+
102
+ if err := handleUpdateStep(cmd, "123", "step-456"); err != nil {
103
+ t.Fatalf("handleUpdateStep failed: %v", err)
104
+ }
105
+ }
106
+
107
+ func TestStepUpdateCommandNoFlags(t *testing.T) {
108
+ testApp := &app.App{Client: testutil.NewTestClient("http://localhost", "", "", "test-token")}
109
+
110
+ cmd := stepUpdateCmd
111
+ cmd.SetContext(testApp.ToContext(context.Background()))
112
+ // Reset flags to ensure no flags are set
113
+ cmd.Flags().Set("content", "")
114
+ cmd.Flags().Set("completed", "false")
115
+
116
+ // Create a fresh command to avoid flag state from other tests
117
+ freshCmd := &cobra.Command{}
118
+ freshCmd.Flags().StringP("content", "c", "", "New step content")
119
+ freshCmd.Flags().BoolP("completed", "d", false, "Mark step as completed")
120
+ freshCmd.SetContext(testApp.ToContext(context.Background()))
121
+
122
+ err := handleUpdateStep(freshCmd, "123", "step-456")
123
+ if err == nil {
124
+ t.Errorf("expected error when no flags provided")
125
+ }
126
+ if err.Error() != "at least one of --content or --completed must be provided" {
127
+ t.Errorf("expected 'at least one flag' error, got %v", err)
128
+ }
129
+ }
130
+
131
+ func TestStepUpdateCommandInvalidCardNumber(t *testing.T) {
132
+ testApp := &app.App{}
133
+
134
+ cmd := stepUpdateCmd
135
+ cmd.SetContext(testApp.ToContext(context.Background()))
136
+ cmd.ParseFlags([]string{
137
+ "--content", "Updated text",
138
+ })
139
+
140
+ err := handleUpdateStep(cmd, "not-a-number", "step-456")
141
+ if err == nil {
142
+ t.Errorf("expected error for invalid card number")
143
+ }
144
+ if err.Error() != "invalid card number: strconv.Atoi: parsing \"not-a-number\": invalid syntax" {
145
+ t.Errorf("expected invalid card number error, got %v", err)
146
+ }
147
+ }
148
+
149
+ func TestStepUpdateCommandNoClient(t *testing.T) {
150
+ testApp := &app.App{}
151
+
152
+ cmd := stepUpdateCmd
153
+ cmd.SetContext(testApp.ToContext(context.Background()))
154
+ cmd.ParseFlags([]string{
155
+ "--content", "Updated text",
156
+ })
157
+
158
+ err := handleUpdateStep(cmd, "123", "step-456")
159
+ if err == nil {
160
+ t.Errorf("expected error when client not available")
161
+ }
162
+ if err.Error() != "API client not available" {
163
+ t.Errorf("expected 'client not available' error, got %v", err)
164
+ }
165
+ }
166
+
167
+ func TestStepUpdateCommandAPIError(t *testing.T) {
168
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
169
+ w.WriteHeader(http.StatusNotFound)
170
+ w.Write([]byte("Step not found"))
171
+ }))
172
+ defer server.Close()
173
+
174
+ client := testutil.NewTestClient(server.URL, "", "", "test-token")
175
+ testApp := &app.App{Client: client}
176
+
177
+ cmd := stepUpdateCmd
178
+ cmd.SetContext(testApp.ToContext(context.Background()))
179
+ cmd.ParseFlags([]string{
180
+ "--content", "Updated text",
181
+ })
182
+
183
+ err := handleUpdateStep(cmd, "123", "step-456")
184
+ if err == nil {
185
+ t.Errorf("expected error for API failure")
186
+ }
187
+ if err.Error() != "updating step: unexpected status code 404: Step not found" {
188
+ t.Errorf("expected API error, got %v", err)
189
+ }
190
+ }
@@ -0,0 +1,59 @@
1
+ package api
2
+
3
+ import (
4
+ "context"
5
+ "fmt"
6
+ "net/http"
7
+ )
8
+
9
+ func (c *Client) GetBoards(ctx context.Context) ([]Board, error) {
10
+ endpointURL := c.AccountBaseURL + "/boards"
11
+
12
+ req, err := c.newRequest(ctx, http.MethodGet, endpointURL, nil)
13
+ if err != nil {
14
+ return nil, fmt.Errorf("failed to create request: %w", err)
15
+ }
16
+
17
+ var response []Board
18
+ _, err = c.decodeResponse(req, &response)
19
+ if err != nil {
20
+ return nil, err
21
+ }
22
+
23
+ return response, nil
24
+ }
25
+
26
+ func (c *Client) GetBoard(ctx context.Context, boardID string) (*Board, error) {
27
+ endpointURL := c.AccountBaseURL + "/boards/" + boardID
28
+
29
+ req, err := c.newRequest(ctx, http.MethodGet, endpointURL, nil)
30
+ if err != nil {
31
+ return nil, fmt.Errorf("failed to create request: %w", err)
32
+ }
33
+
34
+ var response Board
35
+ _, err = c.decodeResponse(req, &response)
36
+ if err != nil {
37
+ return nil, err
38
+ }
39
+
40
+ return &response, nil
41
+ }
42
+
43
+ func (c *Client) PostBoards(ctx context.Context, payload CreateBoardPayload) (bool, error) {
44
+ endpointURL := c.AccountBaseURL + "/boards"
45
+
46
+ body := map[string]CreateBoardPayload{"board": payload}
47
+
48
+ req, err := c.newRequest(ctx, http.MethodPost, endpointURL, body)
49
+ if err != nil {
50
+ return false, fmt.Errorf("failed to create board request: %w", err)
51
+ }
52
+
53
+ _, err = c.decodeResponse(req, nil, http.StatusCreated)
54
+ if err != nil {
55
+ return false, err
56
+ }
57
+
58
+ return true, nil
59
+ }