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/step_create_test.go
DELETED
|
@@ -1,171 +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 TestStepCreateCommandSuccess(t *testing.T) {
|
|
17
|
-
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
18
|
-
if r.URL.Path != "/cards/123/steps" {
|
|
19
|
-
t.Errorf("expected /cards/123/steps, 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]map[string]any
|
|
36
|
-
if err := json.Unmarshal(body, &payload); err != nil {
|
|
37
|
-
t.Fatalf("failed to unmarshal request body: %v", err)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
stepPayload := payload["step"]
|
|
41
|
-
if stepPayload["content"] != "Write tests" {
|
|
42
|
-
t.Errorf("expected content 'Write tests', got %v", stepPayload["content"])
|
|
43
|
-
}
|
|
44
|
-
if stepPayload["completed"] != false {
|
|
45
|
-
t.Errorf("expected completed false, got %v", stepPayload["completed"])
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
w.Header().Set("Content-Type", "application/json")
|
|
49
|
-
w.WriteHeader(http.StatusCreated)
|
|
50
|
-
response := api.Step{
|
|
51
|
-
ID: "step-789",
|
|
52
|
-
Content: "Write tests",
|
|
53
|
-
Completed: false,
|
|
54
|
-
}
|
|
55
|
-
json.NewEncoder(w).Encode(response)
|
|
56
|
-
}))
|
|
57
|
-
defer server.Close()
|
|
58
|
-
|
|
59
|
-
client := testutil.NewTestClient(server.URL, "", "", "test-token")
|
|
60
|
-
testApp := &app.App{Client: client}
|
|
61
|
-
|
|
62
|
-
cmd := stepCreateCmd
|
|
63
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
64
|
-
cmd.ParseFlags([]string{
|
|
65
|
-
"--content", "Write tests",
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
if err := handleCreateStep(cmd, "123"); err != nil {
|
|
69
|
-
t.Fatalf("handleCreateStep failed: %v", err)
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
func TestStepCreateCommandWithCompleted(t *testing.T) {
|
|
74
|
-
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
75
|
-
body, _ := io.ReadAll(r.Body)
|
|
76
|
-
var payload map[string]map[string]any
|
|
77
|
-
if err := json.Unmarshal(body, &payload); err != nil {
|
|
78
|
-
t.Fatalf("failed to unmarshal request body: %v", err)
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
stepPayload := payload["step"]
|
|
82
|
-
if stepPayload["completed"] != true {
|
|
83
|
-
t.Errorf("expected completed true, got %v", stepPayload["completed"])
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
w.Header().Set("Content-Type", "application/json")
|
|
87
|
-
w.WriteHeader(http.StatusCreated)
|
|
88
|
-
response := api.Step{
|
|
89
|
-
ID: "step-789",
|
|
90
|
-
Content: "Already done",
|
|
91
|
-
Completed: true,
|
|
92
|
-
}
|
|
93
|
-
json.NewEncoder(w).Encode(response)
|
|
94
|
-
}))
|
|
95
|
-
defer server.Close()
|
|
96
|
-
|
|
97
|
-
client := testutil.NewTestClient(server.URL, "", "", "test-token")
|
|
98
|
-
testApp := &app.App{Client: client}
|
|
99
|
-
|
|
100
|
-
cmd := stepCreateCmd
|
|
101
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
102
|
-
cmd.ParseFlags([]string{
|
|
103
|
-
"--content", "Already done",
|
|
104
|
-
"--completed",
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
if err := handleCreateStep(cmd, "123"); err != nil {
|
|
108
|
-
t.Fatalf("handleCreateStep failed: %v", err)
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
func TestStepCreateCommandInvalidCardNumber(t *testing.T) {
|
|
113
|
-
testApp := &app.App{}
|
|
114
|
-
|
|
115
|
-
cmd := stepCreateCmd
|
|
116
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
117
|
-
cmd.ParseFlags([]string{
|
|
118
|
-
"--content", "Test step",
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
err := handleCreateStep(cmd, "not-a-number")
|
|
122
|
-
if err == nil {
|
|
123
|
-
t.Errorf("expected error for invalid card number")
|
|
124
|
-
}
|
|
125
|
-
if err.Error() != "invalid card number: strconv.Atoi: parsing \"not-a-number\": invalid syntax" {
|
|
126
|
-
t.Errorf("expected invalid card number error, got %v", err)
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
func TestStepCreateCommandNoClient(t *testing.T) {
|
|
131
|
-
testApp := &app.App{}
|
|
132
|
-
|
|
133
|
-
cmd := stepCreateCmd
|
|
134
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
135
|
-
cmd.ParseFlags([]string{
|
|
136
|
-
"--content", "Test step",
|
|
137
|
-
})
|
|
138
|
-
|
|
139
|
-
err := handleCreateStep(cmd, "123")
|
|
140
|
-
if err == nil {
|
|
141
|
-
t.Errorf("expected error when client not available")
|
|
142
|
-
}
|
|
143
|
-
if err.Error() != "API client not available" {
|
|
144
|
-
t.Errorf("expected 'client not available' error, got %v", err)
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
func TestStepCreateCommandAPIError(t *testing.T) {
|
|
149
|
-
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
150
|
-
w.WriteHeader(http.StatusInternalServerError)
|
|
151
|
-
w.Write([]byte("Internal Server Error"))
|
|
152
|
-
}))
|
|
153
|
-
defer server.Close()
|
|
154
|
-
|
|
155
|
-
client := testutil.NewTestClient(server.URL, "", "", "test-token")
|
|
156
|
-
testApp := &app.App{Client: client}
|
|
157
|
-
|
|
158
|
-
cmd := stepCreateCmd
|
|
159
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
160
|
-
cmd.ParseFlags([]string{
|
|
161
|
-
"--content", "Test step",
|
|
162
|
-
})
|
|
163
|
-
|
|
164
|
-
err := handleCreateStep(cmd, "123")
|
|
165
|
-
if err == nil {
|
|
166
|
-
t.Errorf("expected error for API failure")
|
|
167
|
-
}
|
|
168
|
-
if err.Error() != "creating step: unexpected status code 500: Internal Server Error" {
|
|
169
|
-
t.Errorf("expected API error, got %v", err)
|
|
170
|
-
}
|
|
171
|
-
}
|
package/cmd/step_delete.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 stepDeleteCmd = &cobra.Command{
|
|
13
|
-
Use: "delete <card_number> <step_id>",
|
|
14
|
-
Short: "Delete a step",
|
|
15
|
-
Long: `Delete a step from a card`,
|
|
16
|
-
Args: cobra.ExactArgs(2),
|
|
17
|
-
Run: func(cmd *cobra.Command, args []string) {
|
|
18
|
-
if err := handleDeleteStep(cmd, args[0], args[1]); err != nil {
|
|
19
|
-
fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
func handleDeleteStep(cmd *cobra.Command, cardNumber, stepID 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.DeleteCardStep(context.Background(), cardNum, stepID)
|
|
36
|
-
if err != nil {
|
|
37
|
-
return fmt.Errorf("deleting step: %w", err)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
fmt.Fprintf(cmd.OutOrStdout(), "✓ Step deleted successfully\n")
|
|
41
|
-
return nil
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
func init() {
|
|
45
|
-
stepCmd.AddCommand(stepDeleteCmd)
|
|
46
|
-
}
|
package/cmd/step_delete_test.go
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
package cmd
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
"context"
|
|
5
|
-
"net/http"
|
|
6
|
-
"net/http/httptest"
|
|
7
|
-
"testing"
|
|
8
|
-
|
|
9
|
-
"github.com/rogeriopvl/fizzy/internal/app"
|
|
10
|
-
"github.com/rogeriopvl/fizzy/internal/testutil"
|
|
11
|
-
)
|
|
12
|
-
|
|
13
|
-
func TestStepDeleteCommandSuccess(t *testing.T) {
|
|
14
|
-
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
15
|
-
if r.URL.Path != "/cards/123/steps/step-456" {
|
|
16
|
-
t.Errorf("expected /cards/123/steps/step-456, 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 := stepDeleteCmd
|
|
35
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
36
|
-
|
|
37
|
-
if err := handleDeleteStep(cmd, "123", "step-456"); err != nil {
|
|
38
|
-
t.Fatalf("handleDeleteStep failed: %v", err)
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
func TestStepDeleteCommandInvalidCardNumber(t *testing.T) {
|
|
43
|
-
testApp := &app.App{}
|
|
44
|
-
|
|
45
|
-
cmd := stepDeleteCmd
|
|
46
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
47
|
-
|
|
48
|
-
err := handleDeleteStep(cmd, "not-a-number", "step-456")
|
|
49
|
-
if err == nil {
|
|
50
|
-
t.Errorf("expected error for invalid card number")
|
|
51
|
-
}
|
|
52
|
-
if err.Error() != "invalid card number: strconv.Atoi: parsing \"not-a-number\": invalid syntax" {
|
|
53
|
-
t.Errorf("expected invalid card number error, got %v", err)
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
func TestStepDeleteCommandNoClient(t *testing.T) {
|
|
58
|
-
testApp := &app.App{}
|
|
59
|
-
|
|
60
|
-
cmd := stepDeleteCmd
|
|
61
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
62
|
-
|
|
63
|
-
err := handleDeleteStep(cmd, "123", "step-456")
|
|
64
|
-
if err == nil {
|
|
65
|
-
t.Errorf("expected error when client not available")
|
|
66
|
-
}
|
|
67
|
-
if err.Error() != "API client not available" {
|
|
68
|
-
t.Errorf("expected 'client not available' error, got %v", err)
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
func TestStepDeleteCommandAPIError(t *testing.T) {
|
|
73
|
-
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
74
|
-
w.WriteHeader(http.StatusNotFound)
|
|
75
|
-
w.Write([]byte("Step not found"))
|
|
76
|
-
}))
|
|
77
|
-
defer server.Close()
|
|
78
|
-
|
|
79
|
-
client := testutil.NewTestClient(server.URL, "", "", "test-token")
|
|
80
|
-
testApp := &app.App{Client: client}
|
|
81
|
-
|
|
82
|
-
cmd := stepDeleteCmd
|
|
83
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
84
|
-
|
|
85
|
-
err := handleDeleteStep(cmd, "123", "step-456")
|
|
86
|
-
if err == nil {
|
|
87
|
-
t.Errorf("expected error for API failure")
|
|
88
|
-
}
|
|
89
|
-
if err.Error() != "deleting step: unexpected status code 404: Step not found" {
|
|
90
|
-
t.Errorf("expected API error, got %v", err)
|
|
91
|
-
}
|
|
92
|
-
}
|
package/cmd/step_update.go
DELETED
|
@@ -1,66 +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 stepUpdateCmd = &cobra.Command{
|
|
13
|
-
Use: "update <card_number> <step_id>",
|
|
14
|
-
Short: "Update an existing step",
|
|
15
|
-
Long: `Update the content or completion status of an existing step on a card`,
|
|
16
|
-
Args: cobra.ExactArgs(2),
|
|
17
|
-
Run: func(cmd *cobra.Command, args []string) {
|
|
18
|
-
if err := handleUpdateStep(cmd, args[0], args[1]); err != nil {
|
|
19
|
-
fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
func handleUpdateStep(cmd *cobra.Command, cardNumber, stepID 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
|
-
var contentPtr *string
|
|
36
|
-
var completedPtr *bool
|
|
37
|
-
|
|
38
|
-
if cmd.Flags().Changed("content") {
|
|
39
|
-
content, _ := cmd.Flags().GetString("content")
|
|
40
|
-
contentPtr = &content
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if cmd.Flags().Changed("completed") {
|
|
44
|
-
completed, _ := cmd.Flags().GetBool("completed")
|
|
45
|
-
completedPtr = &completed
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if contentPtr == nil && completedPtr == nil {
|
|
49
|
-
return fmt.Errorf("at least one of --content or --completed must be provided")
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
step, err := a.Client.PutCardStep(context.Background(), cardNum, stepID, contentPtr, completedPtr)
|
|
53
|
-
if err != nil {
|
|
54
|
-
return fmt.Errorf("updating step: %w", err)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
fmt.Fprintf(cmd.OutOrStdout(), "✓ Step updated successfully (id: %s)\n", step.ID)
|
|
58
|
-
return nil
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
func init() {
|
|
62
|
-
stepUpdateCmd.Flags().StringP("content", "c", "", "New step content")
|
|
63
|
-
stepUpdateCmd.Flags().BoolP("completed", "d", false, "Mark step as completed")
|
|
64
|
-
|
|
65
|
-
stepCmd.AddCommand(stepUpdateCmd)
|
|
66
|
-
}
|
package/cmd/step_update_test.go
DELETED
|
@@ -1,190 +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 TestStepUpdateCommandSuccess(t *testing.T) {
|
|
18
|
-
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
19
|
-
if r.URL.Path != "/cards/123/steps/step-456" {
|
|
20
|
-
t.Errorf("expected /cards/123/steps/step-456, 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
|
-
if r.Header.Get("Content-Type") != "application/json" {
|
|
32
|
-
t.Errorf("expected Content-Type: application/json, got %s", r.Header.Get("Content-Type"))
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
body, _ := io.ReadAll(r.Body)
|
|
36
|
-
var payload map[string]map[string]any
|
|
37
|
-
if err := json.Unmarshal(body, &payload); err != nil {
|
|
38
|
-
t.Fatalf("failed to unmarshal request body: %v", err)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
stepPayload := payload["step"]
|
|
42
|
-
if stepPayload["content"] != "Updated step text" {
|
|
43
|
-
t.Errorf("expected content 'Updated step text', got %v", stepPayload["content"])
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
w.Header().Set("Content-Type", "application/json")
|
|
47
|
-
response := api.Step{
|
|
48
|
-
ID: "step-456",
|
|
49
|
-
Content: "Updated step text",
|
|
50
|
-
Completed: false,
|
|
51
|
-
}
|
|
52
|
-
json.NewEncoder(w).Encode(response)
|
|
53
|
-
}))
|
|
54
|
-
defer server.Close()
|
|
55
|
-
|
|
56
|
-
client := testutil.NewTestClient(server.URL, "", "", "test-token")
|
|
57
|
-
testApp := &app.App{Client: client}
|
|
58
|
-
|
|
59
|
-
cmd := stepUpdateCmd
|
|
60
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
61
|
-
cmd.ParseFlags([]string{
|
|
62
|
-
"--content", "Updated step text",
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
if err := handleUpdateStep(cmd, "123", "step-456"); err != nil {
|
|
66
|
-
t.Fatalf("handleUpdateStep failed: %v", err)
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
func TestStepUpdateCommandWithCompleted(t *testing.T) {
|
|
71
|
-
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
72
|
-
body, _ := io.ReadAll(r.Body)
|
|
73
|
-
var payload map[string]map[string]any
|
|
74
|
-
if err := json.Unmarshal(body, &payload); err != nil {
|
|
75
|
-
t.Fatalf("failed to unmarshal request body: %v", err)
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
stepPayload := payload["step"]
|
|
79
|
-
if stepPayload["completed"] != true {
|
|
80
|
-
t.Errorf("expected completed true, got %v", stepPayload["completed"])
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
w.Header().Set("Content-Type", "application/json")
|
|
84
|
-
response := api.Step{
|
|
85
|
-
ID: "step-456",
|
|
86
|
-
Content: "Some step",
|
|
87
|
-
Completed: true,
|
|
88
|
-
}
|
|
89
|
-
json.NewEncoder(w).Encode(response)
|
|
90
|
-
}))
|
|
91
|
-
defer server.Close()
|
|
92
|
-
|
|
93
|
-
client := testutil.NewTestClient(server.URL, "", "", "test-token")
|
|
94
|
-
testApp := &app.App{Client: client}
|
|
95
|
-
|
|
96
|
-
cmd := stepUpdateCmd
|
|
97
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
98
|
-
cmd.ParseFlags([]string{
|
|
99
|
-
"--completed",
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
if err := handleUpdateStep(cmd, "123", "step-456"); err != nil {
|
|
103
|
-
t.Fatalf("handleUpdateStep failed: %v", err)
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
func TestStepUpdateCommandNoFlags(t *testing.T) {
|
|
108
|
-
testApp := &app.App{Client: testutil.NewTestClient("http://localhost", "", "", "test-token")}
|
|
109
|
-
|
|
110
|
-
cmd := stepUpdateCmd
|
|
111
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
112
|
-
// Reset flags to ensure no flags are set
|
|
113
|
-
cmd.Flags().Set("content", "")
|
|
114
|
-
cmd.Flags().Set("completed", "false")
|
|
115
|
-
|
|
116
|
-
// Create a fresh command to avoid flag state from other tests
|
|
117
|
-
freshCmd := &cobra.Command{}
|
|
118
|
-
freshCmd.Flags().StringP("content", "c", "", "New step content")
|
|
119
|
-
freshCmd.Flags().BoolP("completed", "d", false, "Mark step as completed")
|
|
120
|
-
freshCmd.SetContext(testApp.ToContext(context.Background()))
|
|
121
|
-
|
|
122
|
-
err := handleUpdateStep(freshCmd, "123", "step-456")
|
|
123
|
-
if err == nil {
|
|
124
|
-
t.Errorf("expected error when no flags provided")
|
|
125
|
-
}
|
|
126
|
-
if err.Error() != "at least one of --content or --completed must be provided" {
|
|
127
|
-
t.Errorf("expected 'at least one flag' error, got %v", err)
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
func TestStepUpdateCommandInvalidCardNumber(t *testing.T) {
|
|
132
|
-
testApp := &app.App{}
|
|
133
|
-
|
|
134
|
-
cmd := stepUpdateCmd
|
|
135
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
136
|
-
cmd.ParseFlags([]string{
|
|
137
|
-
"--content", "Updated text",
|
|
138
|
-
})
|
|
139
|
-
|
|
140
|
-
err := handleUpdateStep(cmd, "not-a-number", "step-456")
|
|
141
|
-
if err == nil {
|
|
142
|
-
t.Errorf("expected error for invalid card number")
|
|
143
|
-
}
|
|
144
|
-
if err.Error() != "invalid card number: strconv.Atoi: parsing \"not-a-number\": invalid syntax" {
|
|
145
|
-
t.Errorf("expected invalid card number error, got %v", err)
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
func TestStepUpdateCommandNoClient(t *testing.T) {
|
|
150
|
-
testApp := &app.App{}
|
|
151
|
-
|
|
152
|
-
cmd := stepUpdateCmd
|
|
153
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
154
|
-
cmd.ParseFlags([]string{
|
|
155
|
-
"--content", "Updated text",
|
|
156
|
-
})
|
|
157
|
-
|
|
158
|
-
err := handleUpdateStep(cmd, "123", "step-456")
|
|
159
|
-
if err == nil {
|
|
160
|
-
t.Errorf("expected error when client not available")
|
|
161
|
-
}
|
|
162
|
-
if err.Error() != "API client not available" {
|
|
163
|
-
t.Errorf("expected 'client not available' error, got %v", err)
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
func TestStepUpdateCommandAPIError(t *testing.T) {
|
|
168
|
-
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
169
|
-
w.WriteHeader(http.StatusNotFound)
|
|
170
|
-
w.Write([]byte("Step not found"))
|
|
171
|
-
}))
|
|
172
|
-
defer server.Close()
|
|
173
|
-
|
|
174
|
-
client := testutil.NewTestClient(server.URL, "", "", "test-token")
|
|
175
|
-
testApp := &app.App{Client: client}
|
|
176
|
-
|
|
177
|
-
cmd := stepUpdateCmd
|
|
178
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
179
|
-
cmd.ParseFlags([]string{
|
|
180
|
-
"--content", "Updated text",
|
|
181
|
-
})
|
|
182
|
-
|
|
183
|
-
err := handleUpdateStep(cmd, "123", "step-456")
|
|
184
|
-
if err == nil {
|
|
185
|
-
t.Errorf("expected error for API failure")
|
|
186
|
-
}
|
|
187
|
-
if err.Error() != "updating step: unexpected status code 404: Step not found" {
|
|
188
|
-
t.Errorf("expected API error, got %v", err)
|
|
189
|
-
}
|
|
190
|
-
}
|
package/cmd/tag.go
DELETED
package/cmd/tag_list.go
DELETED
|
@@ -1,47 +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 tagListCmd = &cobra.Command{
|
|
12
|
-
Use: "list",
|
|
13
|
-
Short: "List all tags",
|
|
14
|
-
Long: `Retrieve and display all tags in the account`,
|
|
15
|
-
Run: func(cmd *cobra.Command, args []string) {
|
|
16
|
-
if err := handleListTags(cmd); err != nil {
|
|
17
|
-
fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
func handleListTags(cmd *cobra.Command) error {
|
|
23
|
-
a := app.FromContext(cmd.Context())
|
|
24
|
-
if a == nil || a.Client == nil {
|
|
25
|
-
return fmt.Errorf("API client not available")
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
tags, err := a.Client.GetTags(context.Background())
|
|
29
|
-
if err != nil {
|
|
30
|
-
return fmt.Errorf("fetching tags: %w", err)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if len(tags) == 0 {
|
|
34
|
-
fmt.Println("No tags found")
|
|
35
|
-
return nil
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
for _, tag := range tags {
|
|
39
|
-
fmt.Printf("%s\n", tag.Title)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return nil
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
func init() {
|
|
46
|
-
tagCmd.AddCommand(tagListCmd)
|
|
47
|
-
}
|