fizzy-cli 0.6.1 → 0.7.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 (49) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/bin/fizzy +0 -0
  3. package/cmd/board.go +1 -1
  4. package/cmd/board_create.go +1 -1
  5. package/cmd/board_delete.go +40 -0
  6. package/cmd/board_delete_test.go +121 -0
  7. package/cmd/board_show.go +40 -0
  8. package/cmd/board_show_test.go +113 -0
  9. package/cmd/board_update.go +72 -0
  10. package/cmd/board_update_test.go +233 -0
  11. package/cmd/card_assign.go +1 -1
  12. package/cmd/card_close.go +1 -1
  13. package/cmd/card_create.go +1 -1
  14. package/cmd/card_delete.go +1 -1
  15. package/cmd/card_golden.go +1 -1
  16. package/cmd/card_not_now.go +1 -1
  17. package/cmd/card_reopen.go +1 -1
  18. package/cmd/card_tag.go +1 -1
  19. package/cmd/card_triage.go +1 -1
  20. package/cmd/card_ungolden.go +1 -1
  21. package/cmd/card_untriage.go +1 -1
  22. package/cmd/card_unwatch.go +1 -1
  23. package/cmd/card_update.go +1 -1
  24. package/cmd/card_watch.go +1 -1
  25. package/cmd/column_create.go +1 -1
  26. package/cmd/column_delete.go +40 -0
  27. package/cmd/column_delete_test.go +121 -0
  28. package/cmd/column_show.go +40 -0
  29. package/cmd/column_show_test.go +111 -0
  30. package/cmd/column_update.go +67 -0
  31. package/cmd/column_update_test.go +198 -0
  32. package/cmd/comment_create.go +1 -1
  33. package/cmd/comment_delete.go +1 -1
  34. package/cmd/comment_update.go +1 -1
  35. package/cmd/login.go +12 -12
  36. package/cmd/notification_unread.go +1 -1
  37. package/cmd/reaction_create.go +1 -1
  38. package/cmd/reaction_delete.go +1 -1
  39. package/cmd/step_create.go +1 -1
  40. package/cmd/step_delete.go +1 -1
  41. package/cmd/step_update.go +1 -1
  42. package/internal/api/boards.go +34 -0
  43. package/internal/api/columns.go +63 -0
  44. package/internal/api/types.go +12 -0
  45. package/internal/ui/board_show.go +17 -0
  46. package/internal/ui/column_show.go +16 -0
  47. package/internal/ui/format.go +14 -1
  48. package/package.json +1 -1
  49. package/.env +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.7.0 - 2026-01-26
4
+
5
+ ### Features
6
+
7
+ #### Board Management
8
+
9
+ - `fizzy board show <board_id>` - Display details for a specific board
10
+ - `fizzy board update <board_id>` - Update board properties (name, access, auto-postpone period)
11
+ - `fizzy board delete <board_id>` - Delete a board
12
+
13
+ #### Column Management
14
+
15
+ - `fizzy column show <column_id>` - Display details for a specific column
16
+ - `fizzy column update <column_id>` - Update column properties (name, color)
17
+ - `fizzy column delete <column_id>` - Delete a column
18
+
19
+ ### Improvements
20
+
21
+ - Improved command output testability by using consistent output writers
22
+
3
23
  ## 0.6.1 - 2026-01-26
4
24
 
5
25
  ### Fixes
package/bin/fizzy CHANGED
Binary file
package/cmd/board.go CHANGED
@@ -40,7 +40,7 @@ func handleShowBoard(cmd *cobra.Command) error {
40
40
  return fmt.Errorf("fetching board: %w", err)
41
41
  }
42
42
 
43
- fmt.Printf("%s (%s)\n", board.Name, ui.DisplayID(board.ID))
43
+ fmt.Fprintf(cmd.OutOrStdout(), "%s (%s)\n", board.Name, ui.DisplayID(board.ID))
44
44
  return nil
45
45
  }
46
46
 
@@ -44,7 +44,7 @@ func handleCreateBoard(cmd *cobra.Command) error {
44
44
  return fmt.Errorf("creating board: %w", err)
45
45
  }
46
46
 
47
- fmt.Printf("✓ Board '%s' created successfully\n", name)
47
+ fmt.Fprintf(cmd.OutOrStdout(), "✓ Board '%s' created successfully\n", name)
48
48
  return nil
49
49
  }
50
50
 
@@ -0,0 +1,40 @@
1
+ package cmd
2
+
3
+ import (
4
+ "context"
5
+ "fmt"
6
+
7
+ "github.com/rogeriopvl/fizzy/internal/app"
8
+ "github.com/spf13/cobra"
9
+ )
10
+
11
+ var boardDeleteCmd = &cobra.Command{
12
+ Use: "delete <board_id>",
13
+ Short: "Delete a board",
14
+ Long: `Delete a board. Only board administrators can delete boards.`,
15
+ Args: cobra.ExactArgs(1),
16
+ Run: func(cmd *cobra.Command, args []string) {
17
+ if err := handleDeleteBoard(cmd, args[0]); err != nil {
18
+ fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
19
+ }
20
+ },
21
+ }
22
+
23
+ func handleDeleteBoard(cmd *cobra.Command, boardID string) error {
24
+ a := app.FromContext(cmd.Context())
25
+ if a == nil || a.Client == nil {
26
+ return fmt.Errorf("API client not available")
27
+ }
28
+
29
+ err := a.Client.DeleteBoard(context.Background(), boardID)
30
+ if err != nil {
31
+ return fmt.Errorf("deleting board: %w", err)
32
+ }
33
+
34
+ fmt.Fprintf(cmd.OutOrStdout(), "✓ Board '%s' deleted successfully\n", boardID)
35
+ return nil
36
+ }
37
+
38
+ func init() {
39
+ boardCmd.AddCommand(boardDeleteCmd)
40
+ }
@@ -0,0 +1,121 @@
1
+ package cmd
2
+
3
+ import (
4
+ "context"
5
+ "net/http"
6
+ "net/http/httptest"
7
+ "testing"
8
+
9
+ "github.com/rogeriopvl/fizzy/internal/app"
10
+ "github.com/rogeriopvl/fizzy/internal/testutil"
11
+ )
12
+
13
+ func TestBoardDeleteCommandSuccess(t *testing.T) {
14
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
15
+ if r.URL.Path != "/boards/board-123" {
16
+ t.Errorf("expected /boards/board-123, 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 := boardDeleteCmd
35
+ cmd.SetContext(testApp.ToContext(context.Background()))
36
+
37
+ if err := handleDeleteBoard(cmd, "board-123"); err != nil {
38
+ t.Fatalf("handleDeleteBoard failed: %v", err)
39
+ }
40
+ }
41
+
42
+ func TestBoardDeleteCommandNotFound(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("Board 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 := boardDeleteCmd
53
+ cmd.SetContext(testApp.ToContext(context.Background()))
54
+
55
+ err := handleDeleteBoard(cmd, "nonexistent-board")
56
+ if err == nil {
57
+ t.Errorf("expected error for board not found")
58
+ }
59
+ if err.Error() != "deleting board: unexpected status code 404: Board not found" {
60
+ t.Errorf("expected board not found error, got %v", err)
61
+ }
62
+ }
63
+
64
+ func TestBoardDeleteCommandForbidden(t *testing.T) {
65
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
66
+ w.WriteHeader(http.StatusForbidden)
67
+ w.Write([]byte("You don't have permission to delete this board"))
68
+ }))
69
+ defer server.Close()
70
+
71
+ client := testutil.NewTestClient(server.URL, "", "", "test-token")
72
+ testApp := &app.App{Client: client}
73
+
74
+ cmd := boardDeleteCmd
75
+ cmd.SetContext(testApp.ToContext(context.Background()))
76
+
77
+ err := handleDeleteBoard(cmd, "board-123")
78
+ if err == nil {
79
+ t.Errorf("expected error for forbidden access")
80
+ }
81
+ if err.Error() != "deleting board: unexpected status code 403: You don't have permission to delete this board" {
82
+ t.Errorf("expected permission error, got %v", err)
83
+ }
84
+ }
85
+
86
+ func TestBoardDeleteCommandAPIError(t *testing.T) {
87
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
88
+ w.WriteHeader(http.StatusInternalServerError)
89
+ w.Write([]byte("Internal Server Error"))
90
+ }))
91
+ defer server.Close()
92
+
93
+ client := testutil.NewTestClient(server.URL, "", "", "test-token")
94
+ testApp := &app.App{Client: client}
95
+
96
+ cmd := boardDeleteCmd
97
+ cmd.SetContext(testApp.ToContext(context.Background()))
98
+
99
+ err := handleDeleteBoard(cmd, "board-123")
100
+ if err == nil {
101
+ t.Errorf("expected error for API failure")
102
+ }
103
+ if err.Error() != "deleting board: unexpected status code 500: Internal Server Error" {
104
+ t.Errorf("expected API error, got %v", err)
105
+ }
106
+ }
107
+
108
+ func TestBoardDeleteCommandNoClient(t *testing.T) {
109
+ testApp := &app.App{}
110
+
111
+ cmd := boardDeleteCmd
112
+ cmd.SetContext(testApp.ToContext(context.Background()))
113
+
114
+ err := handleDeleteBoard(cmd, "board-123")
115
+ if err == nil {
116
+ t.Errorf("expected error when client not available")
117
+ }
118
+ if err.Error() != "API client not available" {
119
+ t.Errorf("expected 'client not available' error, got %v", err)
120
+ }
121
+ }
@@ -0,0 +1,40 @@
1
+ package cmd
2
+
3
+ import (
4
+ "context"
5
+ "fmt"
6
+
7
+ "github.com/rogeriopvl/fizzy/internal/app"
8
+ "github.com/rogeriopvl/fizzy/internal/ui"
9
+ "github.com/spf13/cobra"
10
+ )
11
+
12
+ var boardShowCmd = &cobra.Command{
13
+ Use: "show <board_id>",
14
+ Short: "Show board details",
15
+ Long: `Retrieve and display detailed information about a specific board`,
16
+ Args: cobra.ExactArgs(1),
17
+ Run: func(cmd *cobra.Command, args []string) {
18
+ if err := handleShowBoardDetails(cmd, args[0]); err != nil {
19
+ fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
20
+ }
21
+ },
22
+ }
23
+
24
+ func handleShowBoardDetails(cmd *cobra.Command, boardID string) error {
25
+ a := app.FromContext(cmd.Context())
26
+ if a == nil || a.Client == nil {
27
+ return fmt.Errorf("API client not available")
28
+ }
29
+
30
+ board, err := a.Client.GetBoard(context.Background(), boardID)
31
+ if err != nil {
32
+ return fmt.Errorf("fetching board: %w", err)
33
+ }
34
+
35
+ return ui.DisplayBoard(cmd.OutOrStdout(), board)
36
+ }
37
+
38
+ func init() {
39
+ boardCmd.AddCommand(boardShowCmd)
40
+ }
@@ -0,0 +1,113 @@
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 TestBoardShowCommandSuccess(t *testing.T) {
16
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
17
+ if r.URL.Path != "/boards/board-123" {
18
+ t.Errorf("expected /boards/board-123, 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.Board{
31
+ ID: "board-123",
32
+ Name: "Project Alpha",
33
+ AllAccess: true,
34
+ CreatedAt: "2025-01-01T00:00:00Z",
35
+ Creator: api.User{
36
+ ID: "user-123",
37
+ Name: "John Doe",
38
+ Role: "owner",
39
+ },
40
+ }
41
+ json.NewEncoder(w).Encode(response)
42
+ }))
43
+ defer server.Close()
44
+
45
+ client := testutil.NewTestClient(server.URL, "", "", "test-token")
46
+ testApp := &app.App{Client: client}
47
+
48
+ cmd := boardShowCmd
49
+ cmd.SetContext(testApp.ToContext(context.Background()))
50
+
51
+ if err := handleShowBoardDetails(cmd, "board-123"); err != nil {
52
+ t.Fatalf("handleShowBoardDetails failed: %v", err)
53
+ }
54
+ }
55
+
56
+ func TestBoardShowCommandNotFound(t *testing.T) {
57
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
58
+ w.WriteHeader(http.StatusNotFound)
59
+ w.Write([]byte("Board not found"))
60
+ }))
61
+ defer server.Close()
62
+
63
+ client := testutil.NewTestClient(server.URL, "", "", "test-token")
64
+ testApp := &app.App{Client: client}
65
+
66
+ cmd := boardShowCmd
67
+ cmd.SetContext(testApp.ToContext(context.Background()))
68
+
69
+ err := handleShowBoardDetails(cmd, "nonexistent-board")
70
+ if err == nil {
71
+ t.Errorf("expected error for board not found")
72
+ }
73
+ if err.Error() != "fetching board: unexpected status code 404: Board not found" {
74
+ t.Errorf("expected board not found error, got %v", err)
75
+ }
76
+ }
77
+
78
+ func TestBoardShowCommandAPIError(t *testing.T) {
79
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
80
+ w.WriteHeader(http.StatusInternalServerError)
81
+ w.Write([]byte("Internal Server Error"))
82
+ }))
83
+ defer server.Close()
84
+
85
+ client := testutil.NewTestClient(server.URL, "", "", "test-token")
86
+ testApp := &app.App{Client: client}
87
+
88
+ cmd := boardShowCmd
89
+ cmd.SetContext(testApp.ToContext(context.Background()))
90
+
91
+ err := handleShowBoardDetails(cmd, "board-123")
92
+ if err == nil {
93
+ t.Errorf("expected error for API failure")
94
+ }
95
+ if err.Error() != "fetching board: unexpected status code 500: Internal Server Error" {
96
+ t.Errorf("expected API error, got %v", err)
97
+ }
98
+ }
99
+
100
+ func TestBoardShowCommandNoClient(t *testing.T) {
101
+ testApp := &app.App{}
102
+
103
+ cmd := boardShowCmd
104
+ cmd.SetContext(testApp.ToContext(context.Background()))
105
+
106
+ err := handleShowBoardDetails(cmd, "board-123")
107
+ if err == nil {
108
+ t.Errorf("expected error when client not available")
109
+ }
110
+ if err.Error() != "API client not available" {
111
+ t.Errorf("expected 'client not available' error, got %v", err)
112
+ }
113
+ }
@@ -0,0 +1,72 @@
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/spf13/cobra"
10
+ )
11
+
12
+ var boardUpdateCmd = &cobra.Command{
13
+ Use: "update <board_id>",
14
+ Short: "Update a board",
15
+ Long: `Update board settings such as name, access permissions, and auto-postpone period`,
16
+ Args: cobra.ExactArgs(1),
17
+ Run: func(cmd *cobra.Command, args []string) {
18
+ if err := handleUpdateBoard(cmd, args[0]); err != nil {
19
+ fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
20
+ }
21
+ },
22
+ }
23
+
24
+ func handleUpdateBoard(cmd *cobra.Command, boardID string) error {
25
+ // Check that at least one flag was explicitly set
26
+ if !cmd.Flags().Changed("name") && !cmd.Flags().Changed("all-access") &&
27
+ !cmd.Flags().Changed("auto-postpone-period") && !cmd.Flags().Changed("description") {
28
+ return fmt.Errorf("at least one flag must be provided (--name, --all-access, --auto-postpone-period, or --description)")
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
+ payload := api.UpdateBoardPayload{}
38
+
39
+ if cmd.Flags().Changed("name") {
40
+ name, _ := cmd.Flags().GetString("name")
41
+ payload.Name = name
42
+ }
43
+ if cmd.Flags().Changed("all-access") {
44
+ allAccess, _ := cmd.Flags().GetBool("all-access")
45
+ payload.AllAccess = &allAccess
46
+ }
47
+ if cmd.Flags().Changed("auto-postpone-period") {
48
+ autoPostponePeriod, _ := cmd.Flags().GetInt("auto-postpone-period")
49
+ payload.AutoPostponePeriod = &autoPostponePeriod
50
+ }
51
+ if cmd.Flags().Changed("description") {
52
+ publicDescription, _ := cmd.Flags().GetString("description")
53
+ payload.PublicDescription = publicDescription
54
+ }
55
+
56
+ err := a.Client.PutBoard(context.Background(), boardID, payload)
57
+ if err != nil {
58
+ return fmt.Errorf("updating board: %w", err)
59
+ }
60
+
61
+ fmt.Fprintf(cmd.OutOrStdout(), "✓ Board '%s' updated successfully\n", boardID)
62
+ return nil
63
+ }
64
+
65
+ func init() {
66
+ boardUpdateCmd.Flags().StringP("name", "n", "", "Board name")
67
+ boardUpdateCmd.Flags().Bool("all-access", false, "Allow all access to the board")
68
+ boardUpdateCmd.Flags().Int("auto-postpone-period", 0, "Auto postpone period in days")
69
+ boardUpdateCmd.Flags().String("description", "", "Public description of the board")
70
+
71
+ boardCmd.AddCommand(boardUpdateCmd)
72
+ }
@@ -0,0 +1,233 @@
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/testutil"
14
+ "github.com/spf13/cobra"
15
+ )
16
+
17
+ func TestBoardUpdateCommandSuccess(t *testing.T) {
18
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
19
+ if r.URL.Path != "/boards/board-123" {
20
+ t.Errorf("expected /boards/board-123, got %s", r.URL.Path)
21
+ }
22
+ if r.Method != http.MethodPut {
23
+ t.Errorf("expected PUT, 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
+ body, _ := io.ReadAll(r.Body)
32
+ var payload map[string]api.UpdateBoardPayload
33
+ if err := json.Unmarshal(body, &payload); err != nil {
34
+ t.Fatalf("failed to unmarshal request body: %v", err)
35
+ }
36
+
37
+ boardPayload := payload["board"]
38
+ if boardPayload.Name != "Updated Board" {
39
+ t.Errorf("expected name 'Updated Board', got %s", boardPayload.Name)
40
+ }
41
+
42
+ w.WriteHeader(http.StatusNoContent)
43
+ }))
44
+ defer server.Close()
45
+
46
+ client := testutil.NewTestClient(server.URL, "", "", "test-token")
47
+ testApp := &app.App{Client: client}
48
+
49
+ cmd := boardUpdateCmd
50
+ cmd.SetContext(testApp.ToContext(context.Background()))
51
+ cmd.ParseFlags([]string{"--name", "Updated Board"})
52
+
53
+ if err := handleUpdateBoard(cmd, "board-123"); err != nil {
54
+ t.Fatalf("handleUpdateBoard failed: %v", err)
55
+ }
56
+ }
57
+
58
+ func TestBoardUpdateCommandWithAllFlags(t *testing.T) {
59
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
60
+ if r.Method != http.MethodPut {
61
+ t.Errorf("expected PUT, got %s", r.Method)
62
+ }
63
+
64
+ body, _ := io.ReadAll(r.Body)
65
+ var payload map[string]api.UpdateBoardPayload
66
+ json.Unmarshal(body, &payload)
67
+
68
+ boardPayload := payload["board"]
69
+ if boardPayload.Name != "Updated Board" {
70
+ t.Errorf("expected name 'Updated Board', got %s", boardPayload.Name)
71
+ }
72
+ if boardPayload.AllAccess == nil || !*boardPayload.AllAccess {
73
+ t.Error("expected AllAccess to be pointer to true")
74
+ }
75
+ if boardPayload.AutoPostponePeriod == nil || *boardPayload.AutoPostponePeriod != 14 {
76
+ t.Errorf("expected AutoPostponePeriod pointer to 14, got %v", boardPayload.AutoPostponePeriod)
77
+ }
78
+ if boardPayload.PublicDescription != "Updated description" {
79
+ t.Errorf("expected description 'Updated description', got %s", boardPayload.PublicDescription)
80
+ }
81
+
82
+ w.WriteHeader(http.StatusNoContent)
83
+ }))
84
+ defer server.Close()
85
+
86
+ client := testutil.NewTestClient(server.URL, "", "", "test-token")
87
+ testApp := &app.App{Client: client}
88
+
89
+ cmd := boardUpdateCmd
90
+ cmd.SetContext(testApp.ToContext(context.Background()))
91
+ cmd.ParseFlags([]string{
92
+ "--name", "Updated Board",
93
+ "--all-access",
94
+ "--auto-postpone-period", "14",
95
+ "--description", "Updated description",
96
+ })
97
+
98
+ if err := handleUpdateBoard(cmd, "board-123"); err != nil {
99
+ t.Fatalf("handleUpdateBoard failed: %v", err)
100
+ }
101
+ }
102
+
103
+ func TestBoardUpdateCommandZeroValues(t *testing.T) {
104
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
105
+ if r.Method != http.MethodPut {
106
+ t.Errorf("expected PUT, got %s", r.Method)
107
+ }
108
+
109
+ body, _ := io.ReadAll(r.Body)
110
+ var payload map[string]api.UpdateBoardPayload
111
+ json.Unmarshal(body, &payload)
112
+
113
+ boardPayload := payload["board"]
114
+ // Verify that false value is sent (not omitted)
115
+ if boardPayload.AllAccess == nil {
116
+ t.Error("expected AllAccess to be set (pointer), but got nil")
117
+ }
118
+ if *boardPayload.AllAccess != false {
119
+ t.Error("expected AllAccess to be false")
120
+ }
121
+ // Verify that 0 value is sent (not omitted)
122
+ if boardPayload.AutoPostponePeriod == nil {
123
+ t.Error("expected AutoPostponePeriod to be set (pointer), but got nil")
124
+ }
125
+ if *boardPayload.AutoPostponePeriod != 0 {
126
+ t.Errorf("expected AutoPostponePeriod to be 0, got %d", *boardPayload.AutoPostponePeriod)
127
+ }
128
+
129
+ w.WriteHeader(http.StatusNoContent)
130
+ }))
131
+ defer server.Close()
132
+
133
+ client := testutil.NewTestClient(server.URL, "", "", "test-token")
134
+ testApp := &app.App{Client: client}
135
+
136
+ cmd := boardUpdateCmd
137
+ cmd.SetContext(testApp.ToContext(context.Background()))
138
+ cmd.ParseFlags([]string{
139
+ "--all-access=false",
140
+ "--auto-postpone-period", "0",
141
+ })
142
+
143
+ if err := handleUpdateBoard(cmd, "board-123"); err != nil {
144
+ t.Fatalf("handleUpdateBoard failed: %v", err)
145
+ }
146
+ }
147
+
148
+ func TestBoardUpdateCommandNoFlags(t *testing.T) {
149
+ client := testutil.NewTestClient("http://localhost", "", "", "test-token")
150
+ testApp := &app.App{Client: client}
151
+
152
+ // Create a fresh command to avoid flag pollution from other tests
153
+ cmd := &cobra.Command{
154
+ Use: "update <board_id>",
155
+ Args: cobra.ExactArgs(1),
156
+ }
157
+ cmd.Flags().String("name", "", "Board name")
158
+ cmd.Flags().Bool("all-access", false, "Allow all access to the board")
159
+ cmd.Flags().Int("auto-postpone-period", 0, "Auto postpone period in days")
160
+ cmd.Flags().String("description", "", "Public description of the board")
161
+
162
+ cmd.SetContext(testApp.ToContext(context.Background()))
163
+
164
+ err := handleUpdateBoard(cmd, "board-123")
165
+ if err == nil {
166
+ t.Errorf("expected error when no flags provided")
167
+ }
168
+ if err.Error() != "at least one flag must be provided (--name, --all-access, --auto-postpone-period, or --description)" {
169
+ t.Errorf("expected flag requirement error, got %v", err)
170
+ }
171
+ }
172
+
173
+ func TestBoardUpdateCommandNotFound(t *testing.T) {
174
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
175
+ w.WriteHeader(http.StatusNotFound)
176
+ w.Write([]byte("Board not found"))
177
+ }))
178
+ defer server.Close()
179
+
180
+ client := testutil.NewTestClient(server.URL, "", "", "test-token")
181
+ testApp := &app.App{Client: client}
182
+
183
+ cmd := boardUpdateCmd
184
+ cmd.SetContext(testApp.ToContext(context.Background()))
185
+ cmd.ParseFlags([]string{"--name", "Updated Board"})
186
+
187
+ err := handleUpdateBoard(cmd, "nonexistent-board")
188
+ if err == nil {
189
+ t.Errorf("expected error for board not found")
190
+ }
191
+ if err.Error() != "updating board: unexpected status code 404: Board not found" {
192
+ t.Errorf("expected board not found error, got %v", err)
193
+ }
194
+ }
195
+
196
+ func TestBoardUpdateCommandAPIError(t *testing.T) {
197
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
198
+ w.WriteHeader(http.StatusInternalServerError)
199
+ w.Write([]byte("Internal Server Error"))
200
+ }))
201
+ defer server.Close()
202
+
203
+ client := testutil.NewTestClient(server.URL, "", "", "test-token")
204
+ testApp := &app.App{Client: client}
205
+
206
+ cmd := boardUpdateCmd
207
+ cmd.SetContext(testApp.ToContext(context.Background()))
208
+ cmd.ParseFlags([]string{"--name", "Updated Board"})
209
+
210
+ err := handleUpdateBoard(cmd, "board-123")
211
+ if err == nil {
212
+ t.Errorf("expected error for API failure")
213
+ }
214
+ if err.Error() != "updating board: unexpected status code 500: Internal Server Error" {
215
+ t.Errorf("expected API error, got %v", err)
216
+ }
217
+ }
218
+
219
+ func TestBoardUpdateCommandNoClient(t *testing.T) {
220
+ testApp := &app.App{}
221
+
222
+ cmd := boardUpdateCmd
223
+ cmd.SetContext(testApp.ToContext(context.Background()))
224
+ cmd.ParseFlags([]string{"--name", "Updated Board"})
225
+
226
+ err := handleUpdateBoard(cmd, "board-123")
227
+ if err == nil {
228
+ t.Errorf("expected error when client not available")
229
+ }
230
+ if err.Error() != "API client not available" {
231
+ t.Errorf("expected 'client not available' error, got %v", err)
232
+ }
233
+ }
@@ -46,7 +46,7 @@ func handleAssignCard(cmd *cobra.Command, cardNumber, userID string) error {
46
46
  return fmt.Errorf("assigning card: %w", err)
47
47
  }
48
48
 
49
- fmt.Printf("✓ Card #%d assignment toggled for user %s\n", cardNum, userID)
49
+ fmt.Fprintf(cmd.OutOrStdout(), "✓ Card #%d assignment toggled for user %s\n", cardNum, userID)
50
50
  return nil
51
51
  }
52
52
 
package/cmd/card_close.go CHANGED
@@ -37,7 +37,7 @@ func handleCloseCard(cmd *cobra.Command, cardNumber string) error {
37
37
  return fmt.Errorf("closing card: %w", err)
38
38
  }
39
39
 
40
- fmt.Printf("✓ Card #%d closed successfully\n", cardNum)
40
+ fmt.Fprintf(cmd.OutOrStdout(), "✓ Card #%d closed successfully\n", cardNum)
41
41
  return nil
42
42
  }
43
43