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.
- package/package.json +2 -1
- package/.env +0 -1
- package/.github/workflows/release.yml +0 -29
- package/.github/workflows/tests.yml +0 -24
- package/AGENTS.md +0 -33
- package/CHANGELOG.md +0 -194
- package/Makefile +0 -43
- package/bin/fizzy +0 -0
- package/cmd/account.go +0 -14
- package/cmd/account_list.go +0 -44
- package/cmd/account_list_test.go +0 -118
- package/cmd/board.go +0 -49
- package/cmd/board_create.go +0 -59
- package/cmd/board_create_test.go +0 -141
- package/cmd/board_delete.go +0 -40
- package/cmd/board_delete_test.go +0 -121
- package/cmd/board_list.go +0 -44
- package/cmd/board_list_test.go +0 -115
- package/cmd/board_show.go +0 -40
- package/cmd/board_show_test.go +0 -113
- package/cmd/board_test.go +0 -92
- package/cmd/board_update.go +0 -72
- package/cmd/board_update_test.go +0 -233
- package/cmd/card.go +0 -24
- package/cmd/card_assign.go +0 -55
- package/cmd/card_assign_test.go +0 -130
- package/cmd/card_close.go +0 -46
- package/cmd/card_close_test.go +0 -92
- package/cmd/card_create.go +0 -72
- package/cmd/card_create_test.go +0 -186
- package/cmd/card_delete.go +0 -46
- package/cmd/card_delete_test.go +0 -92
- package/cmd/card_golden.go +0 -46
- package/cmd/card_golden_test.go +0 -92
- package/cmd/card_list.go +0 -114
- package/cmd/card_list_test.go +0 -373
- package/cmd/card_not_now.go +0 -46
- package/cmd/card_not_now_test.go +0 -92
- package/cmd/card_reaction.go +0 -13
- package/cmd/card_reaction_create.go +0 -46
- package/cmd/card_reaction_create_test.go +0 -148
- package/cmd/card_reaction_delete.go +0 -46
- package/cmd/card_reaction_delete_test.go +0 -112
- package/cmd/card_reaction_list.go +0 -51
- package/cmd/card_reaction_list_test.go +0 -127
- package/cmd/card_reopen.go +0 -46
- package/cmd/card_reopen_test.go +0 -92
- package/cmd/card_show.go +0 -46
- package/cmd/card_show_test.go +0 -92
- package/cmd/card_tag.go +0 -51
- package/cmd/card_tag_test.go +0 -112
- package/cmd/card_triage.go +0 -46
- package/cmd/card_ungolden.go +0 -46
- package/cmd/card_ungolden_test.go +0 -92
- package/cmd/card_untriage.go +0 -46
- package/cmd/card_untriage_test.go +0 -92
- package/cmd/card_unwatch.go +0 -46
- package/cmd/card_unwatch_test.go +0 -92
- package/cmd/card_update.go +0 -82
- package/cmd/card_update_test.go +0 -149
- package/cmd/card_watch.go +0 -46
- package/cmd/card_watch_test.go +0 -92
- package/cmd/column.go +0 -14
- package/cmd/column_create.go +0 -79
- package/cmd/column_create_test.go +0 -178
- package/cmd/column_delete.go +0 -40
- package/cmd/column_delete_test.go +0 -121
- package/cmd/column_list.go +0 -44
- package/cmd/column_list_test.go +0 -138
- package/cmd/column_show.go +0 -40
- package/cmd/column_show_test.go +0 -111
- package/cmd/column_update.go +0 -67
- package/cmd/column_update_test.go +0 -198
- package/cmd/comment.go +0 -14
- package/cmd/comment_create.go +0 -51
- package/cmd/comment_create_test.go +0 -129
- package/cmd/comment_delete.go +0 -46
- package/cmd/comment_delete_test.go +0 -92
- package/cmd/comment_list.go +0 -51
- package/cmd/comment_list_test.go +0 -132
- package/cmd/comment_show.go +0 -46
- package/cmd/comment_show_test.go +0 -104
- package/cmd/comment_update.go +0 -51
- package/cmd/comment_update_test.go +0 -130
- package/cmd/login.go +0 -81
- package/cmd/login_test.go +0 -98
- package/cmd/notification.go +0 -14
- package/cmd/notification_list.go +0 -69
- package/cmd/notification_list_test.go +0 -288
- package/cmd/notification_read.go +0 -51
- package/cmd/notification_read_all.go +0 -38
- package/cmd/notification_read_all_test.go +0 -75
- package/cmd/notification_read_test.go +0 -138
- package/cmd/notification_unread.go +0 -44
- package/cmd/notification_unread_test.go +0 -99
- package/cmd/reaction.go +0 -13
- package/cmd/reaction_create.go +0 -46
- package/cmd/reaction_create_test.go +0 -113
- package/cmd/reaction_delete.go +0 -46
- package/cmd/reaction_delete_test.go +0 -92
- package/cmd/reaction_list.go +0 -51
- package/cmd/reaction_list_test.go +0 -125
- package/cmd/root.go +0 -38
- package/cmd/step.go +0 -14
- package/cmd/step_create.go +0 -53
- package/cmd/step_create_test.go +0 -171
- package/cmd/step_delete.go +0 -46
- package/cmd/step_delete_test.go +0 -92
- package/cmd/step_update.go +0 -66
- package/cmd/step_update_test.go +0 -190
- package/cmd/tag.go +0 -15
- package/cmd/tag_list.go +0 -47
- package/cmd/tag_list_test.go +0 -109
- package/cmd/use.go +0 -85
- package/cmd/use_test.go +0 -186
- package/cmd/user.go +0 -22
- package/cmd/user_deactivate.go +0 -40
- package/cmd/user_deactivate_test.go +0 -121
- package/cmd/user_list.go +0 -44
- package/cmd/user_list_test.go +0 -126
- package/cmd/user_show.go +0 -40
- package/cmd/user_show_test.go +0 -110
- package/cmd/user_update.go +0 -71
- package/cmd/user_update_test.go +0 -177
- package/go.mod +0 -31
- package/go.sum +0 -53
- package/internal/api/boards.go +0 -93
- package/internal/api/cards.go +0 -322
- package/internal/api/client.go +0 -99
- package/internal/api/columns.go +0 -113
- package/internal/api/comments.go +0 -108
- package/internal/api/identity.go +0 -24
- package/internal/api/notifications.go +0 -89
- package/internal/api/reactions.go +0 -130
- package/internal/api/steps.go +0 -101
- package/internal/api/tags.go +0 -24
- package/internal/api/types.go +0 -195
- package/internal/api/users.go +0 -75
- package/internal/app/app.go +0 -49
- package/internal/colors/colors.go +0 -32
- package/internal/config/config.go +0 -70
- package/internal/testutil/client.go +0 -26
- package/internal/ui/account_list.go +0 -14
- package/internal/ui/account_selector.go +0 -63
- package/internal/ui/board_list.go +0 -14
- package/internal/ui/board_show.go +0 -17
- package/internal/ui/card_list.go +0 -14
- package/internal/ui/card_show.go +0 -23
- package/internal/ui/column_list.go +0 -28
- package/internal/ui/column_show.go +0 -16
- package/internal/ui/comment_list.go +0 -25
- package/internal/ui/format.go +0 -27
- package/internal/ui/notification_list.go +0 -27
- package/internal/ui/reaction_list.go +0 -14
- package/internal/ui/user_list.go +0 -19
- package/internal/ui/user_show.go +0 -23
package/cmd/board_test.go
DELETED
|
@@ -1,92 +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/config"
|
|
13
|
-
"github.com/rogeriopvl/fizzy/internal/testutil"
|
|
14
|
-
)
|
|
15
|
-
|
|
16
|
-
func TestBoardCommand(t *testing.T) {
|
|
17
|
-
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
18
|
-
if r.URL.Path != "/boards/board-123" {
|
|
19
|
-
t.Errorf("expected /boards/board-123, got %s", r.URL.Path)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
w.Header().Set("Content-Type", "application/json")
|
|
23
|
-
response := api.Board{
|
|
24
|
-
ID: "board-123",
|
|
25
|
-
Name: "Test Board",
|
|
26
|
-
AllAccess: true,
|
|
27
|
-
CreatedAt: "2025-12-05T19:36:35.534Z",
|
|
28
|
-
}
|
|
29
|
-
json.NewEncoder(w).Encode(response)
|
|
30
|
-
}))
|
|
31
|
-
defer server.Close()
|
|
32
|
-
|
|
33
|
-
client := testutil.NewTestClient(server.URL, "", "", "test-token")
|
|
34
|
-
testApp := &app.App{
|
|
35
|
-
Client: client,
|
|
36
|
-
Config: &config.Config{
|
|
37
|
-
SelectedBoard: "board-123",
|
|
38
|
-
},
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
cmd := boardCmd
|
|
42
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
43
|
-
|
|
44
|
-
if err := handleShowBoard(cmd); err != nil {
|
|
45
|
-
t.Fatalf("handleShowBoard failed: %v", err)
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
func TestBoardCommandNoBoard(t *testing.T) {
|
|
50
|
-
client := testutil.NewTestClient("http://localhost", "", "", "test-token")
|
|
51
|
-
testApp := &app.App{
|
|
52
|
-
Client: client,
|
|
53
|
-
Config: &config.Config{
|
|
54
|
-
SelectedBoard: "",
|
|
55
|
-
},
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
cmd := boardCmd
|
|
59
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
60
|
-
|
|
61
|
-
err := handleShowBoard(cmd)
|
|
62
|
-
if err == nil {
|
|
63
|
-
t.Errorf("expected error when no board selected")
|
|
64
|
-
}
|
|
65
|
-
if err.Error() != "no board selected" {
|
|
66
|
-
t.Errorf("expected 'no board selected' error, got %v", err)
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
func TestBoardCommandAPIError(t *testing.T) {
|
|
71
|
-
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
72
|
-
w.WriteHeader(http.StatusInternalServerError)
|
|
73
|
-
w.Write([]byte("Internal Server Error"))
|
|
74
|
-
}))
|
|
75
|
-
defer server.Close()
|
|
76
|
-
|
|
77
|
-
client := testutil.NewTestClient(server.URL, "", "", "test-token")
|
|
78
|
-
testApp := &app.App{
|
|
79
|
-
Client: client,
|
|
80
|
-
Config: &config.Config{
|
|
81
|
-
SelectedBoard: "board-123",
|
|
82
|
-
},
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
cmd := boardCmd
|
|
86
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
87
|
-
|
|
88
|
-
err := handleShowBoard(cmd)
|
|
89
|
-
if err == nil {
|
|
90
|
-
t.Errorf("expected error for API failure")
|
|
91
|
-
}
|
|
92
|
-
}
|
package/cmd/board_update.go
DELETED
|
@@ -1,72 +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 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
|
-
}
|
package/cmd/board_update_test.go
DELETED
|
@@ -1,233 +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
|
-
"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
|
-
}
|
package/cmd/card.go
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
// Package cmd
|
|
2
|
-
package cmd
|
|
3
|
-
|
|
4
|
-
import "github.com/spf13/cobra"
|
|
5
|
-
|
|
6
|
-
var cardCmd = &cobra.Command{
|
|
7
|
-
Use: "card",
|
|
8
|
-
Short: "Manage cards",
|
|
9
|
-
Long: `Manage cards in Fizzy`,
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
func init() {
|
|
13
|
-
rootCmd.AddCommand(cardCmd)
|
|
14
|
-
|
|
15
|
-
// Here you will define your flags and configuration settings.
|
|
16
|
-
|
|
17
|
-
// Cobra supports Persistent Flags which will work for this command
|
|
18
|
-
// and all subcommands, e.g.:
|
|
19
|
-
// cardsCmd.PersistentFlags().String("foo", "", "A help for foo")
|
|
20
|
-
|
|
21
|
-
// Cobra supports local flags which will only run when this command
|
|
22
|
-
// is called directly, e.g.:
|
|
23
|
-
// cardsCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
|
24
|
-
}
|
package/cmd/card_assign.go
DELETED
|
@@ -1,55 +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 cardAssignCmd = &cobra.Command{
|
|
13
|
-
Use: "assign <card_number> <user_id>",
|
|
14
|
-
Short: "Assign a user to a card",
|
|
15
|
-
Long: `Assign or unassign a user to/from a card.
|
|
16
|
-
|
|
17
|
-
Use "me" as the user_id to assign the card to yourself.`,
|
|
18
|
-
Args: cobra.ExactArgs(2),
|
|
19
|
-
Run: func(cmd *cobra.Command, args []string) {
|
|
20
|
-
if err := handleAssignCard(cmd, args[0], args[1]); err != nil {
|
|
21
|
-
fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
func handleAssignCard(cmd *cobra.Command, cardNumber, userID string) error {
|
|
27
|
-
cardNum, err := strconv.Atoi(cardNumber)
|
|
28
|
-
if err != nil {
|
|
29
|
-
return fmt.Errorf("invalid card number: %w", err)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
a := app.FromContext(cmd.Context())
|
|
33
|
-
if a == nil || a.Client == nil {
|
|
34
|
-
return fmt.Errorf("API client not available")
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if userID == "me" {
|
|
38
|
-
if a.Config.CurrentUserID == "" {
|
|
39
|
-
return fmt.Errorf("current user ID not available, please run 'fizzy login' first")
|
|
40
|
-
}
|
|
41
|
-
userID = a.Config.CurrentUserID
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
_, err = a.Client.PostCardAssignments(context.Background(), cardNum, userID)
|
|
45
|
-
if err != nil {
|
|
46
|
-
return fmt.Errorf("assigning card: %w", err)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
fmt.Fprintf(cmd.OutOrStdout(), "✓ Card #%d assignment toggled for user %s\n", cardNum, userID)
|
|
50
|
-
return nil
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
func init() {
|
|
54
|
-
cardCmd.AddCommand(cardAssignCmd)
|
|
55
|
-
}
|
package/cmd/card_assign_test.go
DELETED
|
@@ -1,130 +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/config"
|
|
11
|
-
"github.com/rogeriopvl/fizzy/internal/testutil"
|
|
12
|
-
)
|
|
13
|
-
|
|
14
|
-
func TestCardAssignCommandSuccess(t *testing.T) {
|
|
15
|
-
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
16
|
-
if r.URL.Path != "/cards/123/assignments" {
|
|
17
|
-
t.Errorf("expected /cards/123/assignments, got %s", r.URL.Path)
|
|
18
|
-
}
|
|
19
|
-
if r.Method != http.MethodPost {
|
|
20
|
-
t.Errorf("expected POST, got %s", r.Method)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
auth := r.Header.Get("Authorization")
|
|
24
|
-
if auth != "Bearer test-token" {
|
|
25
|
-
t.Errorf("expected Bearer test-token, got %s", auth)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
w.WriteHeader(http.StatusNoContent)
|
|
29
|
-
}))
|
|
30
|
-
defer server.Close()
|
|
31
|
-
|
|
32
|
-
client := testutil.NewTestClient(server.URL, "", "", "test-token")
|
|
33
|
-
testApp := &app.App{Client: client}
|
|
34
|
-
|
|
35
|
-
cmd := cardAssignCmd
|
|
36
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
37
|
-
|
|
38
|
-
if err := handleAssignCard(cmd, "123", "user-id-123"); err != nil {
|
|
39
|
-
t.Fatalf("handleAssignCard failed: %v", err)
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
func TestCardAssignCommandWithMe(t *testing.T) {
|
|
44
|
-
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
45
|
-
if r.URL.Path != "/cards/123/assignments" {
|
|
46
|
-
t.Errorf("expected /cards/123/assignments, got %s", r.URL.Path)
|
|
47
|
-
}
|
|
48
|
-
w.WriteHeader(http.StatusNoContent)
|
|
49
|
-
}))
|
|
50
|
-
defer server.Close()
|
|
51
|
-
|
|
52
|
-
client := testutil.NewTestClient(server.URL, "", "", "test-token")
|
|
53
|
-
cfg := &config.Config{CurrentUserID: "my-user-id"}
|
|
54
|
-
testApp := &app.App{Client: client, Config: cfg}
|
|
55
|
-
|
|
56
|
-
cmd := cardAssignCmd
|
|
57
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
58
|
-
|
|
59
|
-
if err := handleAssignCard(cmd, "123", "me"); err != nil {
|
|
60
|
-
t.Fatalf("handleAssignCard with 'me' failed: %v", err)
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
func TestCardAssignCommandAPIError(t *testing.T) {
|
|
65
|
-
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
66
|
-
w.WriteHeader(http.StatusNotFound)
|
|
67
|
-
w.Write([]byte("Card not found"))
|
|
68
|
-
}))
|
|
69
|
-
defer server.Close()
|
|
70
|
-
|
|
71
|
-
client := testutil.NewTestClient(server.URL, "", "", "test-token")
|
|
72
|
-
testApp := &app.App{Client: client}
|
|
73
|
-
|
|
74
|
-
cmd := cardAssignCmd
|
|
75
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
76
|
-
|
|
77
|
-
err := handleAssignCard(cmd, "999", "user-id-123")
|
|
78
|
-
if err == nil {
|
|
79
|
-
t.Errorf("expected error for API failure")
|
|
80
|
-
}
|
|
81
|
-
if err.Error() != "assigning card: unexpected status code 404: Card not found" {
|
|
82
|
-
t.Errorf("expected API error, got %v", err)
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
func TestCardAssignCommandInvalidCardNumber(t *testing.T) {
|
|
87
|
-
testApp := &app.App{}
|
|
88
|
-
|
|
89
|
-
cmd := cardAssignCmd
|
|
90
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
91
|
-
|
|
92
|
-
err := handleAssignCard(cmd, "not-a-number", "user-id-123")
|
|
93
|
-
if err == nil {
|
|
94
|
-
t.Errorf("expected error for invalid card number")
|
|
95
|
-
}
|
|
96
|
-
if err.Error() != "invalid card number: strconv.Atoi: parsing \"not-a-number\": invalid syntax" {
|
|
97
|
-
t.Errorf("expected invalid card number error, got %v", err)
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
func TestCardAssignCommandNoClient(t *testing.T) {
|
|
102
|
-
testApp := &app.App{}
|
|
103
|
-
|
|
104
|
-
cmd := cardAssignCmd
|
|
105
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
106
|
-
|
|
107
|
-
err := handleAssignCard(cmd, "123", "user-id-123")
|
|
108
|
-
if err == nil {
|
|
109
|
-
t.Errorf("expected error when client not available")
|
|
110
|
-
}
|
|
111
|
-
if err.Error() != "API client not available" {
|
|
112
|
-
t.Errorf("expected 'client not available' error, got %v", err)
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
func TestCardAssignCommandMeWithoutUserID(t *testing.T) {
|
|
117
|
-
client := testutil.NewTestClient("http://localhost", "", "", "test-token")
|
|
118
|
-
testApp := &app.App{Client: client, Config: &config.Config{}}
|
|
119
|
-
|
|
120
|
-
cmd := cardAssignCmd
|
|
121
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
122
|
-
|
|
123
|
-
err := handleAssignCard(cmd, "123", "me")
|
|
124
|
-
if err == nil {
|
|
125
|
-
t.Errorf("expected error when using 'me' without current user ID")
|
|
126
|
-
}
|
|
127
|
-
if err.Error() != "current user ID not available, please run 'fizzy login' first" {
|
|
128
|
-
t.Errorf("expected 'current user ID not available' error, got %v", err)
|
|
129
|
-
}
|
|
130
|
-
}
|
package/cmd/card_close.go
DELETED
|
@@ -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 cardCloseCmd = &cobra.Command{
|
|
13
|
-
Use: "close <card_number>",
|
|
14
|
-
Short: "Close a card",
|
|
15
|
-
Long: `Close an existing card`,
|
|
16
|
-
Args: cobra.ExactArgs(1),
|
|
17
|
-
Run: func(cmd *cobra.Command, args []string) {
|
|
18
|
-
if err := handleCloseCard(cmd, args[0]); err != nil {
|
|
19
|
-
fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
func handleCloseCard(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.PostCardsClosure(context.Background(), cardNum)
|
|
36
|
-
if err != nil {
|
|
37
|
-
return fmt.Errorf("closing card: %w", err)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
fmt.Fprintf(cmd.OutOrStdout(), "✓ Card #%d closed successfully\n", cardNum)
|
|
41
|
-
return nil
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
func init() {
|
|
45
|
-
cardCmd.AddCommand(cardCloseCmd)
|
|
46
|
-
}
|