fizzy-cli 0.8.0 → 0.9.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 (156) hide show
  1. package/package.json +2 -1
  2. package/.env +0 -1
  3. package/.github/workflows/release.yml +0 -29
  4. package/.github/workflows/tests.yml +0 -24
  5. package/AGENTS.md +0 -33
  6. package/CHANGELOG.md +0 -194
  7. package/Makefile +0 -43
  8. package/bin/fizzy +0 -0
  9. package/cmd/account.go +0 -14
  10. package/cmd/account_list.go +0 -44
  11. package/cmd/account_list_test.go +0 -118
  12. package/cmd/board.go +0 -49
  13. package/cmd/board_create.go +0 -59
  14. package/cmd/board_create_test.go +0 -141
  15. package/cmd/board_delete.go +0 -40
  16. package/cmd/board_delete_test.go +0 -121
  17. package/cmd/board_list.go +0 -44
  18. package/cmd/board_list_test.go +0 -115
  19. package/cmd/board_show.go +0 -40
  20. package/cmd/board_show_test.go +0 -113
  21. package/cmd/board_test.go +0 -92
  22. package/cmd/board_update.go +0 -72
  23. package/cmd/board_update_test.go +0 -233
  24. package/cmd/card.go +0 -24
  25. package/cmd/card_assign.go +0 -55
  26. package/cmd/card_assign_test.go +0 -130
  27. package/cmd/card_close.go +0 -46
  28. package/cmd/card_close_test.go +0 -92
  29. package/cmd/card_create.go +0 -72
  30. package/cmd/card_create_test.go +0 -186
  31. package/cmd/card_delete.go +0 -46
  32. package/cmd/card_delete_test.go +0 -92
  33. package/cmd/card_golden.go +0 -46
  34. package/cmd/card_golden_test.go +0 -92
  35. package/cmd/card_list.go +0 -114
  36. package/cmd/card_list_test.go +0 -373
  37. package/cmd/card_not_now.go +0 -46
  38. package/cmd/card_not_now_test.go +0 -92
  39. package/cmd/card_reaction.go +0 -13
  40. package/cmd/card_reaction_create.go +0 -46
  41. package/cmd/card_reaction_create_test.go +0 -148
  42. package/cmd/card_reaction_delete.go +0 -46
  43. package/cmd/card_reaction_delete_test.go +0 -112
  44. package/cmd/card_reaction_list.go +0 -51
  45. package/cmd/card_reaction_list_test.go +0 -127
  46. package/cmd/card_reopen.go +0 -46
  47. package/cmd/card_reopen_test.go +0 -92
  48. package/cmd/card_show.go +0 -46
  49. package/cmd/card_show_test.go +0 -92
  50. package/cmd/card_tag.go +0 -51
  51. package/cmd/card_tag_test.go +0 -112
  52. package/cmd/card_triage.go +0 -46
  53. package/cmd/card_ungolden.go +0 -46
  54. package/cmd/card_ungolden_test.go +0 -92
  55. package/cmd/card_untriage.go +0 -46
  56. package/cmd/card_untriage_test.go +0 -92
  57. package/cmd/card_unwatch.go +0 -46
  58. package/cmd/card_unwatch_test.go +0 -92
  59. package/cmd/card_update.go +0 -82
  60. package/cmd/card_update_test.go +0 -149
  61. package/cmd/card_watch.go +0 -46
  62. package/cmd/card_watch_test.go +0 -92
  63. package/cmd/column.go +0 -14
  64. package/cmd/column_create.go +0 -79
  65. package/cmd/column_create_test.go +0 -178
  66. package/cmd/column_delete.go +0 -40
  67. package/cmd/column_delete_test.go +0 -121
  68. package/cmd/column_list.go +0 -44
  69. package/cmd/column_list_test.go +0 -138
  70. package/cmd/column_show.go +0 -40
  71. package/cmd/column_show_test.go +0 -111
  72. package/cmd/column_update.go +0 -67
  73. package/cmd/column_update_test.go +0 -198
  74. package/cmd/comment.go +0 -14
  75. package/cmd/comment_create.go +0 -51
  76. package/cmd/comment_create_test.go +0 -129
  77. package/cmd/comment_delete.go +0 -46
  78. package/cmd/comment_delete_test.go +0 -92
  79. package/cmd/comment_list.go +0 -51
  80. package/cmd/comment_list_test.go +0 -132
  81. package/cmd/comment_show.go +0 -46
  82. package/cmd/comment_show_test.go +0 -104
  83. package/cmd/comment_update.go +0 -51
  84. package/cmd/comment_update_test.go +0 -130
  85. package/cmd/login.go +0 -81
  86. package/cmd/login_test.go +0 -98
  87. package/cmd/notification.go +0 -14
  88. package/cmd/notification_list.go +0 -69
  89. package/cmd/notification_list_test.go +0 -288
  90. package/cmd/notification_read.go +0 -51
  91. package/cmd/notification_read_all.go +0 -38
  92. package/cmd/notification_read_all_test.go +0 -75
  93. package/cmd/notification_read_test.go +0 -138
  94. package/cmd/notification_unread.go +0 -44
  95. package/cmd/notification_unread_test.go +0 -99
  96. package/cmd/reaction.go +0 -13
  97. package/cmd/reaction_create.go +0 -46
  98. package/cmd/reaction_create_test.go +0 -113
  99. package/cmd/reaction_delete.go +0 -46
  100. package/cmd/reaction_delete_test.go +0 -92
  101. package/cmd/reaction_list.go +0 -51
  102. package/cmd/reaction_list_test.go +0 -125
  103. package/cmd/root.go +0 -38
  104. package/cmd/step.go +0 -14
  105. package/cmd/step_create.go +0 -53
  106. package/cmd/step_create_test.go +0 -171
  107. package/cmd/step_delete.go +0 -46
  108. package/cmd/step_delete_test.go +0 -92
  109. package/cmd/step_update.go +0 -66
  110. package/cmd/step_update_test.go +0 -190
  111. package/cmd/tag.go +0 -15
  112. package/cmd/tag_list.go +0 -47
  113. package/cmd/tag_list_test.go +0 -109
  114. package/cmd/use.go +0 -85
  115. package/cmd/use_test.go +0 -186
  116. package/cmd/user.go +0 -22
  117. package/cmd/user_deactivate.go +0 -40
  118. package/cmd/user_deactivate_test.go +0 -121
  119. package/cmd/user_list.go +0 -44
  120. package/cmd/user_list_test.go +0 -126
  121. package/cmd/user_show.go +0 -40
  122. package/cmd/user_show_test.go +0 -110
  123. package/cmd/user_update.go +0 -71
  124. package/cmd/user_update_test.go +0 -177
  125. package/go.mod +0 -31
  126. package/go.sum +0 -53
  127. package/internal/api/boards.go +0 -93
  128. package/internal/api/cards.go +0 -322
  129. package/internal/api/client.go +0 -99
  130. package/internal/api/columns.go +0 -113
  131. package/internal/api/comments.go +0 -108
  132. package/internal/api/identity.go +0 -24
  133. package/internal/api/notifications.go +0 -89
  134. package/internal/api/reactions.go +0 -130
  135. package/internal/api/steps.go +0 -101
  136. package/internal/api/tags.go +0 -24
  137. package/internal/api/types.go +0 -195
  138. package/internal/api/users.go +0 -75
  139. package/internal/app/app.go +0 -49
  140. package/internal/colors/colors.go +0 -32
  141. package/internal/config/config.go +0 -70
  142. package/internal/testutil/client.go +0 -26
  143. package/internal/ui/account_list.go +0 -14
  144. package/internal/ui/account_selector.go +0 -63
  145. package/internal/ui/board_list.go +0 -14
  146. package/internal/ui/board_show.go +0 -17
  147. package/internal/ui/card_list.go +0 -14
  148. package/internal/ui/card_show.go +0 -23
  149. package/internal/ui/column_list.go +0 -28
  150. package/internal/ui/column_show.go +0 -16
  151. package/internal/ui/comment_list.go +0 -25
  152. package/internal/ui/format.go +0 -27
  153. package/internal/ui/notification_list.go +0 -27
  154. package/internal/ui/reaction_list.go +0 -14
  155. package/internal/ui/user_list.go +0 -19
  156. package/internal/ui/user_show.go +0 -23
@@ -1,148 +0,0 @@
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 TestCardReactionCreateCommandSuccess(t *testing.T) {
17
- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
18
- if r.URL.Path != "/cards/123/reactions" {
19
- t.Errorf("expected /cards/123/reactions, 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
- body, _ := io.ReadAll(r.Body)
31
- var payload map[string]map[string]string
32
- if err := json.Unmarshal(body, &payload); err != nil {
33
- t.Fatalf("failed to unmarshal request body: %v", err)
34
- }
35
-
36
- reactionPayload := payload["reaction"]
37
- if reactionPayload["content"] != "👍" {
38
- t.Errorf("expected content '👍', got %s", reactionPayload["content"])
39
- }
40
-
41
- w.Header().Set("Content-Type", "application/json")
42
- w.WriteHeader(http.StatusCreated)
43
- response := api.Reaction{
44
- ID: "reaction-123",
45
- Content: "👍",
46
- Reacter: api.User{ID: "user-1", Name: "John Doe"},
47
- }
48
- json.NewEncoder(w).Encode(response)
49
- }))
50
- defer server.Close()
51
-
52
- client := testutil.NewTestClient(server.URL, "", "", "test-token")
53
- testApp := &app.App{Client: client}
54
-
55
- cmd := cardReactionCreateCmd
56
- cmd.SetContext(testApp.ToContext(context.Background()))
57
-
58
- if err := handleCreateCardReaction(cmd, "123", "👍"); err != nil {
59
- t.Fatalf("handleCreateCardReaction failed: %v", err)
60
- }
61
- }
62
-
63
- func TestCardReactionCreateCommandInvalidCardNumber(t *testing.T) {
64
- testApp := &app.App{}
65
-
66
- cmd := cardReactionCreateCmd
67
- cmd.SetContext(testApp.ToContext(context.Background()))
68
-
69
- err := handleCreateCardReaction(cmd, "not-a-number", "👍")
70
- if err == nil {
71
- t.Errorf("expected error for invalid card number")
72
- }
73
- if err.Error() != "invalid card number: strconv.Atoi: parsing \"not-a-number\": invalid syntax" {
74
- t.Errorf("expected invalid card number error, got %v", err)
75
- }
76
- }
77
-
78
- func TestCardReactionCreateCommandNoClient(t *testing.T) {
79
- testApp := &app.App{}
80
-
81
- cmd := cardReactionCreateCmd
82
- cmd.SetContext(testApp.ToContext(context.Background()))
83
-
84
- err := handleCreateCardReaction(cmd, "123", "👍")
85
- if err == nil {
86
- t.Errorf("expected error when client not available")
87
- }
88
- if err.Error() != "API client not available" {
89
- t.Errorf("expected 'client not available' error, got %v", err)
90
- }
91
- }
92
-
93
- func TestCardReactionCreateCommandAPIError(t *testing.T) {
94
- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
95
- w.WriteHeader(http.StatusNotFound)
96
- w.Write([]byte("Card not found"))
97
- }))
98
- defer server.Close()
99
-
100
- client := testutil.NewTestClient(server.URL, "", "", "test-token")
101
- testApp := &app.App{Client: client}
102
-
103
- cmd := cardReactionCreateCmd
104
- cmd.SetContext(testApp.ToContext(context.Background()))
105
-
106
- err := handleCreateCardReaction(cmd, "123", "👍")
107
- if err == nil {
108
- t.Errorf("expected error for API failure")
109
- }
110
- if err.Error() != "creating reaction: unexpected status code 404: Card not found" {
111
- t.Errorf("expected API error, got %v", err)
112
- }
113
- }
114
-
115
- func TestCardReactionCreateCommandDifferentEmoji(t *testing.T) {
116
- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
117
- body, _ := io.ReadAll(r.Body)
118
- var payload map[string]map[string]string
119
- if err := json.Unmarshal(body, &payload); err != nil {
120
- t.Fatalf("failed to unmarshal request body: %v", err)
121
- }
122
-
123
- reactionPayload := payload["reaction"]
124
- if reactionPayload["content"] != "🎉" {
125
- t.Errorf("expected content '🎉', got %s", reactionPayload["content"])
126
- }
127
-
128
- w.Header().Set("Content-Type", "application/json")
129
- w.WriteHeader(http.StatusCreated)
130
- response := api.Reaction{
131
- ID: "reaction-456",
132
- Content: "🎉",
133
- Reacter: api.User{ID: "user-2", Name: "Jane Doe"},
134
- }
135
- json.NewEncoder(w).Encode(response)
136
- }))
137
- defer server.Close()
138
-
139
- client := testutil.NewTestClient(server.URL, "", "", "test-token")
140
- testApp := &app.App{Client: client}
141
-
142
- cmd := cardReactionCreateCmd
143
- cmd.SetContext(testApp.ToContext(context.Background()))
144
-
145
- if err := handleCreateCardReaction(cmd, "123", "🎉"); err != nil {
146
- t.Fatalf("handleCreateCardReaction failed: %v", err)
147
- }
148
- }
@@ -1,46 +0,0 @@
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 cardReactionDeleteCmd = &cobra.Command{
13
- Use: "delete <card_number> <reaction_id>",
14
- Short: "Delete a reaction from a card",
15
- Long: `Remove your reaction (boost) from a card`,
16
- Args: cobra.ExactArgs(2),
17
- Run: func(cmd *cobra.Command, args []string) {
18
- if err := handleDeleteCardReaction(cmd, args[0], args[1]); err != nil {
19
- fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
20
- }
21
- },
22
- }
23
-
24
- func handleDeleteCardReaction(cmd *cobra.Command, cardNumber, reactionID 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.DeleteCardReaction(context.Background(), cardNum, reactionID)
36
- if err != nil {
37
- return fmt.Errorf("deleting reaction: %w", err)
38
- }
39
-
40
- fmt.Fprintf(cmd.OutOrStdout(), "✓ Reaction deleted successfully\n")
41
- return nil
42
- }
43
-
44
- func init() {
45
- cardReactionCmd.AddCommand(cardReactionDeleteCmd)
46
- }
@@ -1,112 +0,0 @@
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 TestCardReactionDeleteCommandSuccess(t *testing.T) {
14
- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
15
- if r.URL.Path != "/cards/123/reactions/reaction-456" {
16
- t.Errorf("expected /cards/123/reactions/reaction-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 := cardReactionDeleteCmd
35
- cmd.SetContext(testApp.ToContext(context.Background()))
36
-
37
- if err := handleDeleteCardReaction(cmd, "123", "reaction-456"); err != nil {
38
- t.Fatalf("handleDeleteCardReaction failed: %v", err)
39
- }
40
- }
41
-
42
- func TestCardReactionDeleteCommandInvalidCardNumber(t *testing.T) {
43
- testApp := &app.App{}
44
-
45
- cmd := cardReactionDeleteCmd
46
- cmd.SetContext(testApp.ToContext(context.Background()))
47
-
48
- err := handleDeleteCardReaction(cmd, "not-a-number", "reaction-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 TestCardReactionDeleteCommandNoClient(t *testing.T) {
58
- testApp := &app.App{}
59
-
60
- cmd := cardReactionDeleteCmd
61
- cmd.SetContext(testApp.ToContext(context.Background()))
62
-
63
- err := handleDeleteCardReaction(cmd, "123", "reaction-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 TestCardReactionDeleteCommandAPIError(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("Reaction 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 := cardReactionDeleteCmd
83
- cmd.SetContext(testApp.ToContext(context.Background()))
84
-
85
- err := handleDeleteCardReaction(cmd, "123", "reaction-456")
86
- if err == nil {
87
- t.Errorf("expected error for API failure")
88
- }
89
- if err.Error() != "deleting reaction: unexpected status code 404: Reaction not found" {
90
- t.Errorf("expected API error, got %v", err)
91
- }
92
- }
93
-
94
- func TestCardReactionDeleteCommandDifferentReactionID(t *testing.T) {
95
- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
96
- if r.URL.Path != "/cards/456/reactions/reaction-789" {
97
- t.Errorf("expected /cards/456/reactions/reaction-789, got %s", r.URL.Path)
98
- }
99
- w.WriteHeader(http.StatusNoContent)
100
- }))
101
- defer server.Close()
102
-
103
- client := testutil.NewTestClient(server.URL, "", "", "test-token")
104
- testApp := &app.App{Client: client}
105
-
106
- cmd := cardReactionDeleteCmd
107
- cmd.SetContext(testApp.ToContext(context.Background()))
108
-
109
- if err := handleDeleteCardReaction(cmd, "456", "reaction-789"); err != nil {
110
- t.Fatalf("handleDeleteCardReaction failed: %v", err)
111
- }
112
- }
@@ -1,51 +0,0 @@
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 cardReactionListCmd = &cobra.Command{
14
- Use: "list <card_number>",
15
- Short: "List reactions on a card",
16
- Long: `Retrieve and display all reactions (boosts) on a card`,
17
- Args: cobra.ExactArgs(1),
18
- Run: func(cmd *cobra.Command, args []string) {
19
- if err := handleListCardReactions(cmd, args[0]); err != nil {
20
- fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
21
- }
22
- },
23
- }
24
-
25
- func handleListCardReactions(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
- reactions, err := a.Client.GetCardReactions(context.Background(), cardNum)
37
- if err != nil {
38
- return fmt.Errorf("fetching reactions: %w", err)
39
- }
40
-
41
- if len(reactions) == 0 {
42
- fmt.Println("No reactions found")
43
- return nil
44
- }
45
-
46
- return ui.DisplayReactions(reactions)
47
- }
48
-
49
- func init() {
50
- cardReactionCmd.AddCommand(cardReactionListCmd)
51
- }
@@ -1,127 +0,0 @@
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 TestCardReactionListCommandSuccess(t *testing.T) {
16
- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
17
- if r.URL.Path != "/cards/123/reactions" {
18
- t.Errorf("expected /cards/123/reactions, 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
- w.WriteHeader(http.StatusOK)
31
- reactions := []api.Reaction{
32
- {
33
- ID: "reaction-1",
34
- Content: "👍",
35
- Reacter: api.User{ID: "user-1", Name: "Alice"},
36
- },
37
- {
38
- ID: "reaction-2",
39
- Content: "🎉",
40
- Reacter: api.User{ID: "user-2", Name: "Bob"},
41
- },
42
- }
43
- json.NewEncoder(w).Encode(reactions)
44
- }))
45
- defer server.Close()
46
-
47
- client := testutil.NewTestClient(server.URL, "", "", "test-token")
48
- testApp := &app.App{Client: client}
49
-
50
- cmd := cardReactionListCmd
51
- cmd.SetContext(testApp.ToContext(context.Background()))
52
-
53
- if err := handleListCardReactions(cmd, "123"); err != nil {
54
- t.Fatalf("handleListCardReactions failed: %v", err)
55
- }
56
- }
57
-
58
- func TestCardReactionListCommandNoReactions(t *testing.T) {
59
- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
60
- w.Header().Set("Content-Type", "application/json")
61
- w.WriteHeader(http.StatusOK)
62
- json.NewEncoder(w).Encode([]api.Reaction{})
63
- }))
64
- defer server.Close()
65
-
66
- client := testutil.NewTestClient(server.URL, "", "", "test-token")
67
- testApp := &app.App{Client: client}
68
-
69
- cmd := cardReactionListCmd
70
- cmd.SetContext(testApp.ToContext(context.Background()))
71
-
72
- if err := handleListCardReactions(cmd, "123"); err != nil {
73
- t.Fatalf("handleListCardReactions failed: %v", err)
74
- }
75
- }
76
-
77
- func TestCardReactionListCommandInvalidCardNumber(t *testing.T) {
78
- testApp := &app.App{}
79
-
80
- cmd := cardReactionListCmd
81
- cmd.SetContext(testApp.ToContext(context.Background()))
82
-
83
- err := handleListCardReactions(cmd, "not-a-number")
84
- if err == nil {
85
- t.Errorf("expected error for invalid card number")
86
- }
87
- if err.Error() != "invalid card number: strconv.Atoi: parsing \"not-a-number\": invalid syntax" {
88
- t.Errorf("expected invalid card number error, got %v", err)
89
- }
90
- }
91
-
92
- func TestCardReactionListCommandNoClient(t *testing.T) {
93
- testApp := &app.App{}
94
-
95
- cmd := cardReactionListCmd
96
- cmd.SetContext(testApp.ToContext(context.Background()))
97
-
98
- err := handleListCardReactions(cmd, "123")
99
- if err == nil {
100
- t.Errorf("expected error when client not available")
101
- }
102
- if err.Error() != "API client not available" {
103
- t.Errorf("expected 'client not available' error, got %v", err)
104
- }
105
- }
106
-
107
- func TestCardReactionListCommandAPIError(t *testing.T) {
108
- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
109
- w.WriteHeader(http.StatusNotFound)
110
- w.Write([]byte("Card not found"))
111
- }))
112
- defer server.Close()
113
-
114
- client := testutil.NewTestClient(server.URL, "", "", "test-token")
115
- testApp := &app.App{Client: client}
116
-
117
- cmd := cardReactionListCmd
118
- cmd.SetContext(testApp.ToContext(context.Background()))
119
-
120
- err := handleListCardReactions(cmd, "123")
121
- if err == nil {
122
- t.Errorf("expected error for API failure")
123
- }
124
- if err.Error() != "fetching reactions: unexpected status code 404: Card not found" {
125
- t.Errorf("expected API error, got %v", err)
126
- }
127
- }
@@ -1,46 +0,0 @@
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 cardReopenCmd = &cobra.Command{
13
- Use: "reopen <card_number>",
14
- Short: "Reopen a card",
15
- Long: `Reopen an existing closed card`,
16
- Args: cobra.ExactArgs(1),
17
- Run: func(cmd *cobra.Command, args []string) {
18
- if err := handleReopenCard(cmd, args[0]); err != nil {
19
- fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
20
- }
21
- },
22
- }
23
-
24
- func handleReopenCard(cmd *cobra.Command, cardNumber 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.DeleteCardsClosure(context.Background(), cardNum)
36
- if err != nil {
37
- return fmt.Errorf("reopening card: %w", err)
38
- }
39
-
40
- fmt.Fprintf(cmd.OutOrStdout(), "✓ Card #%d reopened successfully\n", cardNum)
41
- return nil
42
- }
43
-
44
- func init() {
45
- cardCmd.AddCommand(cardReopenCmd)
46
- }
@@ -1,92 +0,0 @@
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 TestCardReopenCommandSuccess(t *testing.T) {
14
- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
15
- if r.URL.Path != "/cards/123/closure" {
16
- t.Errorf("expected /cards/123/closure, 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 := cardReopenCmd
35
- cmd.SetContext(testApp.ToContext(context.Background()))
36
-
37
- if err := handleReopenCard(cmd, "123"); err != nil {
38
- t.Fatalf("handleReopenCard failed: %v", err)
39
- }
40
- }
41
-
42
- func TestCardReopenCommandInvalidCardNumber(t *testing.T) {
43
- testApp := &app.App{}
44
-
45
- cmd := cardReopenCmd
46
- cmd.SetContext(testApp.ToContext(context.Background()))
47
-
48
- err := handleReopenCard(cmd, "not-a-number")
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 TestCardReopenCommandNoClient(t *testing.T) {
58
- testApp := &app.App{}
59
-
60
- cmd := cardReopenCmd
61
- cmd.SetContext(testApp.ToContext(context.Background()))
62
-
63
- err := handleReopenCard(cmd, "123")
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 TestCardReopenCommandAPIError(t *testing.T) {
73
- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
74
- w.WriteHeader(http.StatusInternalServerError)
75
- w.Write([]byte("Internal Server Error"))
76
- }))
77
- defer server.Close()
78
-
79
- client := testutil.NewTestClient(server.URL, "", "", "test-token")
80
- testApp := &app.App{Client: client}
81
-
82
- cmd := cardReopenCmd
83
- cmd.SetContext(testApp.ToContext(context.Background()))
84
-
85
- err := handleReopenCard(cmd, "123")
86
- if err == nil {
87
- t.Errorf("expected error for API failure")
88
- }
89
- if err.Error() != "reopening card: unexpected status code 500: Internal Server Error" {
90
- t.Errorf("expected API error, got %v", err)
91
- }
92
- }
package/cmd/card_show.go DELETED
@@ -1,46 +0,0 @@
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 cardShowCmd = &cobra.Command{
14
- Use: "show <card_id>",
15
- Short: "Show card details",
16
- Long: `Retrieve and display details for a specific card`,
17
- Args: cobra.ExactArgs(1),
18
- Run: func(cmd *cobra.Command, args []string) {
19
- if err := handleShowCard(cmd, args[0]); err != nil {
20
- fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
21
- }
22
- },
23
- }
24
-
25
- func handleShowCard(cmd *cobra.Command, cardID string) error {
26
- a := app.FromContext(cmd.Context())
27
- if a == nil || a.Client == nil {
28
- return fmt.Errorf("API client not available")
29
- }
30
-
31
- cardNumber, err := strconv.Atoi(cardID)
32
- if err != nil {
33
- return fmt.Errorf("card ID must be a number: %w", err)
34
- }
35
-
36
- card, err := a.Client.GetCard(context.Background(), cardNumber)
37
- if err != nil {
38
- return fmt.Errorf("fetching card: %w", err)
39
- }
40
-
41
- return ui.DisplayCard(card)
42
- }
43
-
44
- func init() {
45
- cardCmd.AddCommand(cardShowCmd)
46
- }