fizzy-cli 0.1.0 → 0.2.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/.github/workflows/release.yml +29 -0
- package/.github/workflows/tests.yml +24 -0
- package/AGENTS.md +33 -0
- package/CHANGELOG.md +63 -0
- package/Makefile +20 -9
- package/README.md +88 -1
- package/bin/fizzy +0 -0
- package/bin/fizzy-darwin-amd64 +0 -0
- package/bin/fizzy-darwin-arm64 +0 -0
- package/bin/fizzy-linux-amd64 +0 -0
- package/bin/fizzy-linux-arm64 +0 -0
- package/bin/fizzy-windows-amd64.exe +0 -0
- package/cmd/account.go +14 -0
- package/cmd/account_list.go +44 -0
- package/cmd/account_list_test.go +118 -0
- package/cmd/board.go +38 -12
- package/cmd/board_create.go +60 -0
- package/cmd/board_create_test.go +158 -0
- package/cmd/board_list.go +18 -32
- package/cmd/board_list_test.go +115 -0
- package/cmd/board_test.go +92 -0
- package/cmd/card.go +24 -0
- package/cmd/card_close.go +46 -0
- package/cmd/card_close_test.go +92 -0
- package/cmd/card_create.go +73 -0
- package/cmd/card_create_test.go +206 -0
- package/cmd/card_delete.go +46 -0
- package/cmd/card_delete_test.go +92 -0
- package/cmd/card_list.go +53 -0
- package/cmd/card_list_test.go +148 -0
- package/cmd/card_reopen.go +46 -0
- package/cmd/card_reopen_test.go +92 -0
- package/cmd/card_show.go +46 -0
- package/cmd/card_show_test.go +92 -0
- package/cmd/card_update.go +74 -0
- package/cmd/card_update_test.go +147 -0
- package/cmd/column.go +14 -0
- package/cmd/column_create.go +80 -0
- package/cmd/column_create_test.go +196 -0
- package/cmd/column_list.go +44 -0
- package/cmd/column_list_test.go +138 -0
- package/cmd/login.go +61 -4
- package/cmd/login_test.go +98 -0
- package/cmd/root.go +15 -4
- package/cmd/use.go +85 -0
- package/cmd/use_test.go +186 -0
- package/docs/API.md +1168 -0
- package/go.mod +23 -2
- package/go.sum +43 -0
- package/internal/api/client.go +463 -0
- package/internal/app/app.go +49 -0
- package/internal/colors/colors.go +32 -0
- package/internal/config/config.go +69 -0
- package/internal/testutil/client.go +26 -0
- package/internal/ui/account_list.go +14 -0
- package/internal/ui/account_selector.go +63 -0
- package/internal/ui/board_list.go +14 -0
- package/internal/ui/card_list.go +14 -0
- package/internal/ui/card_show.go +23 -0
- package/internal/ui/column_list.go +28 -0
- package/internal/ui/format.go +14 -0
- package/main.go +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,206 @@
|
|
|
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/config"
|
|
14
|
+
"github.com/rogeriopvl/fizzy/internal/testutil"
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
func TestCardCreateCommandSuccess(t *testing.T) {
|
|
18
|
+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
19
|
+
if r.URL.Path != "/boards/board-123/cards" {
|
|
20
|
+
t.Errorf("expected /boards/board-123/cards, got %s", r.URL.Path)
|
|
21
|
+
}
|
|
22
|
+
if r.Method != http.MethodPost {
|
|
23
|
+
t.Errorf("expected POST, got %s", r.Method)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
auth := r.Header.Get("Authorization")
|
|
27
|
+
if auth != "Bearer test-token" {
|
|
28
|
+
t.Errorf("expected Bearer test-token, got %s", auth)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if r.Header.Get("Content-Type") != "application/json" {
|
|
32
|
+
t.Errorf("expected Content-Type: application/json, got %s", r.Header.Get("Content-Type"))
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
body, _ := io.ReadAll(r.Body)
|
|
36
|
+
var payload map[string]api.CreateCardPayload
|
|
37
|
+
if err := json.Unmarshal(body, &payload); err != nil {
|
|
38
|
+
t.Fatalf("failed to unmarshal request body: %v", err)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
cardPayload := payload["card"]
|
|
42
|
+
if cardPayload.Title != "Implement feature" {
|
|
43
|
+
t.Errorf("expected title 'Implement feature', got %s", cardPayload.Title)
|
|
44
|
+
}
|
|
45
|
+
if cardPayload.Description != "A detailed description" {
|
|
46
|
+
t.Errorf("expected description 'A detailed description', got %s", cardPayload.Description)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
w.WriteHeader(http.StatusCreated)
|
|
50
|
+
}))
|
|
51
|
+
defer server.Close()
|
|
52
|
+
|
|
53
|
+
client := testutil.NewTestClient(server.URL, "", "board-123", "test-token")
|
|
54
|
+
testApp := &app.App{
|
|
55
|
+
Client: client,
|
|
56
|
+
Config: &config.Config{SelectedBoard: "board-123"},
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
cmd := cardCreateCmd
|
|
60
|
+
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
61
|
+
|
|
62
|
+
cardTitle = "Implement feature"
|
|
63
|
+
cardDescription = "A detailed description"
|
|
64
|
+
cardStatus = ""
|
|
65
|
+
cardImageURL = ""
|
|
66
|
+
cardTagIDs = []string{}
|
|
67
|
+
cardCreatedAt = ""
|
|
68
|
+
cardLastActiveAt = ""
|
|
69
|
+
|
|
70
|
+
if err := handleCreateCard(cmd); err != nil {
|
|
71
|
+
t.Fatalf("handleCreateCard failed: %v", err)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
func TestCardCreateCommandWithAllFields(t *testing.T) {
|
|
76
|
+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
77
|
+
if r.Method != http.MethodPost {
|
|
78
|
+
t.Errorf("expected POST, got %s", r.Method)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
body, _ := io.ReadAll(r.Body)
|
|
82
|
+
var payload map[string]api.CreateCardPayload
|
|
83
|
+
json.Unmarshal(body, &payload)
|
|
84
|
+
|
|
85
|
+
cardPayload := payload["card"]
|
|
86
|
+
if cardPayload.Title != "Fix bug" {
|
|
87
|
+
t.Errorf("expected title 'Fix bug', got %s", cardPayload.Title)
|
|
88
|
+
}
|
|
89
|
+
if cardPayload.Status != "in_progress" {
|
|
90
|
+
t.Errorf("expected status 'in_progress', got %s", cardPayload.Status)
|
|
91
|
+
}
|
|
92
|
+
if cardPayload.ImageURL != "https://example.com/image.jpg" {
|
|
93
|
+
t.Errorf("expected image URL 'https://example.com/image.jpg', got %s", cardPayload.ImageURL)
|
|
94
|
+
}
|
|
95
|
+
if len(cardPayload.TagIDS) != 2 || cardPayload.TagIDS[0] != "tag-1" || cardPayload.TagIDS[1] != "tag-2" {
|
|
96
|
+
t.Errorf("expected tag IDs [tag-1, tag-2], got %v", cardPayload.TagIDS)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
w.WriteHeader(http.StatusCreated)
|
|
100
|
+
}))
|
|
101
|
+
defer server.Close()
|
|
102
|
+
|
|
103
|
+
client := testutil.NewTestClient(server.URL, "", "board-123", "test-token")
|
|
104
|
+
testApp := &app.App{
|
|
105
|
+
Client: client,
|
|
106
|
+
Config: &config.Config{SelectedBoard: "board-123"},
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
cmd := cardCreateCmd
|
|
110
|
+
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
111
|
+
|
|
112
|
+
cardTitle = "Fix bug"
|
|
113
|
+
cardDescription = ""
|
|
114
|
+
cardStatus = "in_progress"
|
|
115
|
+
cardImageURL = "https://example.com/image.jpg"
|
|
116
|
+
cardTagIDs = []string{"tag-1", "tag-2"}
|
|
117
|
+
cardCreatedAt = ""
|
|
118
|
+
cardLastActiveAt = ""
|
|
119
|
+
|
|
120
|
+
if err := handleCreateCard(cmd); err != nil {
|
|
121
|
+
t.Fatalf("handleCreateCard failed: %v", err)
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
func TestCardCreateCommandNoBoard(t *testing.T) {
|
|
126
|
+
client := testutil.NewTestClient("http://localhost", "", "", "test-token")
|
|
127
|
+
testApp := &app.App{
|
|
128
|
+
Client: client,
|
|
129
|
+
Config: &config.Config{SelectedBoard: ""},
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
cmd := cardCreateCmd
|
|
133
|
+
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
134
|
+
|
|
135
|
+
cardTitle = "Test"
|
|
136
|
+
cardDescription = ""
|
|
137
|
+
cardStatus = ""
|
|
138
|
+
cardImageURL = ""
|
|
139
|
+
cardTagIDs = []string{}
|
|
140
|
+
cardCreatedAt = ""
|
|
141
|
+
cardLastActiveAt = ""
|
|
142
|
+
|
|
143
|
+
err := handleCreateCard(cmd)
|
|
144
|
+
if err == nil {
|
|
145
|
+
t.Errorf("expected error when board not selected")
|
|
146
|
+
}
|
|
147
|
+
if err.Error() != "no board selected" {
|
|
148
|
+
t.Errorf("expected 'no board selected' error, got %v", err)
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
func TestCardCreateCommandNoClient(t *testing.T) {
|
|
153
|
+
testApp := &app.App{}
|
|
154
|
+
|
|
155
|
+
cmd := cardCreateCmd
|
|
156
|
+
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
157
|
+
|
|
158
|
+
cardTitle = "Test"
|
|
159
|
+
cardDescription = ""
|
|
160
|
+
cardStatus = ""
|
|
161
|
+
cardImageURL = ""
|
|
162
|
+
cardTagIDs = []string{}
|
|
163
|
+
cardCreatedAt = ""
|
|
164
|
+
cardLastActiveAt = ""
|
|
165
|
+
|
|
166
|
+
err := handleCreateCard(cmd)
|
|
167
|
+
if err == nil {
|
|
168
|
+
t.Errorf("expected error when client not available")
|
|
169
|
+
}
|
|
170
|
+
if err.Error() != "API client not available" {
|
|
171
|
+
t.Errorf("expected 'client not available' error, got %v", err)
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
func TestCardCreateCommandAPIError(t *testing.T) {
|
|
176
|
+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
177
|
+
w.WriteHeader(http.StatusInternalServerError)
|
|
178
|
+
w.Write([]byte("Internal Server Error"))
|
|
179
|
+
}))
|
|
180
|
+
defer server.Close()
|
|
181
|
+
|
|
182
|
+
client := testutil.NewTestClient(server.URL, "", "board-123", "test-token")
|
|
183
|
+
testApp := &app.App{
|
|
184
|
+
Client: client,
|
|
185
|
+
Config: &config.Config{SelectedBoard: "board-123"},
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
cmd := cardCreateCmd
|
|
189
|
+
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
190
|
+
|
|
191
|
+
cardTitle = "Test"
|
|
192
|
+
cardDescription = ""
|
|
193
|
+
cardStatus = ""
|
|
194
|
+
cardImageURL = ""
|
|
195
|
+
cardTagIDs = []string{}
|
|
196
|
+
cardCreatedAt = ""
|
|
197
|
+
cardLastActiveAt = ""
|
|
198
|
+
|
|
199
|
+
err := handleCreateCard(cmd)
|
|
200
|
+
if err == nil {
|
|
201
|
+
t.Errorf("expected error for API failure")
|
|
202
|
+
}
|
|
203
|
+
if err.Error() != "creating card: unexpected status code 500: Internal Server Error" {
|
|
204
|
+
t.Errorf("expected API error, got %v", err)
|
|
205
|
+
}
|
|
206
|
+
}
|
|
@@ -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 cardDeleteCmd = &cobra.Command{
|
|
13
|
+
Use: "delete <card_number>",
|
|
14
|
+
Short: "Delete a card",
|
|
15
|
+
Long: `Delete an existing card permanently`,
|
|
16
|
+
Args: cobra.ExactArgs(1),
|
|
17
|
+
Run: func(cmd *cobra.Command, args []string) {
|
|
18
|
+
if err := handleDeleteCard(cmd, args[0]); err != nil {
|
|
19
|
+
fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
func handleDeleteCard(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.DeleteCard(context.Background(), cardNum)
|
|
36
|
+
if err != nil {
|
|
37
|
+
return fmt.Errorf("deleting card: %w", err)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
fmt.Printf("✓ Card #%d deleted successfully\n", cardNum)
|
|
41
|
+
return nil
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
func init() {
|
|
45
|
+
cardCmd.AddCommand(cardDeleteCmd)
|
|
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 TestCardDeleteCommand(t *testing.T) {
|
|
14
|
+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
15
|
+
if r.URL.Path != "/cards/1" {
|
|
16
|
+
t.Errorf("expected /cards/1, 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 := cardDeleteCmd
|
|
35
|
+
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
36
|
+
|
|
37
|
+
if err := handleDeleteCard(cmd, "1"); err != nil {
|
|
38
|
+
t.Fatalf("handleDeleteCard failed: %v", err)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
func TestCardDeleteCommandAPIError(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("Card not found"))
|
|
46
|
+
}))
|
|
47
|
+
defer server.Close()
|
|
48
|
+
|
|
49
|
+
client := testutil.NewTestClient(server.URL, "", "", "test-token")
|
|
50
|
+
testApp := &app.App{Client: client}
|
|
51
|
+
|
|
52
|
+
cmd := cardDeleteCmd
|
|
53
|
+
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
54
|
+
|
|
55
|
+
err := handleDeleteCard(cmd, "999")
|
|
56
|
+
if err == nil {
|
|
57
|
+
t.Errorf("expected error for API failure")
|
|
58
|
+
}
|
|
59
|
+
if err.Error() != "deleting card: unexpected status code 404: Card not found" {
|
|
60
|
+
t.Errorf("expected API error, got %v", err)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
func TestCardDeleteCommandNoClient(t *testing.T) {
|
|
65
|
+
testApp := &app.App{}
|
|
66
|
+
|
|
67
|
+
cmd := cardDeleteCmd
|
|
68
|
+
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
69
|
+
|
|
70
|
+
err := handleDeleteCard(cmd, "1")
|
|
71
|
+
if err == nil {
|
|
72
|
+
t.Errorf("expected error when client not available")
|
|
73
|
+
}
|
|
74
|
+
if err.Error() != "API client not available" {
|
|
75
|
+
t.Errorf("expected 'client not available' error, got %v", err)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
func TestCardDeleteCommandInvalidCardNumber(t *testing.T) {
|
|
80
|
+
testApp := &app.App{}
|
|
81
|
+
|
|
82
|
+
cmd := cardDeleteCmd
|
|
83
|
+
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
84
|
+
|
|
85
|
+
err := handleDeleteCard(cmd, "not-a-number")
|
|
86
|
+
if err == nil {
|
|
87
|
+
t.Errorf("expected error for invalid card number")
|
|
88
|
+
}
|
|
89
|
+
if err.Error() != "invalid card number: strconv.Atoi: parsing \"not-a-number\": invalid syntax" {
|
|
90
|
+
t.Errorf("expected invalid card number error, got %v", err)
|
|
91
|
+
}
|
|
92
|
+
}
|
package/cmd/card_list.go
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
package cmd
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"context"
|
|
5
|
+
"fmt"
|
|
6
|
+
|
|
7
|
+
"github.com/rogeriopvl/fizzy/internal/api"
|
|
8
|
+
"github.com/rogeriopvl/fizzy/internal/app"
|
|
9
|
+
"github.com/rogeriopvl/fizzy/internal/ui"
|
|
10
|
+
"github.com/spf13/cobra"
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
var cardListCmd = &cobra.Command{
|
|
14
|
+
Use: "list",
|
|
15
|
+
Short: "List all cards",
|
|
16
|
+
Long: `Retrieve and display all cards from Fizzy`,
|
|
17
|
+
Run: func(cmd *cobra.Command, args []string) {
|
|
18
|
+
if err := handleListCards(cmd); err != nil {
|
|
19
|
+
fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
func handleListCards(cmd *cobra.Command) 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
|
+
if a.Config.SelectedBoard == "" {
|
|
31
|
+
return fmt.Errorf("no board selected")
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
filters := api.CardFilters{
|
|
35
|
+
BoardIDs: []string{a.Config.SelectedBoard},
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
cards, err := a.Client.GetCards(context.Background(), filters)
|
|
39
|
+
if err != nil {
|
|
40
|
+
return fmt.Errorf("fetching cards: %w", err)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if len(cards) == 0 {
|
|
44
|
+
fmt.Println("No cards found")
|
|
45
|
+
return nil
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return ui.DisplayCards(cards)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
func init() {
|
|
52
|
+
cardCmd.AddCommand(cardListCmd)
|
|
53
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
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
|
+
}
|
|
@@ -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 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.Printf("✓ Card #%d reopened successfully\n", cardNum)
|
|
41
|
+
return nil
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
func init() {
|
|
45
|
+
cardCmd.AddCommand(cardReopenCmd)
|
|
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 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
|
+
}
|