fizzy-cli 0.8.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 (156) hide show
  1. package/package.json +2 -1
  2. package/.env +0 -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 -194
  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 -114
  36. package/cmd/card_list_test.go +0 -373
  37. package/cmd/card_not_now.go +0 -46
  38. package/cmd/card_not_now_test.go +0 -92
  39. package/cmd/card_reaction.go +0 -13
  40. package/cmd/card_reaction_create.go +0 -46
  41. package/cmd/card_reaction_create_test.go +0 -148
  42. package/cmd/card_reaction_delete.go +0 -46
  43. package/cmd/card_reaction_delete_test.go +0 -112
  44. package/cmd/card_reaction_list.go +0 -51
  45. package/cmd/card_reaction_list_test.go +0 -127
  46. package/cmd/card_reopen.go +0 -46
  47. package/cmd/card_reopen_test.go +0 -92
  48. package/cmd/card_show.go +0 -46
  49. package/cmd/card_show_test.go +0 -92
  50. package/cmd/card_tag.go +0 -51
  51. package/cmd/card_tag_test.go +0 -112
  52. package/cmd/card_triage.go +0 -46
  53. package/cmd/card_ungolden.go +0 -46
  54. package/cmd/card_ungolden_test.go +0 -92
  55. package/cmd/card_untriage.go +0 -46
  56. package/cmd/card_untriage_test.go +0 -92
  57. package/cmd/card_unwatch.go +0 -46
  58. package/cmd/card_unwatch_test.go +0 -92
  59. package/cmd/card_update.go +0 -82
  60. package/cmd/card_update_test.go +0 -149
  61. package/cmd/card_watch.go +0 -46
  62. package/cmd/card_watch_test.go +0 -92
  63. package/cmd/column.go +0 -14
  64. package/cmd/column_create.go +0 -79
  65. package/cmd/column_create_test.go +0 -178
  66. package/cmd/column_delete.go +0 -40
  67. package/cmd/column_delete_test.go +0 -121
  68. package/cmd/column_list.go +0 -44
  69. package/cmd/column_list_test.go +0 -138
  70. package/cmd/column_show.go +0 -40
  71. package/cmd/column_show_test.go +0 -111
  72. package/cmd/column_update.go +0 -67
  73. package/cmd/column_update_test.go +0 -198
  74. package/cmd/comment.go +0 -14
  75. package/cmd/comment_create.go +0 -51
  76. package/cmd/comment_create_test.go +0 -129
  77. package/cmd/comment_delete.go +0 -46
  78. package/cmd/comment_delete_test.go +0 -92
  79. package/cmd/comment_list.go +0 -51
  80. package/cmd/comment_list_test.go +0 -132
  81. package/cmd/comment_show.go +0 -46
  82. package/cmd/comment_show_test.go +0 -104
  83. package/cmd/comment_update.go +0 -51
  84. package/cmd/comment_update_test.go +0 -130
  85. package/cmd/login.go +0 -81
  86. package/cmd/login_test.go +0 -98
  87. package/cmd/notification.go +0 -14
  88. package/cmd/notification_list.go +0 -69
  89. package/cmd/notification_list_test.go +0 -288
  90. package/cmd/notification_read.go +0 -51
  91. package/cmd/notification_read_all.go +0 -38
  92. package/cmd/notification_read_all_test.go +0 -75
  93. package/cmd/notification_read_test.go +0 -138
  94. package/cmd/notification_unread.go +0 -44
  95. package/cmd/notification_unread_test.go +0 -99
  96. package/cmd/reaction.go +0 -13
  97. package/cmd/reaction_create.go +0 -46
  98. package/cmd/reaction_create_test.go +0 -113
  99. package/cmd/reaction_delete.go +0 -46
  100. package/cmd/reaction_delete_test.go +0 -92
  101. package/cmd/reaction_list.go +0 -51
  102. package/cmd/reaction_list_test.go +0 -125
  103. package/cmd/root.go +0 -38
  104. package/cmd/step.go +0 -14
  105. package/cmd/step_create.go +0 -53
  106. package/cmd/step_create_test.go +0 -171
  107. package/cmd/step_delete.go +0 -46
  108. package/cmd/step_delete_test.go +0 -92
  109. package/cmd/step_update.go +0 -66
  110. package/cmd/step_update_test.go +0 -190
  111. package/cmd/tag.go +0 -15
  112. package/cmd/tag_list.go +0 -47
  113. package/cmd/tag_list_test.go +0 -109
  114. package/cmd/use.go +0 -85
  115. package/cmd/use_test.go +0 -186
  116. package/cmd/user.go +0 -22
  117. package/cmd/user_deactivate.go +0 -40
  118. package/cmd/user_deactivate_test.go +0 -121
  119. package/cmd/user_list.go +0 -44
  120. package/cmd/user_list_test.go +0 -126
  121. package/cmd/user_show.go +0 -40
  122. package/cmd/user_show_test.go +0 -110
  123. package/cmd/user_update.go +0 -71
  124. package/cmd/user_update_test.go +0 -177
  125. package/go.mod +0 -31
  126. package/go.sum +0 -53
  127. package/internal/api/boards.go +0 -93
  128. package/internal/api/cards.go +0 -322
  129. package/internal/api/client.go +0 -99
  130. package/internal/api/columns.go +0 -113
  131. package/internal/api/comments.go +0 -108
  132. package/internal/api/identity.go +0 -24
  133. package/internal/api/notifications.go +0 -89
  134. package/internal/api/reactions.go +0 -130
  135. package/internal/api/steps.go +0 -101
  136. package/internal/api/tags.go +0 -24
  137. package/internal/api/types.go +0 -195
  138. package/internal/api/users.go +0 -75
  139. package/internal/app/app.go +0 -49
  140. package/internal/colors/colors.go +0 -32
  141. package/internal/config/config.go +0 -70
  142. package/internal/testutil/client.go +0 -26
  143. package/internal/ui/account_list.go +0 -14
  144. package/internal/ui/account_selector.go +0 -63
  145. package/internal/ui/board_list.go +0 -14
  146. package/internal/ui/board_show.go +0 -17
  147. package/internal/ui/card_list.go +0 -14
  148. package/internal/ui/card_show.go +0 -23
  149. package/internal/ui/column_list.go +0 -28
  150. package/internal/ui/column_show.go +0 -16
  151. package/internal/ui/comment_list.go +0 -25
  152. package/internal/ui/format.go +0 -27
  153. package/internal/ui/notification_list.go +0 -27
  154. package/internal/ui/reaction_list.go +0 -14
  155. package/internal/ui/user_list.go +0 -19
  156. package/internal/ui/user_show.go +0 -23
@@ -1,109 +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 TestTagListCommand(t *testing.T) {
16
- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
17
- if r.URL.Path != "/tags" {
18
- t.Errorf("expected /tags, 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.Tag{
31
- {
32
- ID: "tag-123",
33
- Title: "bug",
34
- CreatedAt: "2025-01-01T00:00:00Z",
35
- URL: "http://fizzy.localhost:3006/897362094/cards?tag_ids[]=tag-123",
36
- },
37
- {
38
- ID: "tag-456",
39
- Title: "feature",
40
- CreatedAt: "2025-01-02T00:00:00Z",
41
- URL: "http://fizzy.localhost:3006/897362094/cards?tag_ids[]=tag-456",
42
- },
43
- }
44
- json.NewEncoder(w).Encode(response)
45
- }))
46
- defer server.Close()
47
-
48
- client := testutil.NewTestClient(server.URL, "", "", "test-token")
49
- testApp := &app.App{Client: client}
50
-
51
- cmd := tagListCmd
52
- cmd.SetContext(testApp.ToContext(context.Background()))
53
-
54
- if err := handleListTags(cmd); err != nil {
55
- t.Fatalf("handleListTags failed: %v", err)
56
- }
57
- }
58
-
59
- func TestTagListCommandNoTags(t *testing.T) {
60
- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
61
- w.Header().Set("Content-Type", "application/json")
62
- w.Write([]byte("[]"))
63
- }))
64
- defer server.Close()
65
-
66
- client := testutil.NewTestClient(server.URL, "", "", "test-token")
67
- testApp := &app.App{Client: client}
68
-
69
- cmd := tagListCmd
70
- cmd.SetContext(testApp.ToContext(context.Background()))
71
-
72
- if err := handleListTags(cmd); err != nil {
73
- t.Fatalf("handleListTags with no tags failed: %v", err)
74
- }
75
- }
76
-
77
- func TestTagListCommandAPIError(t *testing.T) {
78
- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
79
- w.WriteHeader(http.StatusInternalServerError)
80
- w.Write([]byte("Internal Server Error"))
81
- }))
82
- defer server.Close()
83
-
84
- client := testutil.NewTestClient(server.URL, "", "", "test-token")
85
- testApp := &app.App{Client: client}
86
-
87
- cmd := tagListCmd
88
- cmd.SetContext(testApp.ToContext(context.Background()))
89
-
90
- err := handleListTags(cmd)
91
- if err == nil {
92
- t.Errorf("expected error for API failure")
93
- }
94
- }
95
-
96
- func TestTagListCommandNoClient(t *testing.T) {
97
- testApp := &app.App{}
98
-
99
- cmd := tagListCmd
100
- cmd.SetContext(testApp.ToContext(context.Background()))
101
-
102
- err := handleListTags(cmd)
103
- if err == nil {
104
- t.Errorf("expected error when client not available")
105
- }
106
- if err.Error() != "API client not available" {
107
- t.Errorf("expected 'client not available' error, got %v", err)
108
- }
109
- }
package/cmd/use.go DELETED
@@ -1,85 +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/config"
9
- "github.com/spf13/cobra"
10
- )
11
-
12
- var useCmd = &cobra.Command{
13
- Use: "use",
14
- Short: "Set the active board or account",
15
- Long: `Set the active board or account to use for subsequent commands`,
16
- Run: func(cmd *cobra.Command, args []string) {
17
- if err := handleUse(cmd); err != nil {
18
- fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
19
- }
20
- },
21
- }
22
-
23
- func handleUse(cmd *cobra.Command) error {
24
- board, _ := cmd.Flags().GetString("board")
25
- account, _ := cmd.Flags().GetString("account")
26
-
27
- if board == "" && account == "" {
28
- return fmt.Errorf("must specify either --board or --account")
29
- }
30
-
31
- if board != "" && account != "" {
32
- return fmt.Errorf("cannot specify both --board and --account")
33
- }
34
-
35
- cfg, err := config.Load()
36
- if err != nil {
37
- return fmt.Errorf("loading config: %w", err)
38
- }
39
-
40
- if board != "" {
41
- a := app.FromContext(cmd.Context())
42
- if a == nil || a.Client == nil {
43
- return fmt.Errorf("API client not available")
44
- }
45
-
46
- boards, err := a.Client.GetBoards(context.Background())
47
- if err != nil {
48
- return fmt.Errorf("fetching boards: %w", err)
49
- }
50
-
51
- var boardID string
52
- for _, b := range boards {
53
- if b.Name == board {
54
- boardID = b.ID
55
- break
56
- }
57
- }
58
-
59
- if boardID == "" {
60
- return fmt.Errorf("board '%s' not found", board)
61
- }
62
-
63
- cfg.SelectedBoard = boardID
64
- if err := cfg.Save(); err != nil {
65
- return fmt.Errorf("saving config: %w", err)
66
- }
67
- fmt.Printf("Selected board: %s\n", board)
68
- }
69
-
70
- if account != "" {
71
- cfg.SelectedAccount = account
72
- if err := cfg.Save(); err != nil {
73
- return fmt.Errorf("saving config: %w", err)
74
- }
75
- fmt.Printf("Selected account: %s\n", account)
76
- }
77
-
78
- return nil
79
- }
80
-
81
- func init() {
82
- rootCmd.AddCommand(useCmd)
83
- useCmd.Flags().String("board", "", "Board name to use")
84
- useCmd.Flags().String("account", "", "Account slug to use")
85
- }
package/cmd/use_test.go DELETED
@@ -1,186 +0,0 @@
1
- package cmd
2
-
3
- import (
4
- "context"
5
- "encoding/json"
6
- "fmt"
7
- "net/http"
8
- "net/http/httptest"
9
- "testing"
10
-
11
- "github.com/rogeriopvl/fizzy/internal/api"
12
- "github.com/rogeriopvl/fizzy/internal/app"
13
- "github.com/rogeriopvl/fizzy/internal/config"
14
- "github.com/rogeriopvl/fizzy/internal/testutil"
15
- "github.com/spf13/cobra"
16
- )
17
-
18
- func newUseCmd() *cobra.Command {
19
- cmd := &cobra.Command{
20
- Use: "use",
21
- Short: "Set the active board or account",
22
- Long: `Set the active board or account to use for subsequent commands`,
23
- Run: func(cmd *cobra.Command, args []string) {
24
- if err := handleUse(cmd); err != nil {
25
- fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
26
- }
27
- },
28
- }
29
- cmd.Flags().String("board", "", "Board name to use")
30
- cmd.Flags().String("account", "", "Account slug to use")
31
- return cmd
32
- }
33
-
34
- func TestUseCommandSetBoard(t *testing.T) {
35
- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
36
- if r.URL.Path != "/boards" {
37
- t.Errorf("expected /boards, got %s", r.URL.Path)
38
- }
39
- if r.Method != http.MethodGet {
40
- t.Errorf("expected GET, got %s", r.Method)
41
- }
42
-
43
- auth := r.Header.Get("Authorization")
44
- if auth == "" {
45
- t.Error("missing Authorization header")
46
- }
47
- if auth != "Bearer test-token" {
48
- t.Errorf("expected Bearer test-token, got %s", auth)
49
- }
50
-
51
- w.Header().Set("Content-Type", "application/json")
52
- response := []api.Board{
53
- {
54
- ID: "board-123",
55
- Name: "My Project",
56
- },
57
- {
58
- ID: "board-456",
59
- Name: "Other Board",
60
- },
61
- }
62
- json.NewEncoder(w).Encode(response)
63
- }))
64
- defer server.Close()
65
-
66
- tmpDir := t.TempDir()
67
- t.Setenv("HOME", tmpDir)
68
-
69
- client := testutil.NewTestClient(server.URL, "", "", "test-token")
70
- cfg := &config.Config{}
71
- testApp := &app.App{
72
- Client: client,
73
- Config: cfg,
74
- }
75
-
76
- cmd := newUseCmd()
77
- cmd.SetContext(testApp.ToContext(context.Background()))
78
- cmd.ParseFlags([]string{"--board", "My Project"})
79
-
80
- if err := handleUse(cmd); err != nil {
81
- t.Fatalf("handleUse failed: %v", err)
82
- }
83
-
84
- savedCfg, err := config.Load()
85
- if err != nil {
86
- t.Fatalf("failed to load config: %v", err)
87
- }
88
-
89
- if savedCfg.SelectedBoard != "board-123" {
90
- t.Errorf("expected SelectedBoard=board-123, got %s", savedCfg.SelectedBoard)
91
- }
92
- }
93
-
94
- func TestUseCommandSetAccount(t *testing.T) {
95
- tmpDir := t.TempDir()
96
- t.Setenv("HOME", tmpDir)
97
-
98
- cmd := newUseCmd()
99
- cmd.ParseFlags([]string{"--account", "my-company"})
100
-
101
- cfg := &config.Config{}
102
- testApp := &app.App{Config: cfg}
103
- cmd.SetContext(testApp.ToContext(context.Background()))
104
-
105
- if err := handleUse(cmd); err != nil {
106
- t.Fatalf("handleUse failed: %v", err)
107
- }
108
-
109
- savedCfg, err := config.Load()
110
- if err != nil {
111
- t.Fatalf("failed to load config: %v", err)
112
- }
113
-
114
- if savedCfg.SelectedAccount != "my-company" {
115
- t.Errorf("expected SelectedAccount=my-company, got %s", savedCfg.SelectedAccount)
116
- }
117
- }
118
-
119
- func TestUseCommandBoardNotFound(t *testing.T) {
120
- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
121
- if r.Method != http.MethodGet {
122
- t.Errorf("expected GET, got %s", r.Method)
123
- }
124
-
125
- auth := r.Header.Get("Authorization")
126
- if auth != "Bearer test-token" {
127
- t.Errorf("expected Bearer test-token, got %s", auth)
128
- }
129
-
130
- w.Header().Set("Content-Type", "application/json")
131
- response := []api.Board{
132
- {ID: "board-123", Name: "Existing Board"},
133
- }
134
- json.NewEncoder(w).Encode(response)
135
- }))
136
- defer server.Close()
137
-
138
- tmpDir := t.TempDir()
139
- t.Setenv("HOME", tmpDir)
140
-
141
- client := testutil.NewTestClient(server.URL, "", "", "test-token")
142
- testApp := &app.App{
143
- Client: client,
144
- Config: &config.Config{},
145
- }
146
-
147
- cmd := newUseCmd()
148
- cmd.SetContext(testApp.ToContext(context.Background()))
149
- cmd.ParseFlags([]string{"--board", "Nonexistent Board"})
150
-
151
- err := handleUse(cmd)
152
- if err == nil {
153
- t.Errorf("expected error for nonexistent board")
154
- }
155
- if err.Error() != "board 'Nonexistent Board' not found" {
156
- t.Errorf("expected 'not found' error, got %v", err)
157
- }
158
- }
159
-
160
- func TestUseCommandBothFlagsError(t *testing.T) {
161
- cmd := newUseCmd()
162
- cmd.ParseFlags([]string{"--board", "Board", "--account", "Account"})
163
- cmd.SetContext(context.Background())
164
-
165
- err := handleUse(cmd)
166
- if err == nil {
167
- t.Errorf("expected error when both flags provided")
168
- }
169
- if err.Error() != "cannot specify both --board and --account" {
170
- t.Errorf("expected 'both flags' error, got %v", err)
171
- }
172
- }
173
-
174
- func TestUseCommandNoFlagsError(t *testing.T) {
175
- cmd := newUseCmd()
176
- cmd.SetContext(context.Background())
177
- cmd.ParseFlags([]string{})
178
-
179
- err := handleUse(cmd)
180
- if err == nil {
181
- t.Errorf("expected error when no flags provided")
182
- }
183
- if err.Error() != "must specify either --board or --account" {
184
- t.Errorf("expected 'no flags' error, got %v", err)
185
- }
186
- }
package/cmd/user.go DELETED
@@ -1,22 +0,0 @@
1
- // Package cmd
2
- package cmd
3
-
4
- import (
5
- "github.com/spf13/cobra"
6
- )
7
-
8
- var userCmd = &cobra.Command{
9
- Use: "user",
10
- Short: "Manage users",
11
- Long: `Manage users in your account.
12
-
13
- Use subcommands to list, view, or manage users:
14
- fizzy user list List all users
15
- fizzy user show <id> Show user details
16
- fizzy user update <id> Update user settings
17
- fizzy user deactivate <id> Deactivate a user`,
18
- }
19
-
20
- func init() {
21
- rootCmd.AddCommand(userCmd)
22
- }
@@ -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 userDeactivateCmd = &cobra.Command{
12
- Use: "deactivate <user_id>",
13
- Short: "Deactivate a user",
14
- Long: `Deactivate a user. Only account administrators can deactivate users.`,
15
- Args: cobra.ExactArgs(1),
16
- Run: func(cmd *cobra.Command, args []string) {
17
- if err := handleDeactivateUser(cmd, args[0]); err != nil {
18
- fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
19
- }
20
- },
21
- }
22
-
23
- func handleDeactivateUser(cmd *cobra.Command, userID 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.DeleteUser(context.Background(), userID)
30
- if err != nil {
31
- return fmt.Errorf("deactivating user: %w", err)
32
- }
33
-
34
- fmt.Fprintf(cmd.OutOrStdout(), "✓ User '%s' deactivated successfully\n", userID)
35
- return nil
36
- }
37
-
38
- func init() {
39
- userCmd.AddCommand(userDeactivateCmd)
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 TestUserDeactivateCommandSuccess(t *testing.T) {
14
- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
15
- if r.URL.Path != "/users/user-123" {
16
- t.Errorf("expected /users/user-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 := userDeactivateCmd
35
- cmd.SetContext(testApp.ToContext(context.Background()))
36
-
37
- if err := handleDeactivateUser(cmd, "user-123"); err != nil {
38
- t.Fatalf("handleDeactivateUser failed: %v", err)
39
- }
40
- }
41
-
42
- func TestUserDeactivateCommandNotFound(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("User 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 := userDeactivateCmd
53
- cmd.SetContext(testApp.ToContext(context.Background()))
54
-
55
- err := handleDeactivateUser(cmd, "nonexistent-user")
56
- if err == nil {
57
- t.Errorf("expected error for user not found")
58
- }
59
- if err.Error() != "deactivating user: unexpected status code 404: User not found" {
60
- t.Errorf("expected user not found error, got %v", err)
61
- }
62
- }
63
-
64
- func TestUserDeactivateCommandForbidden(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 deactivate this user"))
68
- }))
69
- defer server.Close()
70
-
71
- client := testutil.NewTestClient(server.URL, "", "", "test-token")
72
- testApp := &app.App{Client: client}
73
-
74
- cmd := userDeactivateCmd
75
- cmd.SetContext(testApp.ToContext(context.Background()))
76
-
77
- err := handleDeactivateUser(cmd, "user-123")
78
- if err == nil {
79
- t.Errorf("expected error for forbidden access")
80
- }
81
- if err.Error() != "deactivating user: unexpected status code 403: You don't have permission to deactivate this user" {
82
- t.Errorf("expected permission error, got %v", err)
83
- }
84
- }
85
-
86
- func TestUserDeactivateCommandAPIError(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 := userDeactivateCmd
97
- cmd.SetContext(testApp.ToContext(context.Background()))
98
-
99
- err := handleDeactivateUser(cmd, "user-123")
100
- if err == nil {
101
- t.Errorf("expected error for API failure")
102
- }
103
- if err.Error() != "deactivating user: unexpected status code 500: Internal Server Error" {
104
- t.Errorf("expected API error, got %v", err)
105
- }
106
- }
107
-
108
- func TestUserDeactivateCommandNoClient(t *testing.T) {
109
- testApp := &app.App{}
110
-
111
- cmd := userDeactivateCmd
112
- cmd.SetContext(testApp.ToContext(context.Background()))
113
-
114
- err := handleDeactivateUser(cmd, "user-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/user_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 userListCmd = &cobra.Command{
13
- Use: "list",
14
- Short: "List all users",
15
- Long: `Retrieve and display all users from the current account`,
16
- Run: func(cmd *cobra.Command, args []string) {
17
- if err := handleListUsers(cmd); err != nil {
18
- fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
19
- }
20
- },
21
- }
22
-
23
- func handleListUsers(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
- users, err := a.Client.GetUsers(context.Background())
30
- if err != nil {
31
- return fmt.Errorf("fetching users: %w", err)
32
- }
33
-
34
- if len(users) == 0 {
35
- fmt.Println("No users found")
36
- return nil
37
- }
38
-
39
- return ui.DisplayUsers(cmd.OutOrStdout(), users)
40
- }
41
-
42
- func init() {
43
- userCmd.AddCommand(userListCmd)
44
- }