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.
Files changed (137) hide show
  1. package/docs/API.md +63 -2
  2. package/package.json +2 -1
  3. package/.github/workflows/release.yml +0 -29
  4. package/.github/workflows/tests.yml +0 -24
  5. package/AGENTS.md +0 -33
  6. package/CHANGELOG.md +0 -168
  7. package/Makefile +0 -43
  8. package/bin/fizzy +0 -0
  9. package/cmd/account.go +0 -14
  10. package/cmd/account_list.go +0 -44
  11. package/cmd/account_list_test.go +0 -118
  12. package/cmd/board.go +0 -49
  13. package/cmd/board_create.go +0 -59
  14. package/cmd/board_create_test.go +0 -141
  15. package/cmd/board_delete.go +0 -40
  16. package/cmd/board_delete_test.go +0 -121
  17. package/cmd/board_list.go +0 -44
  18. package/cmd/board_list_test.go +0 -115
  19. package/cmd/board_show.go +0 -40
  20. package/cmd/board_show_test.go +0 -113
  21. package/cmd/board_test.go +0 -92
  22. package/cmd/board_update.go +0 -72
  23. package/cmd/board_update_test.go +0 -233
  24. package/cmd/card.go +0 -24
  25. package/cmd/card_assign.go +0 -55
  26. package/cmd/card_assign_test.go +0 -130
  27. package/cmd/card_close.go +0 -46
  28. package/cmd/card_close_test.go +0 -92
  29. package/cmd/card_create.go +0 -72
  30. package/cmd/card_create_test.go +0 -186
  31. package/cmd/card_delete.go +0 -46
  32. package/cmd/card_delete_test.go +0 -92
  33. package/cmd/card_golden.go +0 -46
  34. package/cmd/card_golden_test.go +0 -92
  35. package/cmd/card_list.go +0 -53
  36. package/cmd/card_list_test.go +0 -148
  37. package/cmd/card_not_now.go +0 -46
  38. package/cmd/card_not_now_test.go +0 -92
  39. package/cmd/card_reopen.go +0 -46
  40. package/cmd/card_reopen_test.go +0 -92
  41. package/cmd/card_show.go +0 -46
  42. package/cmd/card_show_test.go +0 -92
  43. package/cmd/card_tag.go +0 -51
  44. package/cmd/card_tag_test.go +0 -112
  45. package/cmd/card_triage.go +0 -46
  46. package/cmd/card_ungolden.go +0 -46
  47. package/cmd/card_ungolden_test.go +0 -92
  48. package/cmd/card_untriage.go +0 -46
  49. package/cmd/card_untriage_test.go +0 -92
  50. package/cmd/card_unwatch.go +0 -46
  51. package/cmd/card_unwatch_test.go +0 -92
  52. package/cmd/card_update.go +0 -82
  53. package/cmd/card_update_test.go +0 -149
  54. package/cmd/card_watch.go +0 -46
  55. package/cmd/card_watch_test.go +0 -92
  56. package/cmd/column.go +0 -14
  57. package/cmd/column_create.go +0 -79
  58. package/cmd/column_create_test.go +0 -178
  59. package/cmd/column_delete.go +0 -40
  60. package/cmd/column_delete_test.go +0 -121
  61. package/cmd/column_list.go +0 -44
  62. package/cmd/column_list_test.go +0 -138
  63. package/cmd/column_show.go +0 -40
  64. package/cmd/column_show_test.go +0 -111
  65. package/cmd/column_update.go +0 -67
  66. package/cmd/column_update_test.go +0 -198
  67. package/cmd/comment.go +0 -14
  68. package/cmd/comment_create.go +0 -51
  69. package/cmd/comment_create_test.go +0 -129
  70. package/cmd/comment_delete.go +0 -46
  71. package/cmd/comment_delete_test.go +0 -92
  72. package/cmd/comment_list.go +0 -51
  73. package/cmd/comment_list_test.go +0 -132
  74. package/cmd/comment_show.go +0 -46
  75. package/cmd/comment_show_test.go +0 -104
  76. package/cmd/comment_update.go +0 -51
  77. package/cmd/comment_update_test.go +0 -130
  78. package/cmd/login.go +0 -81
  79. package/cmd/login_test.go +0 -98
  80. package/cmd/notification.go +0 -14
  81. package/cmd/notification_list.go +0 -69
  82. package/cmd/notification_list_test.go +0 -288
  83. package/cmd/notification_read.go +0 -51
  84. package/cmd/notification_read_all.go +0 -38
  85. package/cmd/notification_read_all_test.go +0 -75
  86. package/cmd/notification_read_test.go +0 -138
  87. package/cmd/notification_unread.go +0 -44
  88. package/cmd/notification_unread_test.go +0 -99
  89. package/cmd/reaction.go +0 -13
  90. package/cmd/reaction_create.go +0 -46
  91. package/cmd/reaction_create_test.go +0 -113
  92. package/cmd/reaction_delete.go +0 -46
  93. package/cmd/reaction_delete_test.go +0 -92
  94. package/cmd/reaction_list.go +0 -51
  95. package/cmd/reaction_list_test.go +0 -125
  96. package/cmd/root.go +0 -38
  97. package/cmd/step.go +0 -14
  98. package/cmd/step_create.go +0 -53
  99. package/cmd/step_create_test.go +0 -171
  100. package/cmd/step_delete.go +0 -46
  101. package/cmd/step_delete_test.go +0 -92
  102. package/cmd/step_update.go +0 -66
  103. package/cmd/step_update_test.go +0 -190
  104. package/cmd/tag.go +0 -15
  105. package/cmd/tag_list.go +0 -47
  106. package/cmd/tag_list_test.go +0 -109
  107. package/cmd/use.go +0 -85
  108. package/cmd/use_test.go +0 -186
  109. package/go.mod +0 -31
  110. package/go.sum +0 -53
  111. package/internal/api/boards.go +0 -93
  112. package/internal/api/cards.go +0 -288
  113. package/internal/api/client.go +0 -99
  114. package/internal/api/columns.go +0 -113
  115. package/internal/api/comments.go +0 -108
  116. package/internal/api/identity.go +0 -24
  117. package/internal/api/notifications.go +0 -89
  118. package/internal/api/reactions.go +0 -69
  119. package/internal/api/steps.go +0 -101
  120. package/internal/api/tags.go +0 -24
  121. package/internal/api/types.go +0 -190
  122. package/internal/app/app.go +0 -49
  123. package/internal/colors/colors.go +0 -32
  124. package/internal/config/config.go +0 -70
  125. package/internal/testutil/client.go +0 -26
  126. package/internal/ui/account_list.go +0 -14
  127. package/internal/ui/account_selector.go +0 -63
  128. package/internal/ui/board_list.go +0 -14
  129. package/internal/ui/board_show.go +0 -17
  130. package/internal/ui/card_list.go +0 -14
  131. package/internal/ui/card_show.go +0 -23
  132. package/internal/ui/column_list.go +0 -28
  133. package/internal/ui/column_show.go +0 -16
  134. package/internal/ui/comment_list.go +0 -25
  135. package/internal/ui/format.go +0 -27
  136. package/internal/ui/notification_list.go +0 -27
  137. package/internal/ui/reaction_list.go +0 -14
@@ -1,112 +0,0 @@
1
- package cmd
2
-
3
- import (
4
- "context"
5
- "net/http"
6
- "net/http/httptest"
7
- "testing"
8
-
9
- "github.com/rogeriopvl/fizzy/internal/app"
10
- "github.com/rogeriopvl/fizzy/internal/testutil"
11
- )
12
-
13
- func 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
- }
@@ -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 cardTriageCmd = &cobra.Command{
13
- Use: "triage <card_number> <column_id>",
14
- Short: "Move a card from triage into a column",
15
- Long: `Move a card from triage into a specified column`,
16
- Args: cobra.ExactArgs(2),
17
- Run: func(cmd *cobra.Command, args []string) {
18
- if err := handleTriageCard(cmd, args[0], args[1]); err != nil {
19
- fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
20
- }
21
- },
22
- }
23
-
24
- func handleTriageCard(cmd *cobra.Command, cardNumber string, columnID 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.PostCardTriage(context.Background(), cardNum, columnID)
36
- if err != nil {
37
- return fmt.Errorf("triaging card: %w", err)
38
- }
39
-
40
- fmt.Fprintf(cmd.OutOrStdout(), "✓ Card #%d moved to column successfully\n", cardNum)
41
- return nil
42
- }
43
-
44
- func init() {
45
- cardCmd.AddCommand(cardTriageCmd)
46
- }
@@ -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 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.Fprintf(cmd.OutOrStdout(), "✓ Card #%d golden status removed\n", cardNum)
41
- return nil
42
- }
43
-
44
- func init() {
45
- cardCmd.AddCommand(cardUngoldenCmd)
46
- }
@@ -1,92 +0,0 @@
1
- package cmd
2
-
3
- import (
4
- "context"
5
- "net/http"
6
- "net/http/httptest"
7
- "testing"
8
-
9
- "github.com/rogeriopvl/fizzy/internal/app"
10
- "github.com/rogeriopvl/fizzy/internal/testutil"
11
- )
12
-
13
- func 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
- }
@@ -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 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.Fprintf(cmd.OutOrStdout(), "✓ Card #%d sent back to triage successfully\n", cardNum)
41
- return nil
42
- }
43
-
44
- func init() {
45
- cardCmd.AddCommand(cardUntriagedCmd)
46
- }
@@ -1,92 +0,0 @@
1
- package cmd
2
-
3
- import (
4
- "context"
5
- "net/http"
6
- "net/http/httptest"
7
- "testing"
8
-
9
- "github.com/rogeriopvl/fizzy/internal/app"
10
- "github.com/rogeriopvl/fizzy/internal/testutil"
11
- )
12
-
13
- func 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
- }
@@ -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 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.Fprintf(cmd.OutOrStdout(), "✓ Stopped watching card #%d\n", cardNum)
41
- return nil
42
- }
43
-
44
- func init() {
45
- cardCmd.AddCommand(cardUnwatchCmd)
46
- }
@@ -1,92 +0,0 @@
1
- package cmd
2
-
3
- import (
4
- "context"
5
- "net/http"
6
- "net/http/httptest"
7
- "testing"
8
-
9
- "github.com/rogeriopvl/fizzy/internal/app"
10
- "github.com/rogeriopvl/fizzy/internal/testutil"
11
- )
12
-
13
- func 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
- }
@@ -1,82 +0,0 @@
1
- package cmd
2
-
3
- import (
4
- "context"
5
- "fmt"
6
- "strconv"
7
-
8
- "github.com/rogeriopvl/fizzy/internal/api"
9
- "github.com/rogeriopvl/fizzy/internal/app"
10
- "github.com/spf13/cobra"
11
- )
12
-
13
- var cardUpdateCmd = &cobra.Command{
14
- Use: "update <card_number>",
15
- Short: "Update a card",
16
- Long: `Update an existing card's details`,
17
- Args: cobra.ExactArgs(1),
18
- Run: func(cmd *cobra.Command, args []string) {
19
- if err := handleUpdateCard(cmd, args[0]); err != nil {
20
- fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
21
- }
22
- },
23
- }
24
-
25
- func handleUpdateCard(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
- // Build payload only with flags that were explicitly set
37
- var payload api.UpdateCardPayload
38
- hasChanges := false
39
-
40
- if cmd.Flags().Changed("title") {
41
- payload.Title, _ = cmd.Flags().GetString("title")
42
- hasChanges = true
43
- }
44
- if cmd.Flags().Changed("description") {
45
- payload.Description, _ = cmd.Flags().GetString("description")
46
- hasChanges = true
47
- }
48
- if cmd.Flags().Changed("status") {
49
- payload.Status, _ = cmd.Flags().GetString("status")
50
- hasChanges = true
51
- }
52
- if cmd.Flags().Changed("tag-id") {
53
- payload.TagIDS, _ = cmd.Flags().GetStringSlice("tag-id")
54
- hasChanges = true
55
- }
56
- if cmd.Flags().Changed("last-active-at") {
57
- payload.LastActiveAt, _ = cmd.Flags().GetString("last-active-at")
58
- hasChanges = true
59
- }
60
-
61
- if !hasChanges {
62
- return fmt.Errorf("must provide at least one flag to update (--title, --description, --status, --tag-id, or --last-active-at)")
63
- }
64
-
65
- card, err := a.Client.PutCard(context.Background(), cardNum, payload)
66
- if err != nil {
67
- return fmt.Errorf("updating card: %w", err)
68
- }
69
-
70
- fmt.Fprintf(cmd.OutOrStdout(), "✓ Card #%d updated successfully\n", card.Number)
71
- return nil
72
- }
73
-
74
- func init() {
75
- cardUpdateCmd.Flags().StringP("title", "t", "", "Card title")
76
- cardUpdateCmd.Flags().StringP("description", "d", "", "Card description")
77
- cardUpdateCmd.Flags().String("status", "", "Card status")
78
- cardUpdateCmd.Flags().StringSlice("tag-id", []string{}, "Tag ID (can be used multiple times)")
79
- cardUpdateCmd.Flags().String("last-active-at", "", "Last active timestamp")
80
-
81
- cardCmd.AddCommand(cardUpdateCmd)
82
- }