fizzy-cli 0.7.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.
- package/docs/API.md +63 -2
- package/package.json +2 -1
- package/.github/workflows/release.yml +0 -29
- package/.github/workflows/tests.yml +0 -24
- package/AGENTS.md +0 -33
- package/CHANGELOG.md +0 -168
- package/Makefile +0 -43
- package/bin/fizzy +0 -0
- package/cmd/account.go +0 -14
- package/cmd/account_list.go +0 -44
- package/cmd/account_list_test.go +0 -118
- package/cmd/board.go +0 -49
- package/cmd/board_create.go +0 -59
- package/cmd/board_create_test.go +0 -141
- package/cmd/board_delete.go +0 -40
- package/cmd/board_delete_test.go +0 -121
- package/cmd/board_list.go +0 -44
- package/cmd/board_list_test.go +0 -115
- package/cmd/board_show.go +0 -40
- package/cmd/board_show_test.go +0 -113
- package/cmd/board_test.go +0 -92
- package/cmd/board_update.go +0 -72
- package/cmd/board_update_test.go +0 -233
- package/cmd/card.go +0 -24
- package/cmd/card_assign.go +0 -55
- package/cmd/card_assign_test.go +0 -130
- package/cmd/card_close.go +0 -46
- package/cmd/card_close_test.go +0 -92
- package/cmd/card_create.go +0 -72
- package/cmd/card_create_test.go +0 -186
- package/cmd/card_delete.go +0 -46
- package/cmd/card_delete_test.go +0 -92
- package/cmd/card_golden.go +0 -46
- package/cmd/card_golden_test.go +0 -92
- package/cmd/card_list.go +0 -53
- package/cmd/card_list_test.go +0 -148
- package/cmd/card_not_now.go +0 -46
- package/cmd/card_not_now_test.go +0 -92
- package/cmd/card_reopen.go +0 -46
- package/cmd/card_reopen_test.go +0 -92
- package/cmd/card_show.go +0 -46
- package/cmd/card_show_test.go +0 -92
- package/cmd/card_tag.go +0 -51
- package/cmd/card_tag_test.go +0 -112
- package/cmd/card_triage.go +0 -46
- package/cmd/card_ungolden.go +0 -46
- package/cmd/card_ungolden_test.go +0 -92
- package/cmd/card_untriage.go +0 -46
- package/cmd/card_untriage_test.go +0 -92
- package/cmd/card_unwatch.go +0 -46
- package/cmd/card_unwatch_test.go +0 -92
- package/cmd/card_update.go +0 -82
- package/cmd/card_update_test.go +0 -149
- package/cmd/card_watch.go +0 -46
- package/cmd/card_watch_test.go +0 -92
- package/cmd/column.go +0 -14
- package/cmd/column_create.go +0 -79
- package/cmd/column_create_test.go +0 -178
- package/cmd/column_delete.go +0 -40
- package/cmd/column_delete_test.go +0 -121
- package/cmd/column_list.go +0 -44
- package/cmd/column_list_test.go +0 -138
- package/cmd/column_show.go +0 -40
- package/cmd/column_show_test.go +0 -111
- package/cmd/column_update.go +0 -67
- package/cmd/column_update_test.go +0 -198
- package/cmd/comment.go +0 -14
- package/cmd/comment_create.go +0 -51
- package/cmd/comment_create_test.go +0 -129
- package/cmd/comment_delete.go +0 -46
- package/cmd/comment_delete_test.go +0 -92
- package/cmd/comment_list.go +0 -51
- package/cmd/comment_list_test.go +0 -132
- package/cmd/comment_show.go +0 -46
- package/cmd/comment_show_test.go +0 -104
- package/cmd/comment_update.go +0 -51
- package/cmd/comment_update_test.go +0 -130
- package/cmd/login.go +0 -81
- package/cmd/login_test.go +0 -98
- package/cmd/notification.go +0 -14
- package/cmd/notification_list.go +0 -69
- package/cmd/notification_list_test.go +0 -288
- package/cmd/notification_read.go +0 -51
- package/cmd/notification_read_all.go +0 -38
- package/cmd/notification_read_all_test.go +0 -75
- package/cmd/notification_read_test.go +0 -138
- package/cmd/notification_unread.go +0 -44
- package/cmd/notification_unread_test.go +0 -99
- package/cmd/reaction.go +0 -13
- package/cmd/reaction_create.go +0 -46
- package/cmd/reaction_create_test.go +0 -113
- package/cmd/reaction_delete.go +0 -46
- package/cmd/reaction_delete_test.go +0 -92
- package/cmd/reaction_list.go +0 -51
- package/cmd/reaction_list_test.go +0 -125
- package/cmd/root.go +0 -38
- package/cmd/step.go +0 -14
- package/cmd/step_create.go +0 -53
- package/cmd/step_create_test.go +0 -171
- package/cmd/step_delete.go +0 -46
- package/cmd/step_delete_test.go +0 -92
- package/cmd/step_update.go +0 -66
- package/cmd/step_update_test.go +0 -190
- package/cmd/tag.go +0 -15
- package/cmd/tag_list.go +0 -47
- package/cmd/tag_list_test.go +0 -109
- package/cmd/use.go +0 -85
- package/cmd/use_test.go +0 -186
- package/go.mod +0 -31
- package/go.sum +0 -53
- package/internal/api/boards.go +0 -93
- package/internal/api/cards.go +0 -288
- package/internal/api/client.go +0 -99
- package/internal/api/columns.go +0 -113
- package/internal/api/comments.go +0 -108
- package/internal/api/identity.go +0 -24
- package/internal/api/notifications.go +0 -89
- package/internal/api/reactions.go +0 -69
- package/internal/api/steps.go +0 -101
- package/internal/api/tags.go +0 -24
- package/internal/api/types.go +0 -190
- package/internal/app/app.go +0 -49
- package/internal/colors/colors.go +0 -32
- package/internal/config/config.go +0 -70
- package/internal/testutil/client.go +0 -26
- package/internal/ui/account_list.go +0 -14
- package/internal/ui/account_selector.go +0 -63
- package/internal/ui/board_list.go +0 -14
- package/internal/ui/board_show.go +0 -17
- package/internal/ui/card_list.go +0 -14
- package/internal/ui/card_show.go +0 -23
- package/internal/ui/column_list.go +0 -28
- package/internal/ui/column_show.go +0 -16
- package/internal/ui/comment_list.go +0 -25
- package/internal/ui/format.go +0 -27
- package/internal/ui/notification_list.go +0 -27
- package/internal/ui/reaction_list.go +0 -14
package/cmd/card_list_test.go
DELETED
|
@@ -1,148 +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/config"
|
|
13
|
-
"github.com/rogeriopvl/fizzy/internal/testutil"
|
|
14
|
-
)
|
|
15
|
-
|
|
16
|
-
func TestCardListCommand(t *testing.T) {
|
|
17
|
-
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
18
|
-
if r.URL.Path != "/cards" {
|
|
19
|
-
t.Errorf("expected /cards, got %s", r.URL.Path)
|
|
20
|
-
}
|
|
21
|
-
if r.Method != http.MethodGet {
|
|
22
|
-
t.Errorf("expected GET, got %s", r.Method)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
boardIDs := r.URL.Query()["board_ids[]"]
|
|
26
|
-
if len(boardIDs) == 0 || boardIDs[0] != "board-123" {
|
|
27
|
-
t.Errorf("expected board_ids[]=board-123 in query, got %v", boardIDs)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
auth := r.Header.Get("Authorization")
|
|
31
|
-
if auth != "Bearer test-token" {
|
|
32
|
-
t.Errorf("expected Bearer test-token, got %s", auth)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
w.Header().Set("Content-Type", "application/json")
|
|
36
|
-
response := []api.Card{
|
|
37
|
-
{
|
|
38
|
-
ID: "card-123",
|
|
39
|
-
Number: 1,
|
|
40
|
-
Title: "Implement feature",
|
|
41
|
-
Status: "in_progress",
|
|
42
|
-
CreatedAt: "2025-01-01T00:00:00Z",
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
ID: "card-456",
|
|
46
|
-
Number: 2,
|
|
47
|
-
Title: "Fix bug",
|
|
48
|
-
Status: "todo",
|
|
49
|
-
CreatedAt: "2025-01-02T00:00:00Z",
|
|
50
|
-
},
|
|
51
|
-
}
|
|
52
|
-
json.NewEncoder(w).Encode(response)
|
|
53
|
-
}))
|
|
54
|
-
defer server.Close()
|
|
55
|
-
|
|
56
|
-
client := testutil.NewTestClient(server.URL, "", "board-123", "test-token")
|
|
57
|
-
testApp := &app.App{
|
|
58
|
-
Client: client,
|
|
59
|
-
Config: &config.Config{SelectedBoard: "board-123"},
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
cmd := cardListCmd
|
|
63
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
64
|
-
|
|
65
|
-
if err := handleListCards(cmd); err != nil {
|
|
66
|
-
t.Fatalf("handleListCards failed: %v", err)
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
func TestCardListCommandNoCards(t *testing.T) {
|
|
71
|
-
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
72
|
-
w.Header().Set("Content-Type", "application/json")
|
|
73
|
-
json.NewEncoder(w).Encode([]api.Card{})
|
|
74
|
-
}))
|
|
75
|
-
defer server.Close()
|
|
76
|
-
|
|
77
|
-
client := testutil.NewTestClient(server.URL, "", "board-123", "test-token")
|
|
78
|
-
testApp := &app.App{
|
|
79
|
-
Client: client,
|
|
80
|
-
Config: &config.Config{SelectedBoard: "board-123"},
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
cmd := cardListCmd
|
|
84
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
85
|
-
|
|
86
|
-
if err := handleListCards(cmd); err != nil {
|
|
87
|
-
t.Fatalf("handleListCards failed: %v", err)
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
func TestCardListCommandAPIError(t *testing.T) {
|
|
92
|
-
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
93
|
-
w.WriteHeader(http.StatusInternalServerError)
|
|
94
|
-
w.Write([]byte("Internal Server Error"))
|
|
95
|
-
}))
|
|
96
|
-
defer server.Close()
|
|
97
|
-
|
|
98
|
-
client := testutil.NewTestClient(server.URL, "", "board-123", "test-token")
|
|
99
|
-
testApp := &app.App{
|
|
100
|
-
Client: client,
|
|
101
|
-
Config: &config.Config{SelectedBoard: "board-123"},
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
cmd := cardListCmd
|
|
105
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
106
|
-
|
|
107
|
-
err := handleListCards(cmd)
|
|
108
|
-
if err == nil {
|
|
109
|
-
t.Errorf("expected error for API failure")
|
|
110
|
-
}
|
|
111
|
-
if err.Error() != "fetching cards: unexpected status code 500: Internal Server Error" {
|
|
112
|
-
t.Errorf("expected API error, got %v", err)
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
func TestCardListCommandNoBoard(t *testing.T) {
|
|
117
|
-
client := testutil.NewTestClient("http://localhost", "", "", "test-token")
|
|
118
|
-
testApp := &app.App{
|
|
119
|
-
Client: client,
|
|
120
|
-
Config: &config.Config{SelectedBoard: ""},
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
cmd := cardListCmd
|
|
124
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
125
|
-
|
|
126
|
-
err := handleListCards(cmd)
|
|
127
|
-
if err == nil {
|
|
128
|
-
t.Errorf("expected error when board not selected")
|
|
129
|
-
}
|
|
130
|
-
if err.Error() != "no board selected" {
|
|
131
|
-
t.Errorf("expected 'no board selected' error, got %v", err)
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
func TestCardListCommandNoClient(t *testing.T) {
|
|
136
|
-
testApp := &app.App{}
|
|
137
|
-
|
|
138
|
-
cmd := cardListCmd
|
|
139
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
140
|
-
|
|
141
|
-
err := handleListCards(cmd)
|
|
142
|
-
if err == nil {
|
|
143
|
-
t.Errorf("expected error when client not available")
|
|
144
|
-
}
|
|
145
|
-
if err.Error() != "API client not available" {
|
|
146
|
-
t.Errorf("expected 'client not available' error, got %v", err)
|
|
147
|
-
}
|
|
148
|
-
}
|
package/cmd/card_not_now.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/spf13/cobra"
|
|
10
|
-
)
|
|
11
|
-
|
|
12
|
-
var cardNotNowCmd = &cobra.Command{
|
|
13
|
-
Use: "not-now <card_number>",
|
|
14
|
-
Short: "Move a card to Not Now status",
|
|
15
|
-
Long: `Move an existing card to the "Not Now" status`,
|
|
16
|
-
Args: cobra.ExactArgs(1),
|
|
17
|
-
Run: func(cmd *cobra.Command, args []string) {
|
|
18
|
-
if err := handleNotNowCard(cmd, args[0]); err != nil {
|
|
19
|
-
fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
func handleNotNowCard(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.PostCardNotNow(context.Background(), cardNum)
|
|
36
|
-
if err != nil {
|
|
37
|
-
return fmt.Errorf("moving card to not now: %w", err)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
fmt.Fprintf(cmd.OutOrStdout(), "✓ Card #%d moved to Not Now successfully\n", cardNum)
|
|
41
|
-
return nil
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
func init() {
|
|
45
|
-
cardCmd.AddCommand(cardNotNowCmd)
|
|
46
|
-
}
|
package/cmd/card_not_now_test.go
DELETED
|
@@ -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 TestCardNotNowCommandSuccess(t *testing.T) {
|
|
14
|
-
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
15
|
-
if r.URL.Path != "/cards/123/not_now" {
|
|
16
|
-
t.Errorf("expected /cards/123/not_now, got %s", r.URL.Path)
|
|
17
|
-
}
|
|
18
|
-
if r.Method != http.MethodPost {
|
|
19
|
-
t.Errorf("expected POST, 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 := cardNotNowCmd
|
|
35
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
36
|
-
|
|
37
|
-
if err := handleNotNowCard(cmd, "123"); err != nil {
|
|
38
|
-
t.Fatalf("handleNotNowCard failed: %v", err)
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
func TestCardNotNowCommandInvalidCardNumber(t *testing.T) {
|
|
43
|
-
testApp := &app.App{}
|
|
44
|
-
|
|
45
|
-
cmd := cardNotNowCmd
|
|
46
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
47
|
-
|
|
48
|
-
err := handleNotNowCard(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 TestCardNotNowCommandNoClient(t *testing.T) {
|
|
58
|
-
testApp := &app.App{}
|
|
59
|
-
|
|
60
|
-
cmd := cardNotNowCmd
|
|
61
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
62
|
-
|
|
63
|
-
err := handleNotNowCard(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 TestCardNotNowCommandAPIError(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 := cardNotNowCmd
|
|
83
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
84
|
-
|
|
85
|
-
err := handleNotNowCard(cmd, "123")
|
|
86
|
-
if err == nil {
|
|
87
|
-
t.Errorf("expected error for API failure")
|
|
88
|
-
}
|
|
89
|
-
if err.Error() != "moving card to not now: unexpected status code 500: Internal Server Error" {
|
|
90
|
-
t.Errorf("expected API error, got %v", err)
|
|
91
|
-
}
|
|
92
|
-
}
|
package/cmd/card_reopen.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/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
|
-
}
|
package/cmd/card_reopen_test.go
DELETED
|
@@ -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
|
-
}
|
package/cmd/card_show_test.go
DELETED
|
@@ -1,92 +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 TestCardShowCommand(t *testing.T) {
|
|
16
|
-
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
17
|
-
if r.URL.Path != "/cards/1" {
|
|
18
|
-
t.Errorf("expected /cards/1, 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.Card{
|
|
31
|
-
ID: "card-123",
|
|
32
|
-
Number: 1,
|
|
33
|
-
Title: "Implement feature",
|
|
34
|
-
Status: "in_progress",
|
|
35
|
-
Description: "This is a test card",
|
|
36
|
-
Tags: []string{"feature", "backend"},
|
|
37
|
-
Golden: false,
|
|
38
|
-
CreatedAt: "2025-01-01T00:00:00Z",
|
|
39
|
-
LastActiveAt: "2025-01-15T10:30:00Z",
|
|
40
|
-
URL: "https://example.com/card/1",
|
|
41
|
-
}
|
|
42
|
-
json.NewEncoder(w).Encode(response)
|
|
43
|
-
}))
|
|
44
|
-
defer server.Close()
|
|
45
|
-
|
|
46
|
-
client := testutil.NewTestClient(server.URL, "", "", "test-token")
|
|
47
|
-
testApp := &app.App{Client: client}
|
|
48
|
-
|
|
49
|
-
cmd := cardShowCmd
|
|
50
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
51
|
-
|
|
52
|
-
if err := handleShowCard(cmd, "1"); err != nil {
|
|
53
|
-
t.Fatalf("handleShowCard failed: %v", err)
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
func TestCardShowCommandAPIError(t *testing.T) {
|
|
58
|
-
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
59
|
-
w.WriteHeader(http.StatusNotFound)
|
|
60
|
-
w.Write([]byte("Card not found"))
|
|
61
|
-
}))
|
|
62
|
-
defer server.Close()
|
|
63
|
-
|
|
64
|
-
client := testutil.NewTestClient(server.URL, "", "", "test-token")
|
|
65
|
-
testApp := &app.App{Client: client}
|
|
66
|
-
|
|
67
|
-
cmd := cardShowCmd
|
|
68
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
69
|
-
|
|
70
|
-
err := handleShowCard(cmd, "999")
|
|
71
|
-
if err == nil {
|
|
72
|
-
t.Errorf("expected error for API failure")
|
|
73
|
-
}
|
|
74
|
-
if err.Error() != "fetching card: unexpected status code 404: Card not found" {
|
|
75
|
-
t.Errorf("expected API error, got %v", err)
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
func TestCardShowCommandNoClient(t *testing.T) {
|
|
80
|
-
testApp := &app.App{}
|
|
81
|
-
|
|
82
|
-
cmd := cardShowCmd
|
|
83
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
84
|
-
|
|
85
|
-
err := handleShowCard(cmd, "1")
|
|
86
|
-
if err == nil {
|
|
87
|
-
t.Errorf("expected error when client not available")
|
|
88
|
-
}
|
|
89
|
-
if err.Error() != "API client not available" {
|
|
90
|
-
t.Errorf("expected 'client not available' error, got %v", err)
|
|
91
|
-
}
|
|
92
|
-
}
|
package/cmd/card_tag.go
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
package cmd
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
"context"
|
|
5
|
-
"fmt"
|
|
6
|
-
"strconv"
|
|
7
|
-
"strings"
|
|
8
|
-
|
|
9
|
-
"github.com/rogeriopvl/fizzy/internal/app"
|
|
10
|
-
"github.com/spf13/cobra"
|
|
11
|
-
)
|
|
12
|
-
|
|
13
|
-
var cardTagCmd = &cobra.Command{
|
|
14
|
-
Use: "tag <card_number> <tag_title>",
|
|
15
|
-
Short: "Toggle a tag on or off for a card",
|
|
16
|
-
Long: `Toggle a tag on or off for a card. If the tag doesn't exist, it will be created.
|
|
17
|
-
|
|
18
|
-
The tag title can be specified with or without a leading # symbol.`,
|
|
19
|
-
Args: cobra.ExactArgs(2),
|
|
20
|
-
Run: func(cmd *cobra.Command, args []string) {
|
|
21
|
-
if err := handleTagCard(cmd, args[0], args[1]); err != nil {
|
|
22
|
-
fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
func handleTagCard(cmd *cobra.Command, cardNumber, tagTitle string) error {
|
|
28
|
-
cardNum, err := strconv.Atoi(cardNumber)
|
|
29
|
-
if err != nil {
|
|
30
|
-
return fmt.Errorf("invalid card number: %w", err)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
a := app.FromContext(cmd.Context())
|
|
34
|
-
if a == nil || a.Client == nil {
|
|
35
|
-
return fmt.Errorf("API client not available")
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
tagTitle = strings.TrimPrefix(tagTitle, "#")
|
|
39
|
-
|
|
40
|
-
_, err = a.Client.PostCardTagging(context.Background(), cardNum, tagTitle)
|
|
41
|
-
if err != nil {
|
|
42
|
-
return fmt.Errorf("toggling tag on card: %w", err)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
fmt.Fprintf(cmd.OutOrStdout(), "✓ Tag '%s' toggled on card #%d\n", tagTitle, cardNum)
|
|
46
|
-
return nil
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
func init() {
|
|
50
|
-
cardCmd.AddCommand(cardTagCmd)
|
|
51
|
-
}
|