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,129 @@
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 TestCommentCreateCommandSuccess(t *testing.T) {
17
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
18
+ if r.URL.Path != "/cards/123/comments" {
19
+ t.Errorf("expected /cards/123/comments, 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]string
36
+ if err := json.Unmarshal(body, &payload); err != nil {
37
+ t.Fatalf("failed to unmarshal request body: %v", err)
38
+ }
39
+
40
+ commentPayload := payload["comment"]
41
+ if commentPayload["body"] != "This is a test comment" {
42
+ t.Errorf("expected body 'This is a test comment', got %s", commentPayload["body"])
43
+ }
44
+
45
+ w.Header().Set("Content-Type", "application/json")
46
+ w.WriteHeader(http.StatusCreated)
47
+ response := api.Comment{
48
+ ID: "comment-789",
49
+ CreatedAt: "2025-01-01T00:00:00Z",
50
+ Creator: api.User{ID: "user-1", Name: "John Doe"},
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 := commentCreateCmd
60
+ cmd.SetContext(testApp.ToContext(context.Background()))
61
+ cmd.ParseFlags([]string{
62
+ "--body", "This is a test comment",
63
+ })
64
+
65
+ if err := handleCreateComment(cmd, "123"); err != nil {
66
+ t.Fatalf("handleCreateComment failed: %v", err)
67
+ }
68
+ }
69
+
70
+ func TestCommentCreateCommandInvalidCardNumber(t *testing.T) {
71
+ testApp := &app.App{}
72
+
73
+ cmd := commentCreateCmd
74
+ cmd.SetContext(testApp.ToContext(context.Background()))
75
+ cmd.ParseFlags([]string{
76
+ "--body", "Test comment",
77
+ })
78
+
79
+ err := handleCreateComment(cmd, "not-a-number")
80
+ if err == nil {
81
+ t.Errorf("expected error for invalid card number")
82
+ }
83
+ if err.Error() != "invalid card number: strconv.Atoi: parsing \"not-a-number\": invalid syntax" {
84
+ t.Errorf("expected invalid card number error, got %v", err)
85
+ }
86
+ }
87
+
88
+ func TestCommentCreateCommandNoClient(t *testing.T) {
89
+ testApp := &app.App{}
90
+
91
+ cmd := commentCreateCmd
92
+ cmd.SetContext(testApp.ToContext(context.Background()))
93
+ cmd.ParseFlags([]string{
94
+ "--body", "Test comment",
95
+ })
96
+
97
+ err := handleCreateComment(cmd, "123")
98
+ if err == nil {
99
+ t.Errorf("expected error when client not available")
100
+ }
101
+ if err.Error() != "API client not available" {
102
+ t.Errorf("expected 'client not available' error, got %v", err)
103
+ }
104
+ }
105
+
106
+ func TestCommentCreateCommandAPIError(t *testing.T) {
107
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
108
+ w.WriteHeader(http.StatusInternalServerError)
109
+ w.Write([]byte("Internal Server Error"))
110
+ }))
111
+ defer server.Close()
112
+
113
+ client := testutil.NewTestClient(server.URL, "", "", "test-token")
114
+ testApp := &app.App{Client: client}
115
+
116
+ cmd := commentCreateCmd
117
+ cmd.SetContext(testApp.ToContext(context.Background()))
118
+ cmd.ParseFlags([]string{
119
+ "--body", "Test comment",
120
+ })
121
+
122
+ err := handleCreateComment(cmd, "123")
123
+ if err == nil {
124
+ t.Errorf("expected error for API failure")
125
+ }
126
+ if err.Error() != "creating comment: unexpected status code 500: Internal Server Error" {
127
+ t.Errorf("expected API error, got %v", err)
128
+ }
129
+ }
@@ -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 commentDeleteCmd = &cobra.Command{
13
+ Use: "delete <card_number> <comment_id>",
14
+ Short: "Delete a comment",
15
+ Long: `Delete a comment from a card`,
16
+ Args: cobra.ExactArgs(2),
17
+ Run: func(cmd *cobra.Command, args []string) {
18
+ if err := handleDeleteComment(cmd, args[0], args[1]); err != nil {
19
+ fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
20
+ }
21
+ },
22
+ }
23
+
24
+ func handleDeleteComment(cmd *cobra.Command, cardNumber, commentID 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.DeleteCardComment(context.Background(), cardNum, commentID)
36
+ if err != nil {
37
+ return fmt.Errorf("deleting comment: %w", err)
38
+ }
39
+
40
+ fmt.Printf("✓ Comment deleted successfully\n")
41
+ return nil
42
+ }
43
+
44
+ func init() {
45
+ commentCmd.AddCommand(commentDeleteCmd)
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 TestCommentDeleteCommandSuccess(t *testing.T) {
14
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
15
+ if r.URL.Path != "/cards/123/comments/comment-456" {
16
+ t.Errorf("expected /cards/123/comments/comment-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 := commentDeleteCmd
35
+ cmd.SetContext(testApp.ToContext(context.Background()))
36
+
37
+ if err := handleDeleteComment(cmd, "123", "comment-456"); err != nil {
38
+ t.Fatalf("handleDeleteComment failed: %v", err)
39
+ }
40
+ }
41
+
42
+ func TestCommentDeleteCommandInvalidCardNumber(t *testing.T) {
43
+ testApp := &app.App{}
44
+
45
+ cmd := commentDeleteCmd
46
+ cmd.SetContext(testApp.ToContext(context.Background()))
47
+
48
+ err := handleDeleteComment(cmd, "not-a-number", "comment-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 TestCommentDeleteCommandNoClient(t *testing.T) {
58
+ testApp := &app.App{}
59
+
60
+ cmd := commentDeleteCmd
61
+ cmd.SetContext(testApp.ToContext(context.Background()))
62
+
63
+ err := handleDeleteComment(cmd, "123", "comment-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 TestCommentDeleteCommandAPIError(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("Comment 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 := commentDeleteCmd
83
+ cmd.SetContext(testApp.ToContext(context.Background()))
84
+
85
+ err := handleDeleteComment(cmd, "123", "comment-456")
86
+ if err == nil {
87
+ t.Errorf("expected error for API failure")
88
+ }
89
+ if err.Error() != "deleting comment: unexpected status code 404: Comment not found" {
90
+ t.Errorf("expected API error, got %v", err)
91
+ }
92
+ }
@@ -0,0 +1,51 @@
1
+ package cmd
2
+
3
+ import (
4
+ "context"
5
+ "fmt"
6
+ "strconv"
7
+
8
+ "github.com/rogeriopvl/fizzy/internal/app"
9
+ "github.com/rogeriopvl/fizzy/internal/ui"
10
+ "github.com/spf13/cobra"
11
+ )
12
+
13
+ var commentListCmd = &cobra.Command{
14
+ Use: "list <card_number>",
15
+ Short: "List comments on a card",
16
+ Long: `Retrieve and display all comments on a card`,
17
+ Args: cobra.ExactArgs(1),
18
+ Run: func(cmd *cobra.Command, args []string) {
19
+ if err := handleListComments(cmd, args[0]); err != nil {
20
+ fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
21
+ }
22
+ },
23
+ }
24
+
25
+ func handleListComments(cmd *cobra.Command, cardNumber string) error {
26
+ cardNum, err := strconv.Atoi(cardNumber)
27
+ if err != nil {
28
+ return fmt.Errorf("invalid card number: %w", err)
29
+ }
30
+
31
+ a := app.FromContext(cmd.Context())
32
+ if a == nil || a.Client == nil {
33
+ return fmt.Errorf("API client not available")
34
+ }
35
+
36
+ comments, err := a.Client.GetCardComments(context.Background(), cardNum)
37
+ if err != nil {
38
+ return fmt.Errorf("fetching comments: %w", err)
39
+ }
40
+
41
+ if len(comments) == 0 {
42
+ fmt.Println("No comments found")
43
+ return nil
44
+ }
45
+
46
+ return ui.DisplayComments(comments)
47
+ }
48
+
49
+ func init() {
50
+ commentCmd.AddCommand(commentListCmd)
51
+ }
@@ -0,0 +1,132 @@
1
+ package cmd
2
+
3
+ import (
4
+ "context"
5
+ "encoding/json"
6
+ "net/http"
7
+ "net/http/httptest"
8
+ "testing"
9
+
10
+ "github.com/rogeriopvl/fizzy/internal/api"
11
+ "github.com/rogeriopvl/fizzy/internal/app"
12
+ "github.com/rogeriopvl/fizzy/internal/testutil"
13
+ )
14
+
15
+ func TestCommentListCommandSuccess(t *testing.T) {
16
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
17
+ if r.URL.Path != "/cards/123/comments" {
18
+ t.Errorf("expected /cards/123/comments, got %s", r.URL.Path)
19
+ }
20
+ if r.Method != http.MethodGet {
21
+ t.Errorf("expected GET, got %s", r.Method)
22
+ }
23
+
24
+ auth := r.Header.Get("Authorization")
25
+ if auth != "Bearer test-token" {
26
+ t.Errorf("expected Bearer test-token, got %s", auth)
27
+ }
28
+
29
+ w.Header().Set("Content-Type", "application/json")
30
+ response := []api.Comment{
31
+ {
32
+ ID: "comment-123",
33
+ CreatedAt: "2025-01-01T00:00:00Z",
34
+ UpdatedAt: "2025-01-01T00:00:00Z",
35
+ Creator: api.User{ID: "user-1", Name: "John Doe"},
36
+ },
37
+ {
38
+ ID: "comment-456",
39
+ CreatedAt: "2025-01-02T00:00:00Z",
40
+ UpdatedAt: "2025-01-02T00:00:00Z",
41
+ Creator: api.User{ID: "user-2", Name: "Jane Doe"},
42
+ },
43
+ }
44
+ // Set the body field manually since it's a struct
45
+ response[0].Body.PlainText = "First comment"
46
+ response[0].Body.HTML = "<p>First comment</p>"
47
+ response[1].Body.PlainText = "Second comment"
48
+ response[1].Body.HTML = "<p>Second comment</p>"
49
+ json.NewEncoder(w).Encode(response)
50
+ }))
51
+ defer server.Close()
52
+
53
+ client := testutil.NewTestClient(server.URL, "", "", "test-token")
54
+ testApp := &app.App{Client: client}
55
+
56
+ cmd := commentListCmd
57
+ cmd.SetContext(testApp.ToContext(context.Background()))
58
+
59
+ if err := handleListComments(cmd, "123"); err != nil {
60
+ t.Fatalf("handleListComments failed: %v", err)
61
+ }
62
+ }
63
+
64
+ func TestCommentListCommandNoComments(t *testing.T) {
65
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
66
+ w.Header().Set("Content-Type", "application/json")
67
+ json.NewEncoder(w).Encode([]api.Comment{})
68
+ }))
69
+ defer server.Close()
70
+
71
+ client := testutil.NewTestClient(server.URL, "", "", "test-token")
72
+ testApp := &app.App{Client: client}
73
+
74
+ cmd := commentListCmd
75
+ cmd.SetContext(testApp.ToContext(context.Background()))
76
+
77
+ if err := handleListComments(cmd, "123"); err != nil {
78
+ t.Fatalf("handleListComments failed: %v", err)
79
+ }
80
+ }
81
+
82
+ func TestCommentListCommandInvalidCardNumber(t *testing.T) {
83
+ testApp := &app.App{}
84
+
85
+ cmd := commentListCmd
86
+ cmd.SetContext(testApp.ToContext(context.Background()))
87
+
88
+ err := handleListComments(cmd, "not-a-number")
89
+ if err == nil {
90
+ t.Errorf("expected error for invalid card number")
91
+ }
92
+ if err.Error() != "invalid card number: strconv.Atoi: parsing \"not-a-number\": invalid syntax" {
93
+ t.Errorf("expected invalid card number error, got %v", err)
94
+ }
95
+ }
96
+
97
+ func TestCommentListCommandNoClient(t *testing.T) {
98
+ testApp := &app.App{}
99
+
100
+ cmd := commentListCmd
101
+ cmd.SetContext(testApp.ToContext(context.Background()))
102
+
103
+ err := handleListComments(cmd, "123")
104
+ if err == nil {
105
+ t.Errorf("expected error when client not available")
106
+ }
107
+ if err.Error() != "API client not available" {
108
+ t.Errorf("expected 'client not available' error, got %v", err)
109
+ }
110
+ }
111
+
112
+ func TestCommentListCommandAPIError(t *testing.T) {
113
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
114
+ w.WriteHeader(http.StatusInternalServerError)
115
+ w.Write([]byte("Internal Server Error"))
116
+ }))
117
+ defer server.Close()
118
+
119
+ client := testutil.NewTestClient(server.URL, "", "", "test-token")
120
+ testApp := &app.App{Client: client}
121
+
122
+ cmd := commentListCmd
123
+ cmd.SetContext(testApp.ToContext(context.Background()))
124
+
125
+ err := handleListComments(cmd, "123")
126
+ if err == nil {
127
+ t.Errorf("expected error for API failure")
128
+ }
129
+ if err.Error() != "fetching comments: unexpected status code 500: Internal Server Error" {
130
+ t.Errorf("expected API error, got %v", err)
131
+ }
132
+ }
@@ -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/rogeriopvl/fizzy/internal/ui"
10
+ "github.com/spf13/cobra"
11
+ )
12
+
13
+ var commentShowCmd = &cobra.Command{
14
+ Use: "show <card_number> <comment_id>",
15
+ Short: "Show a specific comment",
16
+ Long: `Display details of a specific comment on a card`,
17
+ Args: cobra.ExactArgs(2),
18
+ Run: func(cmd *cobra.Command, args []string) {
19
+ if err := handleShowComment(cmd, args[0], args[1]); err != nil {
20
+ fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
21
+ }
22
+ },
23
+ }
24
+
25
+ func handleShowComment(cmd *cobra.Command, cardNumber, commentID string) error {
26
+ cardNum, err := strconv.Atoi(cardNumber)
27
+ if err != nil {
28
+ return fmt.Errorf("invalid card number: %w", err)
29
+ }
30
+
31
+ a := app.FromContext(cmd.Context())
32
+ if a == nil || a.Client == nil {
33
+ return fmt.Errorf("API client not available")
34
+ }
35
+
36
+ comment, err := a.Client.GetCardComment(context.Background(), cardNum, commentID)
37
+ if err != nil {
38
+ return fmt.Errorf("fetching comment: %w", err)
39
+ }
40
+
41
+ return ui.DisplayComment(comment)
42
+ }
43
+
44
+ func init() {
45
+ commentCmd.AddCommand(commentShowCmd)
46
+ }
@@ -0,0 +1,104 @@
1
+ package cmd
2
+
3
+ import (
4
+ "context"
5
+ "encoding/json"
6
+ "net/http"
7
+ "net/http/httptest"
8
+ "testing"
9
+
10
+ "github.com/rogeriopvl/fizzy/internal/api"
11
+ "github.com/rogeriopvl/fizzy/internal/app"
12
+ "github.com/rogeriopvl/fizzy/internal/testutil"
13
+ )
14
+
15
+ func TestCommentShowCommandSuccess(t *testing.T) {
16
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
17
+ if r.URL.Path != "/cards/123/comments/comment-456" {
18
+ t.Errorf("expected /cards/123/comments/comment-456, got %s", r.URL.Path)
19
+ }
20
+ if r.Method != http.MethodGet {
21
+ t.Errorf("expected GET, got %s", r.Method)
22
+ }
23
+
24
+ auth := r.Header.Get("Authorization")
25
+ if auth != "Bearer test-token" {
26
+ t.Errorf("expected Bearer test-token, got %s", auth)
27
+ }
28
+
29
+ w.Header().Set("Content-Type", "application/json")
30
+ response := api.Comment{
31
+ ID: "comment-456",
32
+ CreatedAt: "2025-01-01T00:00:00Z",
33
+ UpdatedAt: "2025-01-01T00:00:00Z",
34
+ Creator: api.User{ID: "user-1", Name: "John Doe"},
35
+ Card: api.CardReference{ID: "card-123", Title: "Test Card"},
36
+ }
37
+ response.Body.PlainText = "This is a test comment"
38
+ response.Body.HTML = "<p>This is a test comment</p>"
39
+ json.NewEncoder(w).Encode(response)
40
+ }))
41
+ defer server.Close()
42
+
43
+ client := testutil.NewTestClient(server.URL, "", "", "test-token")
44
+ testApp := &app.App{Client: client}
45
+
46
+ cmd := commentShowCmd
47
+ cmd.SetContext(testApp.ToContext(context.Background()))
48
+
49
+ if err := handleShowComment(cmd, "123", "comment-456"); err != nil {
50
+ t.Fatalf("handleShowComment failed: %v", err)
51
+ }
52
+ }
53
+
54
+ func TestCommentShowCommandInvalidCardNumber(t *testing.T) {
55
+ testApp := &app.App{}
56
+
57
+ cmd := commentShowCmd
58
+ cmd.SetContext(testApp.ToContext(context.Background()))
59
+
60
+ err := handleShowComment(cmd, "not-a-number", "comment-456")
61
+ if err == nil {
62
+ t.Errorf("expected error for invalid card number")
63
+ }
64
+ if err.Error() != "invalid card number: strconv.Atoi: parsing \"not-a-number\": invalid syntax" {
65
+ t.Errorf("expected invalid card number error, got %v", err)
66
+ }
67
+ }
68
+
69
+ func TestCommentShowCommandNoClient(t *testing.T) {
70
+ testApp := &app.App{}
71
+
72
+ cmd := commentShowCmd
73
+ cmd.SetContext(testApp.ToContext(context.Background()))
74
+
75
+ err := handleShowComment(cmd, "123", "comment-456")
76
+ if err == nil {
77
+ t.Errorf("expected error when client not available")
78
+ }
79
+ if err.Error() != "API client not available" {
80
+ t.Errorf("expected 'client not available' error, got %v", err)
81
+ }
82
+ }
83
+
84
+ func TestCommentShowCommandAPIError(t *testing.T) {
85
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
86
+ w.WriteHeader(http.StatusNotFound)
87
+ w.Write([]byte("Comment not found"))
88
+ }))
89
+ defer server.Close()
90
+
91
+ client := testutil.NewTestClient(server.URL, "", "", "test-token")
92
+ testApp := &app.App{Client: client}
93
+
94
+ cmd := commentShowCmd
95
+ cmd.SetContext(testApp.ToContext(context.Background()))
96
+
97
+ err := handleShowComment(cmd, "123", "comment-456")
98
+ if err == nil {
99
+ t.Errorf("expected error for API failure")
100
+ }
101
+ if err.Error() != "fetching comment: unexpected status code 404: Comment not found" {
102
+ t.Errorf("expected API error, got %v", err)
103
+ }
104
+ }
@@ -0,0 +1,51 @@
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 commentUpdateCmd = &cobra.Command{
13
+ Use: "update <card_number> <comment_id>",
14
+ Short: "Update an existing comment",
15
+ Long: `Update the body of an existing comment on a card`,
16
+ Args: cobra.ExactArgs(2),
17
+ Run: func(cmd *cobra.Command, args []string) {
18
+ if err := handleUpdateComment(cmd, args[0], args[1]); err != nil {
19
+ fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
20
+ }
21
+ },
22
+ }
23
+
24
+ func handleUpdateComment(cmd *cobra.Command, cardNumber, commentID 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
+ body, _ := cmd.Flags().GetString("body")
36
+
37
+ comment, err := a.Client.PutCardComment(context.Background(), cardNum, commentID, body)
38
+ if err != nil {
39
+ return fmt.Errorf("updating comment: %w", err)
40
+ }
41
+
42
+ fmt.Printf("✓ Comment updated successfully (id: %s)\n", comment.ID)
43
+ return nil
44
+ }
45
+
46
+ func init() {
47
+ commentUpdateCmd.Flags().StringP("body", "b", "", "New comment body (required)")
48
+ commentUpdateCmd.MarkFlagRequired("body")
49
+
50
+ commentCmd.AddCommand(commentUpdateCmd)
51
+ }