fizzy-cli 0.3.0 → 0.5.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 +28 -0
- package/cmd/board_create.go +15 -16
- package/cmd/board_create_test.go +0 -17
- package/cmd/card_create.go +24 -25
- package/cmd/card_create_test.go +20 -40
- package/cmd/card_golden.go +46 -0
- package/cmd/card_golden_test.go +92 -0
- package/cmd/card_not_now.go +46 -0
- package/cmd/card_not_now_test.go +92 -0
- package/cmd/card_tag.go +51 -0
- package/cmd/card_tag_test.go +112 -0
- package/cmd/card_ungolden.go +46 -0
- package/cmd/card_ungolden_test.go +92 -0
- package/cmd/card_untriage.go +46 -0
- package/cmd/card_untriage_test.go +92 -0
- package/cmd/card_unwatch.go +46 -0
- package/cmd/card_unwatch_test.go +92 -0
- package/cmd/card_update.go +18 -19
- package/cmd/card_update_test.go +28 -24
- package/cmd/card_watch.go +46 -0
- package/cmd/card_watch_test.go +92 -0
- package/cmd/column_create.go +11 -12
- package/cmd/column_create_test.go +3 -21
- package/cmd/comment.go +14 -0
- package/cmd/comment_create.go +51 -0
- package/cmd/comment_create_test.go +129 -0
- package/cmd/comment_list.go +51 -0
- package/cmd/comment_list_test.go +132 -0
- package/cmd/comment_show.go +46 -0
- package/cmd/comment_show_test.go +104 -0
- package/cmd/tag.go +15 -0
- package/cmd/tag_list.go +47 -0
- package/cmd/tag_list_test.go +109 -0
- package/docs/API.md +36 -0
- package/internal/api/client.go +211 -1
- package/internal/ui/comment_list.go +25 -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 TestCardTagCommandSuccess(t *testing.T) {
|
|
14
|
+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
15
|
+
if r.URL.Path != "/cards/123/taggings" {
|
|
16
|
+
t.Errorf("expected /cards/123/taggings, 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 := cardTagCmd
|
|
35
|
+
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
36
|
+
|
|
37
|
+
if err := handleTagCard(cmd, "123", "bug"); err != nil {
|
|
38
|
+
t.Fatalf("handleTagCard failed: %v", err)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
func TestCardTagCommandWithHashPrefix(t *testing.T) {
|
|
43
|
+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
44
|
+
if r.URL.Path != "/cards/456/taggings" {
|
|
45
|
+
t.Errorf("expected /cards/456/taggings, got %s", r.URL.Path)
|
|
46
|
+
}
|
|
47
|
+
w.WriteHeader(http.StatusNoContent)
|
|
48
|
+
}))
|
|
49
|
+
defer server.Close()
|
|
50
|
+
|
|
51
|
+
client := testutil.NewTestClient(server.URL, "", "", "test-token")
|
|
52
|
+
testApp := &app.App{Client: client}
|
|
53
|
+
|
|
54
|
+
cmd := cardTagCmd
|
|
55
|
+
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
56
|
+
|
|
57
|
+
if err := handleTagCard(cmd, "456", "#feature"); err != nil {
|
|
58
|
+
t.Fatalf("handleTagCard with # prefix failed: %v", err)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
func TestCardTagCommandAPIError(t *testing.T) {
|
|
63
|
+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
64
|
+
w.WriteHeader(http.StatusNotFound)
|
|
65
|
+
w.Write([]byte("Card not found"))
|
|
66
|
+
}))
|
|
67
|
+
defer server.Close()
|
|
68
|
+
|
|
69
|
+
client := testutil.NewTestClient(server.URL, "", "", "test-token")
|
|
70
|
+
testApp := &app.App{Client: client}
|
|
71
|
+
|
|
72
|
+
cmd := cardTagCmd
|
|
73
|
+
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
74
|
+
|
|
75
|
+
err := handleTagCard(cmd, "999", "bug")
|
|
76
|
+
if err == nil {
|
|
77
|
+
t.Errorf("expected error for API failure")
|
|
78
|
+
}
|
|
79
|
+
if err.Error() != "toggling tag on card: unexpected status code 404: Card not found" {
|
|
80
|
+
t.Errorf("expected API error, got %v", err)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
func TestCardTagCommandInvalidCardNumber(t *testing.T) {
|
|
85
|
+
testApp := &app.App{}
|
|
86
|
+
|
|
87
|
+
cmd := cardTagCmd
|
|
88
|
+
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
89
|
+
|
|
90
|
+
err := handleTagCard(cmd, "not-a-number", "bug")
|
|
91
|
+
if err == nil {
|
|
92
|
+
t.Errorf("expected error for invalid card number")
|
|
93
|
+
}
|
|
94
|
+
if err.Error() != "invalid card number: strconv.Atoi: parsing \"not-a-number\": invalid syntax" {
|
|
95
|
+
t.Errorf("expected invalid card number error, got %v", err)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
func TestCardTagCommandNoClient(t *testing.T) {
|
|
100
|
+
testApp := &app.App{}
|
|
101
|
+
|
|
102
|
+
cmd := cardTagCmd
|
|
103
|
+
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
104
|
+
|
|
105
|
+
err := handleTagCard(cmd, "123", "bug")
|
|
106
|
+
if err == nil {
|
|
107
|
+
t.Errorf("expected error when client not available")
|
|
108
|
+
}
|
|
109
|
+
if err.Error() != "API client not available" {
|
|
110
|
+
t.Errorf("expected 'client not available' error, got %v", err)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -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 cardUngoldenCmd = &cobra.Command{
|
|
13
|
+
Use: "ungolden <card_number>",
|
|
14
|
+
Short: "Remove golden status from a card",
|
|
15
|
+
Long: `Remove golden status from an existing card`,
|
|
16
|
+
Args: cobra.ExactArgs(1),
|
|
17
|
+
Run: func(cmd *cobra.Command, args []string) {
|
|
18
|
+
if err := handleUngoldenCard(cmd, args[0]); err != nil {
|
|
19
|
+
fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
func handleUngoldenCard(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.DeleteCardGoldenness(context.Background(), cardNum)
|
|
36
|
+
if err != nil {
|
|
37
|
+
return fmt.Errorf("removing golden status: %w", err)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
fmt.Printf("✓ Card #%d golden status removed\n", cardNum)
|
|
41
|
+
return nil
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
func init() {
|
|
45
|
+
cardCmd.AddCommand(cardUngoldenCmd)
|
|
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 TestCardUngoldenCommandSuccess(t *testing.T) {
|
|
14
|
+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
15
|
+
if r.URL.Path != "/cards/123/goldness" {
|
|
16
|
+
t.Errorf("expected /cards/123/goldness, 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 := cardUngoldenCmd
|
|
35
|
+
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
36
|
+
|
|
37
|
+
if err := handleUngoldenCard(cmd, "123"); err != nil {
|
|
38
|
+
t.Fatalf("handleUngoldenCard failed: %v", err)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
func TestCardUngoldenCommandInvalidCardNumber(t *testing.T) {
|
|
43
|
+
testApp := &app.App{}
|
|
44
|
+
|
|
45
|
+
cmd := cardUngoldenCmd
|
|
46
|
+
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
47
|
+
|
|
48
|
+
err := handleUngoldenCard(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 TestCardUngoldenCommandNoClient(t *testing.T) {
|
|
58
|
+
testApp := &app.App{}
|
|
59
|
+
|
|
60
|
+
cmd := cardUngoldenCmd
|
|
61
|
+
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
62
|
+
|
|
63
|
+
err := handleUngoldenCard(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 TestCardUngoldenCommandAPIError(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 := cardUngoldenCmd
|
|
83
|
+
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
84
|
+
|
|
85
|
+
err := handleUngoldenCard(cmd, "123")
|
|
86
|
+
if err == nil {
|
|
87
|
+
t.Errorf("expected error for API failure")
|
|
88
|
+
}
|
|
89
|
+
if err.Error() != "removing golden status: unexpected status code 500: Internal Server Error" {
|
|
90
|
+
t.Errorf("expected API error, got %v", err)
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -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 cardUntriagedCmd = &cobra.Command{
|
|
13
|
+
Use: "untriage <card_number>",
|
|
14
|
+
Short: "Send a card back to triage",
|
|
15
|
+
Long: `Send an existing card back to the triage column`,
|
|
16
|
+
Args: cobra.ExactArgs(1),
|
|
17
|
+
Run: func(cmd *cobra.Command, args []string) {
|
|
18
|
+
if err := handleUntriagedCard(cmd, args[0]); err != nil {
|
|
19
|
+
fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
func handleUntriagedCard(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.DeleteCardTriage(context.Background(), cardNum)
|
|
36
|
+
if err != nil {
|
|
37
|
+
return fmt.Errorf("sending card back to triage: %w", err)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
fmt.Printf("✓ Card #%d sent back to triage successfully\n", cardNum)
|
|
41
|
+
return nil
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
func init() {
|
|
45
|
+
cardCmd.AddCommand(cardUntriagedCmd)
|
|
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 TestCardUntriagedCommandSuccess(t *testing.T) {
|
|
14
|
+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
15
|
+
if r.URL.Path != "/cards/123/triage" {
|
|
16
|
+
t.Errorf("expected /cards/123/triage, 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 := cardUntriagedCmd
|
|
35
|
+
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
36
|
+
|
|
37
|
+
if err := handleUntriagedCard(cmd, "123"); err != nil {
|
|
38
|
+
t.Fatalf("handleUntriagedCard failed: %v", err)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
func TestCardUntriagedCommandInvalidCardNumber(t *testing.T) {
|
|
43
|
+
testApp := &app.App{}
|
|
44
|
+
|
|
45
|
+
cmd := cardUntriagedCmd
|
|
46
|
+
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
47
|
+
|
|
48
|
+
err := handleUntriagedCard(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 TestCardUntriagedCommandNoClient(t *testing.T) {
|
|
58
|
+
testApp := &app.App{}
|
|
59
|
+
|
|
60
|
+
cmd := cardUntriagedCmd
|
|
61
|
+
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
62
|
+
|
|
63
|
+
err := handleUntriagedCard(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 TestCardUntriagedCommandAPIError(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 := cardUntriagedCmd
|
|
83
|
+
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
84
|
+
|
|
85
|
+
err := handleUntriagedCard(cmd, "123")
|
|
86
|
+
if err == nil {
|
|
87
|
+
t.Errorf("expected error for API failure")
|
|
88
|
+
}
|
|
89
|
+
if err.Error() != "sending card back to triage: unexpected status code 500: Internal Server Error" {
|
|
90
|
+
t.Errorf("expected API error, got %v", err)
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -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 cardUnwatchCmd = &cobra.Command{
|
|
13
|
+
Use: "unwatch <card_number>",
|
|
14
|
+
Short: "Unsubscribe from card notifications",
|
|
15
|
+
Long: `Unsubscribe from notifications for an existing card`,
|
|
16
|
+
Args: cobra.ExactArgs(1),
|
|
17
|
+
Run: func(cmd *cobra.Command, args []string) {
|
|
18
|
+
if err := handleUnwatchCard(cmd, args[0]); err != nil {
|
|
19
|
+
fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
func handleUnwatchCard(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.DeleteCardWatch(context.Background(), cardNum)
|
|
36
|
+
if err != nil {
|
|
37
|
+
return fmt.Errorf("unwatching card: %w", err)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
fmt.Printf("✓ Stopped watching card #%d\n", cardNum)
|
|
41
|
+
return nil
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
func init() {
|
|
45
|
+
cardCmd.AddCommand(cardUnwatchCmd)
|
|
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 TestCardUnwatchCommandSuccess(t *testing.T) {
|
|
14
|
+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
15
|
+
if r.URL.Path != "/cards/123/watch" {
|
|
16
|
+
t.Errorf("expected /cards/123/watch, 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 := cardUnwatchCmd
|
|
35
|
+
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
36
|
+
|
|
37
|
+
if err := handleUnwatchCard(cmd, "123"); err != nil {
|
|
38
|
+
t.Fatalf("handleUnwatchCard failed: %v", err)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
func TestCardUnwatchCommandInvalidCardNumber(t *testing.T) {
|
|
43
|
+
testApp := &app.App{}
|
|
44
|
+
|
|
45
|
+
cmd := cardUnwatchCmd
|
|
46
|
+
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
47
|
+
|
|
48
|
+
err := handleUnwatchCard(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 TestCardUnwatchCommandNoClient(t *testing.T) {
|
|
58
|
+
testApp := &app.App{}
|
|
59
|
+
|
|
60
|
+
cmd := cardUnwatchCmd
|
|
61
|
+
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
62
|
+
|
|
63
|
+
err := handleUnwatchCard(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 TestCardUnwatchCommandAPIError(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 := cardUnwatchCmd
|
|
83
|
+
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
84
|
+
|
|
85
|
+
err := handleUnwatchCard(cmd, "123")
|
|
86
|
+
if err == nil {
|
|
87
|
+
t.Errorf("expected error for API failure")
|
|
88
|
+
}
|
|
89
|
+
if err.Error() != "unwatching card: unexpected status code 500: Internal Server Error" {
|
|
90
|
+
t.Errorf("expected API error, got %v", err)
|
|
91
|
+
}
|
|
92
|
+
}
|
package/cmd/card_update.go
CHANGED
|
@@ -10,14 +10,6 @@ import (
|
|
|
10
10
|
"github.com/spf13/cobra"
|
|
11
11
|
)
|
|
12
12
|
|
|
13
|
-
var (
|
|
14
|
-
updateTitle string
|
|
15
|
-
updateDescription string
|
|
16
|
-
updateStatus string
|
|
17
|
-
updateTagIDs []string
|
|
18
|
-
updateLastActiveAt string
|
|
19
|
-
)
|
|
20
|
-
|
|
21
13
|
var cardUpdateCmd = &cobra.Command{
|
|
22
14
|
Use: "update <card_number>",
|
|
23
15
|
Short: "Update a card",
|
|
@@ -41,16 +33,23 @@ func handleUpdateCard(cmd *cobra.Command, cardNumber string) error {
|
|
|
41
33
|
return fmt.Errorf("API client not available")
|
|
42
34
|
}
|
|
43
35
|
|
|
44
|
-
|
|
36
|
+
// Read flag values directly from command
|
|
37
|
+
title, _ := cmd.Flags().GetString("title")
|
|
38
|
+
description, _ := cmd.Flags().GetString("description")
|
|
39
|
+
status, _ := cmd.Flags().GetString("status")
|
|
40
|
+
tagIDs, _ := cmd.Flags().GetStringSlice("tag-id")
|
|
41
|
+
lastActiveAt, _ := cmd.Flags().GetString("last-active-at")
|
|
42
|
+
|
|
43
|
+
if title == "" && description == "" && status == "" && len(tagIDs) == 0 && lastActiveAt == "" {
|
|
45
44
|
return fmt.Errorf("must provide at least one flag to update (--title, --description, --status, --tag-id, or --last-active-at)")
|
|
46
45
|
}
|
|
47
46
|
|
|
48
47
|
payload := api.UpdateCardPayload{
|
|
49
|
-
Title:
|
|
50
|
-
Description:
|
|
51
|
-
Status:
|
|
52
|
-
TagIDS:
|
|
53
|
-
LastActiveAt:
|
|
48
|
+
Title: title,
|
|
49
|
+
Description: description,
|
|
50
|
+
Status: status,
|
|
51
|
+
TagIDS: tagIDs,
|
|
52
|
+
LastActiveAt: lastActiveAt,
|
|
54
53
|
}
|
|
55
54
|
|
|
56
55
|
card, err := a.Client.PutCard(context.Background(), cardNum, payload)
|
|
@@ -63,11 +62,11 @@ func handleUpdateCard(cmd *cobra.Command, cardNumber string) error {
|
|
|
63
62
|
}
|
|
64
63
|
|
|
65
64
|
func init() {
|
|
66
|
-
cardUpdateCmd.Flags().
|
|
67
|
-
cardUpdateCmd.Flags().
|
|
68
|
-
cardUpdateCmd.Flags().
|
|
69
|
-
cardUpdateCmd.Flags().
|
|
70
|
-
cardUpdateCmd.Flags().
|
|
65
|
+
cardUpdateCmd.Flags().StringP("title", "t", "", "Card title")
|
|
66
|
+
cardUpdateCmd.Flags().StringP("description", "d", "", "Card description")
|
|
67
|
+
cardUpdateCmd.Flags().String("status", "", "Card status")
|
|
68
|
+
cardUpdateCmd.Flags().StringSlice("tag-id", []string{}, "Tag ID (can be used multiple times)")
|
|
69
|
+
cardUpdateCmd.Flags().String("last-active-at", "", "Last active timestamp")
|
|
71
70
|
|
|
72
71
|
cardCmd.AddCommand(cardUpdateCmd)
|
|
73
72
|
}
|
package/cmd/card_update_test.go
CHANGED
|
@@ -10,6 +10,7 @@ import (
|
|
|
10
10
|
"github.com/rogeriopvl/fizzy/internal/api"
|
|
11
11
|
"github.com/rogeriopvl/fizzy/internal/app"
|
|
12
12
|
"github.com/rogeriopvl/fizzy/internal/testutil"
|
|
13
|
+
"github.com/spf13/cobra"
|
|
13
14
|
)
|
|
14
15
|
|
|
15
16
|
func TestCardUpdateCommand(t *testing.T) {
|
|
@@ -48,11 +49,12 @@ func TestCardUpdateCommand(t *testing.T) {
|
|
|
48
49
|
|
|
49
50
|
cmd := cardUpdateCmd
|
|
50
51
|
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
cmd.ParseFlags([]string{
|
|
53
|
+
"--title", "Updated card title",
|
|
54
|
+
"--description", "Updated description",
|
|
55
|
+
"--status", "published",
|
|
56
|
+
"--tag-id", "updated-tag",
|
|
57
|
+
})
|
|
56
58
|
|
|
57
59
|
if err := handleUpdateCard(cmd, "1"); err != nil {
|
|
58
60
|
t.Fatalf("handleUpdateCard failed: %v", err)
|
|
@@ -71,8 +73,9 @@ func TestCardUpdateCommandAPIError(t *testing.T) {
|
|
|
71
73
|
|
|
72
74
|
cmd := cardUpdateCmd
|
|
73
75
|
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
74
|
-
|
|
75
|
-
|
|
76
|
+
cmd.ParseFlags([]string{
|
|
77
|
+
"--title", "Updated card",
|
|
78
|
+
})
|
|
76
79
|
|
|
77
80
|
err := handleUpdateCard(cmd, "999")
|
|
78
81
|
if err == nil {
|
|
@@ -88,8 +91,9 @@ func TestCardUpdateCommandNoClient(t *testing.T) {
|
|
|
88
91
|
|
|
89
92
|
cmd := cardUpdateCmd
|
|
90
93
|
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
91
|
-
|
|
92
|
-
|
|
94
|
+
cmd.ParseFlags([]string{
|
|
95
|
+
"--title", "Updated card",
|
|
96
|
+
})
|
|
93
97
|
|
|
94
98
|
err := handleUpdateCard(cmd, "1")
|
|
95
99
|
if err == nil {
|
|
@@ -105,8 +109,9 @@ func TestCardUpdateCommandInvalidCardNumber(t *testing.T) {
|
|
|
105
109
|
|
|
106
110
|
cmd := cardUpdateCmd
|
|
107
111
|
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
108
|
-
|
|
109
|
-
|
|
112
|
+
cmd.ParseFlags([]string{
|
|
113
|
+
"--title", "Updated card",
|
|
114
|
+
})
|
|
110
115
|
|
|
111
116
|
err := handleUpdateCard(cmd, "not-a-number")
|
|
112
117
|
if err == nil {
|
|
@@ -118,22 +123,21 @@ func TestCardUpdateCommandInvalidCardNumber(t *testing.T) {
|
|
|
118
123
|
}
|
|
119
124
|
|
|
120
125
|
func TestCardUpdateCommandNoFlags(t *testing.T) {
|
|
121
|
-
|
|
122
|
-
w.WriteHeader(http.StatusOK)
|
|
123
|
-
}))
|
|
124
|
-
defer server.Close()
|
|
125
|
-
|
|
126
|
-
client := testutil.NewTestClient(server.URL, "", "", "test-token")
|
|
126
|
+
client := testutil.NewTestClient("http://localhost", "", "", "test-token")
|
|
127
127
|
testApp := &app.App{Client: client}
|
|
128
128
|
|
|
129
|
-
|
|
130
|
-
cmd.
|
|
129
|
+
// Create a fresh command to avoid flag pollution from other tests
|
|
130
|
+
cmd := &cobra.Command{
|
|
131
|
+
Use: "update <card_number>",
|
|
132
|
+
Args: cobra.ExactArgs(1),
|
|
133
|
+
}
|
|
134
|
+
cmd.Flags().String("title", "", "Card title")
|
|
135
|
+
cmd.Flags().String("description", "", "Card description")
|
|
136
|
+
cmd.Flags().String("status", "", "Card status")
|
|
137
|
+
cmd.Flags().StringSlice("tag-id", []string{}, "Tag ID")
|
|
138
|
+
cmd.Flags().String("last-active-at", "", "Last active timestamp")
|
|
131
139
|
|
|
132
|
-
|
|
133
|
-
updateDescription = ""
|
|
134
|
-
updateStatus = ""
|
|
135
|
-
updateTagIDs = []string{}
|
|
136
|
-
updateLastActiveAt = ""
|
|
140
|
+
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
137
141
|
|
|
138
142
|
err := handleUpdateCard(cmd, "1")
|
|
139
143
|
if err == nil {
|