fizzy-cli 0.6.1 → 0.8.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.
- package/CHANGELOG.md +46 -0
- package/bin/fizzy +0 -0
- package/cmd/board.go +1 -1
- package/cmd/board_create.go +1 -1
- package/cmd/board_delete.go +40 -0
- package/cmd/board_delete_test.go +121 -0
- package/cmd/board_show.go +40 -0
- package/cmd/board_show_test.go +113 -0
- package/cmd/board_update.go +72 -0
- package/cmd/board_update_test.go +233 -0
- package/cmd/card_assign.go +1 -1
- package/cmd/card_close.go +1 -1
- package/cmd/card_create.go +1 -1
- package/cmd/card_delete.go +1 -1
- package/cmd/card_golden.go +1 -1
- package/cmd/card_list.go +62 -1
- package/cmd/card_list_test.go +225 -0
- package/cmd/card_not_now.go +1 -1
- package/cmd/card_reaction.go +13 -0
- package/cmd/card_reaction_create.go +46 -0
- package/cmd/card_reaction_create_test.go +148 -0
- package/cmd/card_reaction_delete.go +46 -0
- package/cmd/card_reaction_delete_test.go +112 -0
- package/cmd/card_reaction_list.go +51 -0
- package/cmd/card_reaction_list_test.go +127 -0
- package/cmd/card_reopen.go +1 -1
- package/cmd/card_tag.go +1 -1
- package/cmd/card_triage.go +1 -1
- package/cmd/card_ungolden.go +1 -1
- package/cmd/card_untriage.go +1 -1
- package/cmd/card_unwatch.go +1 -1
- package/cmd/card_update.go +1 -1
- package/cmd/card_watch.go +1 -1
- package/cmd/column_create.go +1 -1
- package/cmd/column_delete.go +40 -0
- package/cmd/column_delete_test.go +121 -0
- package/cmd/column_show.go +40 -0
- package/cmd/column_show_test.go +111 -0
- package/cmd/column_update.go +67 -0
- package/cmd/column_update_test.go +198 -0
- package/cmd/comment_create.go +1 -1
- package/cmd/comment_delete.go +1 -1
- package/cmd/comment_update.go +1 -1
- package/cmd/login.go +12 -12
- package/cmd/notification_unread.go +1 -1
- package/cmd/reaction.go +2 -2
- package/cmd/reaction_create.go +1 -1
- package/cmd/reaction_delete.go +1 -1
- package/cmd/step_create.go +1 -1
- package/cmd/step_delete.go +1 -1
- package/cmd/step_update.go +1 -1
- package/cmd/user.go +22 -0
- package/cmd/user_deactivate.go +40 -0
- package/cmd/user_deactivate_test.go +121 -0
- package/cmd/user_list.go +44 -0
- package/cmd/user_list_test.go +126 -0
- package/cmd/user_show.go +40 -0
- package/cmd/user_show_test.go +110 -0
- package/cmd/user_update.go +71 -0
- package/cmd/user_update_test.go +177 -0
- package/docs/API.md +63 -2
- package/internal/api/boards.go +34 -0
- package/internal/api/cards.go +40 -6
- package/internal/api/columns.go +63 -0
- package/internal/api/reactions.go +61 -0
- package/internal/api/types.go +17 -0
- package/internal/api/users.go +75 -0
- package/internal/ui/board_show.go +17 -0
- package/internal/ui/column_show.go +16 -0
- package/internal/ui/format.go +14 -1
- package/internal/ui/user_list.go +19 -0
- package/internal/ui/user_show.go +23 -0
- package/package.json +1 -1
|
@@ -0,0 +1,112 @@
|
|
|
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
|
+
}
|
|
@@ -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 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
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
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
|
+
}
|
package/cmd/card_reopen.go
CHANGED
|
@@ -37,7 +37,7 @@ func handleReopenCard(cmd *cobra.Command, cardNumber string) error {
|
|
|
37
37
|
return fmt.Errorf("reopening card: %w", err)
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
fmt.
|
|
40
|
+
fmt.Fprintf(cmd.OutOrStdout(), "✓ Card #%d reopened successfully\n", cardNum)
|
|
41
41
|
return nil
|
|
42
42
|
}
|
|
43
43
|
|
package/cmd/card_tag.go
CHANGED
|
@@ -42,7 +42,7 @@ func handleTagCard(cmd *cobra.Command, cardNumber, tagTitle string) error {
|
|
|
42
42
|
return fmt.Errorf("toggling tag on card: %w", err)
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
fmt.
|
|
45
|
+
fmt.Fprintf(cmd.OutOrStdout(), "✓ Tag '%s' toggled on card #%d\n", tagTitle, cardNum)
|
|
46
46
|
return nil
|
|
47
47
|
}
|
|
48
48
|
|
package/cmd/card_triage.go
CHANGED
|
@@ -37,7 +37,7 @@ func handleTriageCard(cmd *cobra.Command, cardNumber string, columnID string) er
|
|
|
37
37
|
return fmt.Errorf("triaging card: %w", err)
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
fmt.
|
|
40
|
+
fmt.Fprintf(cmd.OutOrStdout(), "✓ Card #%d moved to column successfully\n", cardNum)
|
|
41
41
|
return nil
|
|
42
42
|
}
|
|
43
43
|
|
package/cmd/card_ungolden.go
CHANGED
|
@@ -37,7 +37,7 @@ func handleUngoldenCard(cmd *cobra.Command, cardNumber string) error {
|
|
|
37
37
|
return fmt.Errorf("removing golden status: %w", err)
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
fmt.
|
|
40
|
+
fmt.Fprintf(cmd.OutOrStdout(), "✓ Card #%d golden status removed\n", cardNum)
|
|
41
41
|
return nil
|
|
42
42
|
}
|
|
43
43
|
|
package/cmd/card_untriage.go
CHANGED
|
@@ -37,7 +37,7 @@ func handleUntriagedCard(cmd *cobra.Command, cardNumber string) error {
|
|
|
37
37
|
return fmt.Errorf("sending card back to triage: %w", err)
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
fmt.
|
|
40
|
+
fmt.Fprintf(cmd.OutOrStdout(), "✓ Card #%d sent back to triage successfully\n", cardNum)
|
|
41
41
|
return nil
|
|
42
42
|
}
|
|
43
43
|
|
package/cmd/card_unwatch.go
CHANGED
|
@@ -37,7 +37,7 @@ func handleUnwatchCard(cmd *cobra.Command, cardNumber string) error {
|
|
|
37
37
|
return fmt.Errorf("unwatching card: %w", err)
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
fmt.
|
|
40
|
+
fmt.Fprintf(cmd.OutOrStdout(), "✓ Stopped watching card #%d\n", cardNum)
|
|
41
41
|
return nil
|
|
42
42
|
}
|
|
43
43
|
|
package/cmd/card_update.go
CHANGED
|
@@ -67,7 +67,7 @@ func handleUpdateCard(cmd *cobra.Command, cardNumber string) error {
|
|
|
67
67
|
return fmt.Errorf("updating card: %w", err)
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
fmt.
|
|
70
|
+
fmt.Fprintf(cmd.OutOrStdout(), "✓ Card #%d updated successfully\n", card.Number)
|
|
71
71
|
return nil
|
|
72
72
|
}
|
|
73
73
|
|
package/cmd/card_watch.go
CHANGED
|
@@ -37,7 +37,7 @@ func handleWatchCard(cmd *cobra.Command, cardNumber string) error {
|
|
|
37
37
|
return fmt.Errorf("watching card: %w", err)
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
fmt.
|
|
40
|
+
fmt.Fprintf(cmd.OutOrStdout(), "✓ Now watching card #%d\n", cardNum)
|
|
41
41
|
return nil
|
|
42
42
|
}
|
|
43
43
|
|
package/cmd/column_create.go
CHANGED
|
@@ -66,7 +66,7 @@ func handleCreateColumn(cmd *cobra.Command) error {
|
|
|
66
66
|
return fmt.Errorf("creating column: %w", err)
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
fmt.
|
|
69
|
+
fmt.Fprintf(cmd.OutOrStdout(), "✓ Column '%s' created successfully\n", name)
|
|
70
70
|
return nil
|
|
71
71
|
}
|
|
72
72
|
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
package cmd
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"context"
|
|
5
|
+
"fmt"
|
|
6
|
+
|
|
7
|
+
"github.com/rogeriopvl/fizzy/internal/app"
|
|
8
|
+
"github.com/spf13/cobra"
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
var columnDeleteCmd = &cobra.Command{
|
|
12
|
+
Use: "delete <column_id>",
|
|
13
|
+
Short: "Delete a column",
|
|
14
|
+
Long: `Delete a column. Only board administrators can delete columns.`,
|
|
15
|
+
Args: cobra.ExactArgs(1),
|
|
16
|
+
Run: func(cmd *cobra.Command, args []string) {
|
|
17
|
+
if err := handleDeleteColumn(cmd, args[0]); err != nil {
|
|
18
|
+
fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
func handleDeleteColumn(cmd *cobra.Command, columnID string) error {
|
|
24
|
+
a := app.FromContext(cmd.Context())
|
|
25
|
+
if a == nil || a.Client == nil {
|
|
26
|
+
return fmt.Errorf("API client not available")
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
err := a.Client.DeleteColumn(context.Background(), columnID)
|
|
30
|
+
if err != nil {
|
|
31
|
+
return fmt.Errorf("deleting column: %w", err)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
fmt.Fprintf(cmd.OutOrStdout(), "✓ Column '%s' deleted successfully\n", columnID)
|
|
35
|
+
return nil
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
func init() {
|
|
39
|
+
columnCmd.AddCommand(columnDeleteCmd)
|
|
40
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
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 TestColumnDeleteCommandSuccess(t *testing.T) {
|
|
14
|
+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
15
|
+
if r.URL.Path != "/boards/board-123/columns/col-456" {
|
|
16
|
+
t.Errorf("expected /boards/board-123/columns/col-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, "", "board-123", "test-token")
|
|
32
|
+
testApp := &app.App{Client: client}
|
|
33
|
+
|
|
34
|
+
cmd := columnDeleteCmd
|
|
35
|
+
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
36
|
+
|
|
37
|
+
if err := handleDeleteColumn(cmd, "col-456"); err != nil {
|
|
38
|
+
t.Fatalf("handleDeleteColumn failed: %v", err)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
func TestColumnDeleteCommandNotFound(t *testing.T) {
|
|
43
|
+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
44
|
+
w.WriteHeader(http.StatusNotFound)
|
|
45
|
+
w.Write([]byte("Column not found"))
|
|
46
|
+
}))
|
|
47
|
+
defer server.Close()
|
|
48
|
+
|
|
49
|
+
client := testutil.NewTestClient(server.URL, "", "board-123", "test-token")
|
|
50
|
+
testApp := &app.App{Client: client}
|
|
51
|
+
|
|
52
|
+
cmd := columnDeleteCmd
|
|
53
|
+
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
54
|
+
|
|
55
|
+
err := handleDeleteColumn(cmd, "nonexistent-col")
|
|
56
|
+
if err == nil {
|
|
57
|
+
t.Errorf("expected error for column not found")
|
|
58
|
+
}
|
|
59
|
+
if err.Error() != "deleting column: unexpected status code 404: Column not found" {
|
|
60
|
+
t.Errorf("expected column not found error, got %v", err)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
func TestColumnDeleteCommandForbidden(t *testing.T) {
|
|
65
|
+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
66
|
+
w.WriteHeader(http.StatusForbidden)
|
|
67
|
+
w.Write([]byte("You don't have permission to delete this column"))
|
|
68
|
+
}))
|
|
69
|
+
defer server.Close()
|
|
70
|
+
|
|
71
|
+
client := testutil.NewTestClient(server.URL, "", "board-123", "test-token")
|
|
72
|
+
testApp := &app.App{Client: client}
|
|
73
|
+
|
|
74
|
+
cmd := columnDeleteCmd
|
|
75
|
+
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
76
|
+
|
|
77
|
+
err := handleDeleteColumn(cmd, "col-456")
|
|
78
|
+
if err == nil {
|
|
79
|
+
t.Errorf("expected error for forbidden access")
|
|
80
|
+
}
|
|
81
|
+
if err.Error() != "deleting column: unexpected status code 403: You don't have permission to delete this column" {
|
|
82
|
+
t.Errorf("expected permission error, got %v", err)
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
func TestColumnDeleteCommandAPIError(t *testing.T) {
|
|
87
|
+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
88
|
+
w.WriteHeader(http.StatusInternalServerError)
|
|
89
|
+
w.Write([]byte("Internal Server Error"))
|
|
90
|
+
}))
|
|
91
|
+
defer server.Close()
|
|
92
|
+
|
|
93
|
+
client := testutil.NewTestClient(server.URL, "", "board-123", "test-token")
|
|
94
|
+
testApp := &app.App{Client: client}
|
|
95
|
+
|
|
96
|
+
cmd := columnDeleteCmd
|
|
97
|
+
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
98
|
+
|
|
99
|
+
err := handleDeleteColumn(cmd, "col-456")
|
|
100
|
+
if err == nil {
|
|
101
|
+
t.Errorf("expected error for API failure")
|
|
102
|
+
}
|
|
103
|
+
if err.Error() != "deleting column: unexpected status code 500: Internal Server Error" {
|
|
104
|
+
t.Errorf("expected API error, got %v", err)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
func TestColumnDeleteCommandNoClient(t *testing.T) {
|
|
109
|
+
testApp := &app.App{}
|
|
110
|
+
|
|
111
|
+
cmd := columnDeleteCmd
|
|
112
|
+
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
113
|
+
|
|
114
|
+
err := handleDeleteColumn(cmd, "col-456")
|
|
115
|
+
if err == nil {
|
|
116
|
+
t.Errorf("expected error when client not available")
|
|
117
|
+
}
|
|
118
|
+
if err.Error() != "API client not available" {
|
|
119
|
+
t.Errorf("expected 'client not available' error, got %v", err)
|
|
120
|
+
}
|
|
121
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
package cmd
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"context"
|
|
5
|
+
"fmt"
|
|
6
|
+
|
|
7
|
+
"github.com/rogeriopvl/fizzy/internal/app"
|
|
8
|
+
"github.com/rogeriopvl/fizzy/internal/ui"
|
|
9
|
+
"github.com/spf13/cobra"
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
var columnShowCmd = &cobra.Command{
|
|
13
|
+
Use: "show <column_id>",
|
|
14
|
+
Short: "Show column details",
|
|
15
|
+
Long: `Retrieve and display detailed information about a specific column`,
|
|
16
|
+
Args: cobra.ExactArgs(1),
|
|
17
|
+
Run: func(cmd *cobra.Command, args []string) {
|
|
18
|
+
if err := handleShowColumnDetails(cmd, args[0]); err != nil {
|
|
19
|
+
fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
func handleShowColumnDetails(cmd *cobra.Command, columnID string) error {
|
|
25
|
+
a := app.FromContext(cmd.Context())
|
|
26
|
+
if a == nil || a.Client == nil {
|
|
27
|
+
return fmt.Errorf("API client not available")
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
column, err := a.Client.GetColumn(context.Background(), columnID)
|
|
31
|
+
if err != nil {
|
|
32
|
+
return fmt.Errorf("fetching column: %w", err)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return ui.DisplayColumn(cmd.OutOrStdout(), column)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
func init() {
|
|
39
|
+
columnCmd.AddCommand(columnShowCmd)
|
|
40
|
+
}
|