fizzy-cli 0.8.0 → 1.0.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 (159) hide show
  1. package/.golangci.yml +56 -0
  2. package/IMPLEMENTATION_PLAN.md +58 -0
  3. package/docs/API.md +89 -0
  4. package/package.json +2 -1
  5. package/.env +0 -1
  6. package/.github/workflows/release.yml +0 -29
  7. package/.github/workflows/tests.yml +0 -24
  8. package/AGENTS.md +0 -33
  9. package/CHANGELOG.md +0 -194
  10. package/Makefile +0 -43
  11. package/bin/fizzy +0 -0
  12. package/cmd/account.go +0 -14
  13. package/cmd/account_list.go +0 -44
  14. package/cmd/account_list_test.go +0 -118
  15. package/cmd/board.go +0 -49
  16. package/cmd/board_create.go +0 -59
  17. package/cmd/board_create_test.go +0 -141
  18. package/cmd/board_delete.go +0 -40
  19. package/cmd/board_delete_test.go +0 -121
  20. package/cmd/board_list.go +0 -44
  21. package/cmd/board_list_test.go +0 -115
  22. package/cmd/board_show.go +0 -40
  23. package/cmd/board_show_test.go +0 -113
  24. package/cmd/board_test.go +0 -92
  25. package/cmd/board_update.go +0 -72
  26. package/cmd/board_update_test.go +0 -233
  27. package/cmd/card.go +0 -24
  28. package/cmd/card_assign.go +0 -55
  29. package/cmd/card_assign_test.go +0 -130
  30. package/cmd/card_close.go +0 -46
  31. package/cmd/card_close_test.go +0 -92
  32. package/cmd/card_create.go +0 -72
  33. package/cmd/card_create_test.go +0 -186
  34. package/cmd/card_delete.go +0 -46
  35. package/cmd/card_delete_test.go +0 -92
  36. package/cmd/card_golden.go +0 -46
  37. package/cmd/card_golden_test.go +0 -92
  38. package/cmd/card_list.go +0 -114
  39. package/cmd/card_list_test.go +0 -373
  40. package/cmd/card_not_now.go +0 -46
  41. package/cmd/card_not_now_test.go +0 -92
  42. package/cmd/card_reaction.go +0 -13
  43. package/cmd/card_reaction_create.go +0 -46
  44. package/cmd/card_reaction_create_test.go +0 -148
  45. package/cmd/card_reaction_delete.go +0 -46
  46. package/cmd/card_reaction_delete_test.go +0 -112
  47. package/cmd/card_reaction_list.go +0 -51
  48. package/cmd/card_reaction_list_test.go +0 -127
  49. package/cmd/card_reopen.go +0 -46
  50. package/cmd/card_reopen_test.go +0 -92
  51. package/cmd/card_show.go +0 -46
  52. package/cmd/card_show_test.go +0 -92
  53. package/cmd/card_tag.go +0 -51
  54. package/cmd/card_tag_test.go +0 -112
  55. package/cmd/card_triage.go +0 -46
  56. package/cmd/card_ungolden.go +0 -46
  57. package/cmd/card_ungolden_test.go +0 -92
  58. package/cmd/card_untriage.go +0 -46
  59. package/cmd/card_untriage_test.go +0 -92
  60. package/cmd/card_unwatch.go +0 -46
  61. package/cmd/card_unwatch_test.go +0 -92
  62. package/cmd/card_update.go +0 -82
  63. package/cmd/card_update_test.go +0 -149
  64. package/cmd/card_watch.go +0 -46
  65. package/cmd/card_watch_test.go +0 -92
  66. package/cmd/column.go +0 -14
  67. package/cmd/column_create.go +0 -79
  68. package/cmd/column_create_test.go +0 -178
  69. package/cmd/column_delete.go +0 -40
  70. package/cmd/column_delete_test.go +0 -121
  71. package/cmd/column_list.go +0 -44
  72. package/cmd/column_list_test.go +0 -138
  73. package/cmd/column_show.go +0 -40
  74. package/cmd/column_show_test.go +0 -111
  75. package/cmd/column_update.go +0 -67
  76. package/cmd/column_update_test.go +0 -198
  77. package/cmd/comment.go +0 -14
  78. package/cmd/comment_create.go +0 -51
  79. package/cmd/comment_create_test.go +0 -129
  80. package/cmd/comment_delete.go +0 -46
  81. package/cmd/comment_delete_test.go +0 -92
  82. package/cmd/comment_list.go +0 -51
  83. package/cmd/comment_list_test.go +0 -132
  84. package/cmd/comment_show.go +0 -46
  85. package/cmd/comment_show_test.go +0 -104
  86. package/cmd/comment_update.go +0 -51
  87. package/cmd/comment_update_test.go +0 -130
  88. package/cmd/login.go +0 -81
  89. package/cmd/login_test.go +0 -98
  90. package/cmd/notification.go +0 -14
  91. package/cmd/notification_list.go +0 -69
  92. package/cmd/notification_list_test.go +0 -288
  93. package/cmd/notification_read.go +0 -51
  94. package/cmd/notification_read_all.go +0 -38
  95. package/cmd/notification_read_all_test.go +0 -75
  96. package/cmd/notification_read_test.go +0 -138
  97. package/cmd/notification_unread.go +0 -44
  98. package/cmd/notification_unread_test.go +0 -99
  99. package/cmd/reaction.go +0 -13
  100. package/cmd/reaction_create.go +0 -46
  101. package/cmd/reaction_create_test.go +0 -113
  102. package/cmd/reaction_delete.go +0 -46
  103. package/cmd/reaction_delete_test.go +0 -92
  104. package/cmd/reaction_list.go +0 -51
  105. package/cmd/reaction_list_test.go +0 -125
  106. package/cmd/root.go +0 -38
  107. package/cmd/step.go +0 -14
  108. package/cmd/step_create.go +0 -53
  109. package/cmd/step_create_test.go +0 -171
  110. package/cmd/step_delete.go +0 -46
  111. package/cmd/step_delete_test.go +0 -92
  112. package/cmd/step_update.go +0 -66
  113. package/cmd/step_update_test.go +0 -190
  114. package/cmd/tag.go +0 -15
  115. package/cmd/tag_list.go +0 -47
  116. package/cmd/tag_list_test.go +0 -109
  117. package/cmd/use.go +0 -85
  118. package/cmd/use_test.go +0 -186
  119. package/cmd/user.go +0 -22
  120. package/cmd/user_deactivate.go +0 -40
  121. package/cmd/user_deactivate_test.go +0 -121
  122. package/cmd/user_list.go +0 -44
  123. package/cmd/user_list_test.go +0 -126
  124. package/cmd/user_show.go +0 -40
  125. package/cmd/user_show_test.go +0 -110
  126. package/cmd/user_update.go +0 -71
  127. package/cmd/user_update_test.go +0 -177
  128. package/go.mod +0 -31
  129. package/go.sum +0 -53
  130. package/internal/api/boards.go +0 -93
  131. package/internal/api/cards.go +0 -322
  132. package/internal/api/client.go +0 -99
  133. package/internal/api/columns.go +0 -113
  134. package/internal/api/comments.go +0 -108
  135. package/internal/api/identity.go +0 -24
  136. package/internal/api/notifications.go +0 -89
  137. package/internal/api/reactions.go +0 -130
  138. package/internal/api/steps.go +0 -101
  139. package/internal/api/tags.go +0 -24
  140. package/internal/api/types.go +0 -195
  141. package/internal/api/users.go +0 -75
  142. package/internal/app/app.go +0 -49
  143. package/internal/colors/colors.go +0 -32
  144. package/internal/config/config.go +0 -70
  145. package/internal/testutil/client.go +0 -26
  146. package/internal/ui/account_list.go +0 -14
  147. package/internal/ui/account_selector.go +0 -63
  148. package/internal/ui/board_list.go +0 -14
  149. package/internal/ui/board_show.go +0 -17
  150. package/internal/ui/card_list.go +0 -14
  151. package/internal/ui/card_show.go +0 -23
  152. package/internal/ui/column_list.go +0 -28
  153. package/internal/ui/column_show.go +0 -16
  154. package/internal/ui/comment_list.go +0 -25
  155. package/internal/ui/format.go +0 -27
  156. package/internal/ui/notification_list.go +0 -27
  157. package/internal/ui/reaction_list.go +0 -14
  158. package/internal/ui/user_list.go +0 -19
  159. package/internal/ui/user_show.go +0 -23
@@ -1,118 +0,0 @@
1
- package cmd
2
-
3
- import (
4
- "context"
5
- "encoding/json"
6
- "net/http"
7
- "net/http/httptest"
8
- "testing"
9
-
10
- "github.com/rogeriopvl/fizzy/internal/api"
11
- "github.com/rogeriopvl/fizzy/internal/app"
12
- "github.com/rogeriopvl/fizzy/internal/testutil"
13
- )
14
-
15
- func TestAccountListCommand(t *testing.T) {
16
- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
17
- if r.URL.Path != "/my/identity" {
18
- t.Errorf("expected /my/identity, 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 == "" {
26
- t.Error("missing Authorization header")
27
- }
28
- if auth != "Bearer test-token" {
29
- t.Errorf("expected Bearer test-token, got %s", auth)
30
- }
31
-
32
- w.Header().Set("Content-Type", "application/json")
33
- response := api.GetMyIdentityResponse{
34
- Accounts: []api.Account{
35
- {
36
- ID: "account-123",
37
- Name: "Personal",
38
- Slug: "personal",
39
- CreatedAt: "2025-01-01T00:00:00Z",
40
- },
41
- {
42
- ID: "account-456",
43
- Name: "Work",
44
- Slug: "work",
45
- CreatedAt: "2025-01-02T00:00:00Z",
46
- },
47
- },
48
- }
49
- json.NewEncoder(w).Encode(response)
50
- }))
51
- defer server.Close()
52
-
53
- client := testutil.NewTestClient(server.URL, "", "", "test-token")
54
- testApp := &app.App{Client: client}
55
-
56
- cmd := accountListCmd
57
- cmd.SetContext(testApp.ToContext(context.Background()))
58
-
59
- if err := handleListAccounts(cmd); err != nil {
60
- t.Fatalf("handleListAccounts failed: %v", err)
61
- }
62
- }
63
-
64
- func TestAccountListCommandNoAccounts(t *testing.T) {
65
- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
66
- w.Header().Set("Content-Type", "application/json")
67
- response := api.GetMyIdentityResponse{Accounts: []api.Account{}}
68
- json.NewEncoder(w).Encode(response)
69
- }))
70
- defer server.Close()
71
-
72
- client := testutil.NewTestClient(server.URL, "", "", "test-token")
73
- testApp := &app.App{Client: client}
74
-
75
- cmd := accountListCmd
76
- cmd.SetContext(testApp.ToContext(context.Background()))
77
-
78
- if err := handleListAccounts(cmd); err != nil {
79
- t.Fatalf("handleListAccounts failed: %v", err)
80
- }
81
- }
82
-
83
- func TestAccountListCommandAPIError(t *testing.T) {
84
- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
85
- w.WriteHeader(http.StatusInternalServerError)
86
- w.Write([]byte("Internal Server Error"))
87
- }))
88
- defer server.Close()
89
-
90
- client := testutil.NewTestClient(server.URL, "", "", "test-token")
91
- testApp := &app.App{Client: client}
92
-
93
- cmd := accountListCmd
94
- cmd.SetContext(testApp.ToContext(context.Background()))
95
-
96
- err := handleListAccounts(cmd)
97
- if err == nil {
98
- t.Errorf("expected error for API failure")
99
- }
100
- if err.Error() != "fetching accounts: unexpected status code 500: Internal Server Error" {
101
- t.Errorf("expected API error, got %v", err)
102
- }
103
- }
104
-
105
- func TestAccountListCommandNoClient(t *testing.T) {
106
- testApp := &app.App{}
107
-
108
- cmd := accountListCmd
109
- cmd.SetContext(testApp.ToContext(context.Background()))
110
-
111
- err := handleListAccounts(cmd)
112
- if err == nil {
113
- t.Errorf("expected error when client not available")
114
- }
115
- if err.Error() != "API client not available" {
116
- t.Errorf("expected 'client not available' error, got %v", err)
117
- }
118
- }
package/cmd/board.go DELETED
@@ -1,49 +0,0 @@
1
- // Package cmd
2
- package cmd
3
-
4
- import (
5
- "context"
6
- "fmt"
7
-
8
- "github.com/rogeriopvl/fizzy/internal/app"
9
- "github.com/rogeriopvl/fizzy/internal/ui"
10
- "github.com/spf13/cobra"
11
- )
12
-
13
- var boardCmd = &cobra.Command{
14
- Use: "board",
15
- Short: "Show the currently selected board",
16
- Long: `Display the name and ID of the currently selected board.
17
-
18
- Use subcommands to list, create, or manage boards:
19
- fizzy board list List all boards
20
- fizzy board create Create a new board`,
21
- Run: func(cmd *cobra.Command, args []string) {
22
- if err := handleShowBoard(cmd); err != nil {
23
- fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
24
- }
25
- },
26
- }
27
-
28
- func handleShowBoard(cmd *cobra.Command) error {
29
- a := app.FromContext(cmd.Context())
30
- if a == nil || a.Client == nil {
31
- return fmt.Errorf("API client not available")
32
- }
33
-
34
- if a.Config.SelectedBoard == "" {
35
- return fmt.Errorf("no board selected")
36
- }
37
-
38
- board, err := a.Client.GetBoard(context.Background(), a.Config.SelectedBoard)
39
- if err != nil {
40
- return fmt.Errorf("fetching board: %w", err)
41
- }
42
-
43
- fmt.Fprintf(cmd.OutOrStdout(), "%s (%s)\n", board.Name, ui.DisplayID(board.ID))
44
- return nil
45
- }
46
-
47
- func init() {
48
- rootCmd.AddCommand(boardCmd)
49
- }
@@ -1,59 +0,0 @@
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 boardCreateCmd = &cobra.Command{
13
- Use: "create",
14
- Short: "Create a new board",
15
- Long: `Create a new board in Fizzy`,
16
- Run: func(cmd *cobra.Command, args []string) {
17
- if err := handleCreateBoard(cmd); err != nil {
18
- fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
19
- }
20
- },
21
- }
22
-
23
- func handleCreateBoard(cmd *cobra.Command) 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
- // Read flag values directly from command
30
- name, _ := cmd.Flags().GetString("name")
31
- allAccess, _ := cmd.Flags().GetBool("all-access")
32
- autoPostponePeriod, _ := cmd.Flags().GetInt("auto-postpone-period")
33
- publicDescription, _ := cmd.Flags().GetString("description")
34
-
35
- payload := api.CreateBoardPayload{
36
- Name: name,
37
- AllAccess: allAccess,
38
- AutoPostponePeriod: autoPostponePeriod,
39
- PublicDescription: publicDescription,
40
- }
41
-
42
- _, err := a.Client.PostBoards(context.Background(), payload)
43
- if err != nil {
44
- return fmt.Errorf("creating board: %w", err)
45
- }
46
-
47
- fmt.Fprintf(cmd.OutOrStdout(), "✓ Board '%s' created successfully\n", name)
48
- return nil
49
- }
50
-
51
- func init() {
52
- boardCreateCmd.Flags().StringP("name", "n", "", "Board name (required)")
53
- boardCreateCmd.MarkFlagRequired("name")
54
- boardCreateCmd.Flags().Bool("all-access", false, "Allow all access to the board")
55
- boardCreateCmd.Flags().Int("auto-postpone-period", 0, "Auto postpone period in days")
56
- boardCreateCmd.Flags().String("description", "", "Public description of the board")
57
-
58
- boardCmd.AddCommand(boardCreateCmd)
59
- }
@@ -1,141 +0,0 @@
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
- )
15
-
16
- func TestBoardCreateCommandSuccess(t *testing.T) {
17
- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
18
- if r.URL.Path != "/boards" {
19
- t.Errorf("expected /boards, got %s", r.URL.Path)
20
- }
21
- if r.Method != http.MethodPost {
22
- t.Errorf("expected POST, got %s", r.Method)
23
- }
24
-
25
- auth := r.Header.Get("Authorization")
26
- if auth != "Bearer test-token" {
27
- t.Errorf("expected Bearer test-token, got %s", auth)
28
- }
29
-
30
- if r.Header.Get("Content-Type") != "application/json" {
31
- t.Errorf("expected Content-Type: application/json, got %s", r.Header.Get("Content-Type"))
32
- }
33
-
34
- body, _ := io.ReadAll(r.Body)
35
- var payload map[string]api.CreateBoardPayload
36
- if err := json.Unmarshal(body, &payload); err != nil {
37
- t.Fatalf("failed to unmarshal request body: %v", err)
38
- }
39
-
40
- boardPayload := payload["board"]
41
- if boardPayload.Name != "Test Board" {
42
- t.Errorf("expected name 'Test Board', got %s", boardPayload.Name)
43
- }
44
-
45
- w.WriteHeader(http.StatusCreated)
46
- w.Header().Set("Location", "/boards/board-123")
47
- }))
48
- defer server.Close()
49
-
50
- client := testutil.NewTestClient(server.URL, "", "", "test-token")
51
- testApp := &app.App{Client: client}
52
-
53
- cmd := boardCreateCmd
54
- cmd.SetContext(testApp.ToContext(context.Background()))
55
- cmd.ParseFlags([]string{"--name", "Test Board"})
56
-
57
- if err := handleCreateBoard(cmd); err != nil {
58
- t.Fatalf("handleCreateBoard failed: %v", err)
59
- }
60
- }
61
-
62
- func TestBoardCreateCommandWithAllFlags(t *testing.T) {
63
- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
64
- if r.Method != http.MethodPost {
65
- t.Errorf("expected POST, got %s", r.Method)
66
- }
67
-
68
- body, _ := io.ReadAll(r.Body)
69
- var payload map[string]api.CreateBoardPayload
70
- json.Unmarshal(body, &payload)
71
-
72
- boardPayload := payload["board"]
73
- if !boardPayload.AllAccess {
74
- t.Error("expected AllAccess to be true")
75
- }
76
- if boardPayload.AutoPostponePeriod != 7 {
77
- t.Errorf("expected AutoPostponePeriod 7, got %d", boardPayload.AutoPostponePeriod)
78
- }
79
- if boardPayload.PublicDescription != "Team project" {
80
- t.Errorf("expected description 'Team project', got %s", boardPayload.PublicDescription)
81
- }
82
-
83
- w.WriteHeader(http.StatusCreated)
84
- }))
85
- defer server.Close()
86
-
87
- client := testutil.NewTestClient(server.URL, "", "", "test-token")
88
- testApp := &app.App{Client: client}
89
-
90
- cmd := boardCreateCmd
91
- cmd.SetContext(testApp.ToContext(context.Background()))
92
- cmd.ParseFlags([]string{
93
- "--name", "Test Board",
94
- "--all-access",
95
- "--auto-postpone-period", "7",
96
- "--description", "Team project",
97
- })
98
-
99
- if err := handleCreateBoard(cmd); err != nil {
100
- t.Fatalf("handleCreateBoard failed: %v", err)
101
- }
102
- }
103
-
104
- func TestBoardCreateCommandAPIError(t *testing.T) {
105
- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
106
- w.WriteHeader(http.StatusInternalServerError)
107
- w.Write([]byte("Internal Server Error"))
108
- }))
109
- defer server.Close()
110
-
111
- client := testutil.NewTestClient(server.URL, "", "", "test-token")
112
- testApp := &app.App{Client: client}
113
-
114
- cmd := boardCreateCmd
115
- cmd.SetContext(testApp.ToContext(context.Background()))
116
- cmd.ParseFlags([]string{"--name", "Test Board"})
117
-
118
- err := handleCreateBoard(cmd)
119
- if err == nil {
120
- t.Errorf("expected error for API failure")
121
- }
122
- if err.Error() != "creating board: unexpected status code 500: Internal Server Error" {
123
- t.Errorf("expected API error, got %v", err)
124
- }
125
- }
126
-
127
- func TestBoardCreateCommandNoClient(t *testing.T) {
128
- testApp := &app.App{}
129
-
130
- cmd := boardCreateCmd
131
- cmd.SetContext(testApp.ToContext(context.Background()))
132
- cmd.ParseFlags([]string{"--name", "Test Board"})
133
-
134
- err := handleCreateBoard(cmd)
135
- if err == nil {
136
- t.Errorf("expected error when client not available")
137
- }
138
- if err.Error() != "API client not available" {
139
- t.Errorf("expected 'client not available' error, got %v", err)
140
- }
141
- }
@@ -1,40 +0,0 @@
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
- }
@@ -1,121 +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 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
- }
package/cmd/board_list.go DELETED
@@ -1,44 +0,0 @@
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 boardListCmd = &cobra.Command{
13
- Use: "list",
14
- Short: "List all boards",
15
- Long: `Retrieve and display all boards from Fizzy`,
16
- Run: func(cmd *cobra.Command, args []string) {
17
- if err := handleListBoards(cmd); err != nil {
18
- fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
19
- }
20
- },
21
- }
22
-
23
- func handleListBoards(cmd *cobra.Command) 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
- boards, err := a.Client.GetBoards(context.Background())
30
- if err != nil {
31
- return fmt.Errorf("fetching boards: %w", err)
32
- }
33
-
34
- if len(boards) == 0 {
35
- fmt.Println("No boards found")
36
- return nil
37
- }
38
-
39
- return ui.DisplayBoards(boards)
40
- }
41
-
42
- func init() {
43
- boardCmd.AddCommand(boardListCmd)
44
- }
@@ -1,115 +0,0 @@
1
- package cmd
2
-
3
- import (
4
- "context"
5
- "encoding/json"
6
- "net/http"
7
- "net/http/httptest"
8
- "testing"
9
-
10
- "github.com/rogeriopvl/fizzy/internal/api"
11
- "github.com/rogeriopvl/fizzy/internal/app"
12
- "github.com/rogeriopvl/fizzy/internal/testutil"
13
- )
14
-
15
- func TestBoardListCommand(t *testing.T) {
16
- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
17
- if r.URL.Path != "/boards" {
18
- t.Errorf("expected /boards, 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 == "" {
26
- t.Error("missing Authorization header")
27
- }
28
- if auth != "Bearer test-token" {
29
- t.Errorf("expected Bearer test-token, got %s", auth)
30
- }
31
-
32
- w.Header().Set("Content-Type", "application/json")
33
- response := []api.Board{
34
- {
35
- ID: "board-123",
36
- Name: "Project Alpha",
37
- AllAccess: true,
38
- CreatedAt: "2025-01-01T00:00:00Z",
39
- },
40
- {
41
- ID: "board-456",
42
- Name: "Project Beta",
43
- AllAccess: false,
44
- CreatedAt: "2025-01-02T00:00:00Z",
45
- },
46
- }
47
- json.NewEncoder(w).Encode(response)
48
- }))
49
- defer server.Close()
50
-
51
- client := testutil.NewTestClient(server.URL, "", "", "test-token")
52
- testApp := &app.App{Client: client}
53
-
54
- cmd := boardListCmd
55
- cmd.SetContext(testApp.ToContext(context.Background()))
56
-
57
- if err := handleListBoards(cmd); err != nil {
58
- t.Fatalf("handleListBoards failed: %v", err)
59
- }
60
- }
61
-
62
- func TestBoardListCommandNoBoards(t *testing.T) {
63
- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
64
- w.Header().Set("Content-Type", "application/json")
65
- json.NewEncoder(w).Encode([]api.Board{})
66
- }))
67
- defer server.Close()
68
-
69
- client := testutil.NewTestClient(server.URL, "", "", "test-token")
70
- testApp := &app.App{Client: client}
71
-
72
- cmd := boardListCmd
73
- cmd.SetContext(testApp.ToContext(context.Background()))
74
-
75
- if err := handleListBoards(cmd); err != nil {
76
- t.Fatalf("handleListBoards failed: %v", err)
77
- }
78
- }
79
-
80
- func TestBoardListCommandAPIError(t *testing.T) {
81
- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
82
- w.WriteHeader(http.StatusInternalServerError)
83
- w.Write([]byte("Internal Server Error"))
84
- }))
85
- defer server.Close()
86
-
87
- client := testutil.NewTestClient(server.URL, "", "", "test-token")
88
- testApp := &app.App{Client: client}
89
-
90
- cmd := boardListCmd
91
- cmd.SetContext(testApp.ToContext(context.Background()))
92
-
93
- err := handleListBoards(cmd)
94
- if err == nil {
95
- t.Errorf("expected error for API failure")
96
- }
97
- if err.Error() != "fetching boards: unexpected status code 500: Internal Server Error" {
98
- t.Errorf("expected API error, got %v", err)
99
- }
100
- }
101
-
102
- func TestBoardListCommandNoClient(t *testing.T) {
103
- testApp := &app.App{}
104
-
105
- cmd := boardListCmd
106
- cmd.SetContext(testApp.ToContext(context.Background()))
107
-
108
- err := handleListBoards(cmd)
109
- if err == nil {
110
- t.Errorf("expected error when client not available")
111
- }
112
- if err.Error() != "API client not available" {
113
- t.Errorf("expected 'client not available' error, got %v", err)
114
- }
115
- }