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.
- package/.golangci.yml +56 -0
- package/IMPLEMENTATION_PLAN.md +58 -0
- package/docs/API.md +89 -0
- 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/card_not_now_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 TestCardNotNowCommandSuccess(t *testing.T) {
|
|
14
|
-
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
15
|
-
if r.URL.Path != "/cards/123/not_now" {
|
|
16
|
-
t.Errorf("expected /cards/123/not_now, got %s", r.URL.Path)
|
|
17
|
-
}
|
|
18
|
-
if r.Method != http.MethodPost {
|
|
19
|
-
t.Errorf("expected POST, 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 := cardNotNowCmd
|
|
35
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
36
|
-
|
|
37
|
-
if err := handleNotNowCard(cmd, "123"); err != nil {
|
|
38
|
-
t.Fatalf("handleNotNowCard failed: %v", err)
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
func TestCardNotNowCommandInvalidCardNumber(t *testing.T) {
|
|
43
|
-
testApp := &app.App{}
|
|
44
|
-
|
|
45
|
-
cmd := cardNotNowCmd
|
|
46
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
47
|
-
|
|
48
|
-
err := handleNotNowCard(cmd, "not-a-number")
|
|
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 TestCardNotNowCommandNoClient(t *testing.T) {
|
|
58
|
-
testApp := &app.App{}
|
|
59
|
-
|
|
60
|
-
cmd := cardNotNowCmd
|
|
61
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
62
|
-
|
|
63
|
-
err := handleNotNowCard(cmd, "123")
|
|
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 TestCardNotNowCommandAPIError(t *testing.T) {
|
|
73
|
-
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
74
|
-
w.WriteHeader(http.StatusInternalServerError)
|
|
75
|
-
w.Write([]byte("Internal Server Error"))
|
|
76
|
-
}))
|
|
77
|
-
defer server.Close()
|
|
78
|
-
|
|
79
|
-
client := testutil.NewTestClient(server.URL, "", "", "test-token")
|
|
80
|
-
testApp := &app.App{Client: client}
|
|
81
|
-
|
|
82
|
-
cmd := cardNotNowCmd
|
|
83
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
84
|
-
|
|
85
|
-
err := handleNotNowCard(cmd, "123")
|
|
86
|
-
if err == nil {
|
|
87
|
-
t.Errorf("expected error for API failure")
|
|
88
|
-
}
|
|
89
|
-
if err.Error() != "moving card to not now: unexpected status code 500: Internal Server Error" {
|
|
90
|
-
t.Errorf("expected API error, got %v", err)
|
|
91
|
-
}
|
|
92
|
-
}
|
package/cmd/card_reaction.go
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
package cmd
|
|
2
|
-
|
|
3
|
-
import "github.com/spf13/cobra"
|
|
4
|
-
|
|
5
|
-
var cardReactionCmd = &cobra.Command{
|
|
6
|
-
Use: "reaction",
|
|
7
|
-
Short: "Manage card reactions",
|
|
8
|
-
Long: `Manage reactions (boosts) on cards in Fizzy`,
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
func init() {
|
|
12
|
-
cardCmd.AddCommand(cardReactionCmd)
|
|
13
|
-
}
|
|
@@ -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 cardReactionCreateCmd = &cobra.Command{
|
|
13
|
-
Use: "create <card_number> <emoji>",
|
|
14
|
-
Short: "Create a reaction on a card",
|
|
15
|
-
Long: `Create an emoji reaction (boost) on a card`,
|
|
16
|
-
Args: cobra.ExactArgs(2),
|
|
17
|
-
Run: func(cmd *cobra.Command, args []string) {
|
|
18
|
-
if err := handleCreateCardReaction(cmd, args[0], args[1]); err != nil {
|
|
19
|
-
fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
func handleCreateCardReaction(cmd *cobra.Command, cardNumber, emoji 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.PostCardReaction(context.Background(), cardNum, emoji)
|
|
36
|
-
if err != nil {
|
|
37
|
-
return fmt.Errorf("creating reaction: %w", err)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
fmt.Fprintf(cmd.OutOrStdout(), "✓ Reaction %s created successfully\n", emoji)
|
|
41
|
-
return nil
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
func init() {
|
|
45
|
-
cardReactionCmd.AddCommand(cardReactionCreateCmd)
|
|
46
|
-
}
|
|
@@ -1,148 +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 TestCardReactionCreateCommandSuccess(t *testing.T) {
|
|
17
|
-
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
18
|
-
if r.URL.Path != "/cards/123/reactions" {
|
|
19
|
-
t.Errorf("expected /cards/123/reactions, 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
|
-
body, _ := io.ReadAll(r.Body)
|
|
31
|
-
var payload map[string]map[string]string
|
|
32
|
-
if err := json.Unmarshal(body, &payload); err != nil {
|
|
33
|
-
t.Fatalf("failed to unmarshal request body: %v", err)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
reactionPayload := payload["reaction"]
|
|
37
|
-
if reactionPayload["content"] != "👍" {
|
|
38
|
-
t.Errorf("expected content '👍', got %s", reactionPayload["content"])
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
w.Header().Set("Content-Type", "application/json")
|
|
42
|
-
w.WriteHeader(http.StatusCreated)
|
|
43
|
-
response := api.Reaction{
|
|
44
|
-
ID: "reaction-123",
|
|
45
|
-
Content: "👍",
|
|
46
|
-
Reacter: api.User{ID: "user-1", Name: "John Doe"},
|
|
47
|
-
}
|
|
48
|
-
json.NewEncoder(w).Encode(response)
|
|
49
|
-
}))
|
|
50
|
-
defer server.Close()
|
|
51
|
-
|
|
52
|
-
client := testutil.NewTestClient(server.URL, "", "", "test-token")
|
|
53
|
-
testApp := &app.App{Client: client}
|
|
54
|
-
|
|
55
|
-
cmd := cardReactionCreateCmd
|
|
56
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
57
|
-
|
|
58
|
-
if err := handleCreateCardReaction(cmd, "123", "👍"); err != nil {
|
|
59
|
-
t.Fatalf("handleCreateCardReaction failed: %v", err)
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
func TestCardReactionCreateCommandInvalidCardNumber(t *testing.T) {
|
|
64
|
-
testApp := &app.App{}
|
|
65
|
-
|
|
66
|
-
cmd := cardReactionCreateCmd
|
|
67
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
68
|
-
|
|
69
|
-
err := handleCreateCardReaction(cmd, "not-a-number", "👍")
|
|
70
|
-
if err == nil {
|
|
71
|
-
t.Errorf("expected error for invalid card number")
|
|
72
|
-
}
|
|
73
|
-
if err.Error() != "invalid card number: strconv.Atoi: parsing \"not-a-number\": invalid syntax" {
|
|
74
|
-
t.Errorf("expected invalid card number error, got %v", err)
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
func TestCardReactionCreateCommandNoClient(t *testing.T) {
|
|
79
|
-
testApp := &app.App{}
|
|
80
|
-
|
|
81
|
-
cmd := cardReactionCreateCmd
|
|
82
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
83
|
-
|
|
84
|
-
err := handleCreateCardReaction(cmd, "123", "👍")
|
|
85
|
-
if err == nil {
|
|
86
|
-
t.Errorf("expected error when client not available")
|
|
87
|
-
}
|
|
88
|
-
if err.Error() != "API client not available" {
|
|
89
|
-
t.Errorf("expected 'client not available' error, got %v", err)
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
func TestCardReactionCreateCommandAPIError(t *testing.T) {
|
|
94
|
-
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
95
|
-
w.WriteHeader(http.StatusNotFound)
|
|
96
|
-
w.Write([]byte("Card not found"))
|
|
97
|
-
}))
|
|
98
|
-
defer server.Close()
|
|
99
|
-
|
|
100
|
-
client := testutil.NewTestClient(server.URL, "", "", "test-token")
|
|
101
|
-
testApp := &app.App{Client: client}
|
|
102
|
-
|
|
103
|
-
cmd := cardReactionCreateCmd
|
|
104
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
105
|
-
|
|
106
|
-
err := handleCreateCardReaction(cmd, "123", "👍")
|
|
107
|
-
if err == nil {
|
|
108
|
-
t.Errorf("expected error for API failure")
|
|
109
|
-
}
|
|
110
|
-
if err.Error() != "creating reaction: unexpected status code 404: Card not found" {
|
|
111
|
-
t.Errorf("expected API error, got %v", err)
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
func TestCardReactionCreateCommandDifferentEmoji(t *testing.T) {
|
|
116
|
-
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
117
|
-
body, _ := io.ReadAll(r.Body)
|
|
118
|
-
var payload map[string]map[string]string
|
|
119
|
-
if err := json.Unmarshal(body, &payload); err != nil {
|
|
120
|
-
t.Fatalf("failed to unmarshal request body: %v", err)
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
reactionPayload := payload["reaction"]
|
|
124
|
-
if reactionPayload["content"] != "🎉" {
|
|
125
|
-
t.Errorf("expected content '🎉', got %s", reactionPayload["content"])
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
w.Header().Set("Content-Type", "application/json")
|
|
129
|
-
w.WriteHeader(http.StatusCreated)
|
|
130
|
-
response := api.Reaction{
|
|
131
|
-
ID: "reaction-456",
|
|
132
|
-
Content: "🎉",
|
|
133
|
-
Reacter: api.User{ID: "user-2", Name: "Jane Doe"},
|
|
134
|
-
}
|
|
135
|
-
json.NewEncoder(w).Encode(response)
|
|
136
|
-
}))
|
|
137
|
-
defer server.Close()
|
|
138
|
-
|
|
139
|
-
client := testutil.NewTestClient(server.URL, "", "", "test-token")
|
|
140
|
-
testApp := &app.App{Client: client}
|
|
141
|
-
|
|
142
|
-
cmd := cardReactionCreateCmd
|
|
143
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
144
|
-
|
|
145
|
-
if err := handleCreateCardReaction(cmd, "123", "🎉"); err != nil {
|
|
146
|
-
t.Fatalf("handleCreateCardReaction failed: %v", err)
|
|
147
|
-
}
|
|
148
|
-
}
|
|
@@ -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 cardReactionDeleteCmd = &cobra.Command{
|
|
13
|
-
Use: "delete <card_number> <reaction_id>",
|
|
14
|
-
Short: "Delete a reaction from a card",
|
|
15
|
-
Long: `Remove your reaction (boost) from a card`,
|
|
16
|
-
Args: cobra.ExactArgs(2),
|
|
17
|
-
Run: func(cmd *cobra.Command, args []string) {
|
|
18
|
-
if err := handleDeleteCardReaction(cmd, args[0], args[1]); err != nil {
|
|
19
|
-
fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
func handleDeleteCardReaction(cmd *cobra.Command, cardNumber, reactionID 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.DeleteCardReaction(context.Background(), cardNum, reactionID)
|
|
36
|
-
if err != nil {
|
|
37
|
-
return fmt.Errorf("deleting reaction: %w", err)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
fmt.Fprintf(cmd.OutOrStdout(), "✓ Reaction deleted successfully\n")
|
|
41
|
-
return nil
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
func init() {
|
|
45
|
-
cardReactionCmd.AddCommand(cardReactionDeleteCmd)
|
|
46
|
-
}
|
|
@@ -1,112 +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 TestCardReactionDeleteCommandSuccess(t *testing.T) {
|
|
14
|
-
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
15
|
-
if r.URL.Path != "/cards/123/reactions/reaction-456" {
|
|
16
|
-
t.Errorf("expected /cards/123/reactions/reaction-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 := cardReactionDeleteCmd
|
|
35
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
36
|
-
|
|
37
|
-
if err := handleDeleteCardReaction(cmd, "123", "reaction-456"); err != nil {
|
|
38
|
-
t.Fatalf("handleDeleteCardReaction failed: %v", err)
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
func TestCardReactionDeleteCommandInvalidCardNumber(t *testing.T) {
|
|
43
|
-
testApp := &app.App{}
|
|
44
|
-
|
|
45
|
-
cmd := cardReactionDeleteCmd
|
|
46
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
47
|
-
|
|
48
|
-
err := handleDeleteCardReaction(cmd, "not-a-number", "reaction-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 TestCardReactionDeleteCommandNoClient(t *testing.T) {
|
|
58
|
-
testApp := &app.App{}
|
|
59
|
-
|
|
60
|
-
cmd := cardReactionDeleteCmd
|
|
61
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
62
|
-
|
|
63
|
-
err := handleDeleteCardReaction(cmd, "123", "reaction-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 TestCardReactionDeleteCommandAPIError(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("Reaction 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 := cardReactionDeleteCmd
|
|
83
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
84
|
-
|
|
85
|
-
err := handleDeleteCardReaction(cmd, "123", "reaction-456")
|
|
86
|
-
if err == nil {
|
|
87
|
-
t.Errorf("expected error for API failure")
|
|
88
|
-
}
|
|
89
|
-
if err.Error() != "deleting reaction: unexpected status code 404: Reaction not found" {
|
|
90
|
-
t.Errorf("expected API error, got %v", err)
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
func TestCardReactionDeleteCommandDifferentReactionID(t *testing.T) {
|
|
95
|
-
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
96
|
-
if r.URL.Path != "/cards/456/reactions/reaction-789" {
|
|
97
|
-
t.Errorf("expected /cards/456/reactions/reaction-789, got %s", r.URL.Path)
|
|
98
|
-
}
|
|
99
|
-
w.WriteHeader(http.StatusNoContent)
|
|
100
|
-
}))
|
|
101
|
-
defer server.Close()
|
|
102
|
-
|
|
103
|
-
client := testutil.NewTestClient(server.URL, "", "", "test-token")
|
|
104
|
-
testApp := &app.App{Client: client}
|
|
105
|
-
|
|
106
|
-
cmd := cardReactionDeleteCmd
|
|
107
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
108
|
-
|
|
109
|
-
if err := handleDeleteCardReaction(cmd, "456", "reaction-789"); err != nil {
|
|
110
|
-
t.Fatalf("handleDeleteCardReaction failed: %v", err)
|
|
111
|
-
}
|
|
112
|
-
}
|
|
@@ -1,51 +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/rogeriopvl/fizzy/internal/ui"
|
|
10
|
-
"github.com/spf13/cobra"
|
|
11
|
-
)
|
|
12
|
-
|
|
13
|
-
var cardReactionListCmd = &cobra.Command{
|
|
14
|
-
Use: "list <card_number>",
|
|
15
|
-
Short: "List reactions on a card",
|
|
16
|
-
Long: `Retrieve and display all reactions (boosts) on a card`,
|
|
17
|
-
Args: cobra.ExactArgs(1),
|
|
18
|
-
Run: func(cmd *cobra.Command, args []string) {
|
|
19
|
-
if err := handleListCardReactions(cmd, args[0]); err != nil {
|
|
20
|
-
fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
func handleListCardReactions(cmd *cobra.Command, cardNumber string) error {
|
|
26
|
-
cardNum, err := strconv.Atoi(cardNumber)
|
|
27
|
-
if err != nil {
|
|
28
|
-
return fmt.Errorf("invalid card number: %w", err)
|
|
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
|
-
reactions, err := a.Client.GetCardReactions(context.Background(), cardNum)
|
|
37
|
-
if err != nil {
|
|
38
|
-
return fmt.Errorf("fetching reactions: %w", err)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if len(reactions) == 0 {
|
|
42
|
-
fmt.Println("No reactions found")
|
|
43
|
-
return nil
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return ui.DisplayReactions(reactions)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
func init() {
|
|
50
|
-
cardReactionCmd.AddCommand(cardReactionListCmd)
|
|
51
|
-
}
|
|
@@ -1,127 +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 TestCardReactionListCommandSuccess(t *testing.T) {
|
|
16
|
-
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
17
|
-
if r.URL.Path != "/cards/123/reactions" {
|
|
18
|
-
t.Errorf("expected /cards/123/reactions, 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
|
-
w.WriteHeader(http.StatusOK)
|
|
31
|
-
reactions := []api.Reaction{
|
|
32
|
-
{
|
|
33
|
-
ID: "reaction-1",
|
|
34
|
-
Content: "👍",
|
|
35
|
-
Reacter: api.User{ID: "user-1", Name: "Alice"},
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
ID: "reaction-2",
|
|
39
|
-
Content: "🎉",
|
|
40
|
-
Reacter: api.User{ID: "user-2", Name: "Bob"},
|
|
41
|
-
},
|
|
42
|
-
}
|
|
43
|
-
json.NewEncoder(w).Encode(reactions)
|
|
44
|
-
}))
|
|
45
|
-
defer server.Close()
|
|
46
|
-
|
|
47
|
-
client := testutil.NewTestClient(server.URL, "", "", "test-token")
|
|
48
|
-
testApp := &app.App{Client: client}
|
|
49
|
-
|
|
50
|
-
cmd := cardReactionListCmd
|
|
51
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
52
|
-
|
|
53
|
-
if err := handleListCardReactions(cmd, "123"); err != nil {
|
|
54
|
-
t.Fatalf("handleListCardReactions failed: %v", err)
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
func TestCardReactionListCommandNoReactions(t *testing.T) {
|
|
59
|
-
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
60
|
-
w.Header().Set("Content-Type", "application/json")
|
|
61
|
-
w.WriteHeader(http.StatusOK)
|
|
62
|
-
json.NewEncoder(w).Encode([]api.Reaction{})
|
|
63
|
-
}))
|
|
64
|
-
defer server.Close()
|
|
65
|
-
|
|
66
|
-
client := testutil.NewTestClient(server.URL, "", "", "test-token")
|
|
67
|
-
testApp := &app.App{Client: client}
|
|
68
|
-
|
|
69
|
-
cmd := cardReactionListCmd
|
|
70
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
71
|
-
|
|
72
|
-
if err := handleListCardReactions(cmd, "123"); err != nil {
|
|
73
|
-
t.Fatalf("handleListCardReactions failed: %v", err)
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
func TestCardReactionListCommandInvalidCardNumber(t *testing.T) {
|
|
78
|
-
testApp := &app.App{}
|
|
79
|
-
|
|
80
|
-
cmd := cardReactionListCmd
|
|
81
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
82
|
-
|
|
83
|
-
err := handleListCardReactions(cmd, "not-a-number")
|
|
84
|
-
if err == nil {
|
|
85
|
-
t.Errorf("expected error for invalid card number")
|
|
86
|
-
}
|
|
87
|
-
if err.Error() != "invalid card number: strconv.Atoi: parsing \"not-a-number\": invalid syntax" {
|
|
88
|
-
t.Errorf("expected invalid card number error, got %v", err)
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
func TestCardReactionListCommandNoClient(t *testing.T) {
|
|
93
|
-
testApp := &app.App{}
|
|
94
|
-
|
|
95
|
-
cmd := cardReactionListCmd
|
|
96
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
97
|
-
|
|
98
|
-
err := handleListCardReactions(cmd, "123")
|
|
99
|
-
if err == nil {
|
|
100
|
-
t.Errorf("expected error when client not available")
|
|
101
|
-
}
|
|
102
|
-
if err.Error() != "API client not available" {
|
|
103
|
-
t.Errorf("expected 'client not available' error, got %v", err)
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
func TestCardReactionListCommandAPIError(t *testing.T) {
|
|
108
|
-
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
109
|
-
w.WriteHeader(http.StatusNotFound)
|
|
110
|
-
w.Write([]byte("Card not found"))
|
|
111
|
-
}))
|
|
112
|
-
defer server.Close()
|
|
113
|
-
|
|
114
|
-
client := testutil.NewTestClient(server.URL, "", "", "test-token")
|
|
115
|
-
testApp := &app.App{Client: client}
|
|
116
|
-
|
|
117
|
-
cmd := cardReactionListCmd
|
|
118
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
119
|
-
|
|
120
|
-
err := handleListCardReactions(cmd, "123")
|
|
121
|
-
if err == nil {
|
|
122
|
-
t.Errorf("expected error for API failure")
|
|
123
|
-
}
|
|
124
|
-
if err.Error() != "fetching reactions: unexpected status code 404: Card not found" {
|
|
125
|
-
t.Errorf("expected API error, got %v", err)
|
|
126
|
-
}
|
|
127
|
-
}
|
package/cmd/card_reopen.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 cardReopenCmd = &cobra.Command{
|
|
13
|
-
Use: "reopen <card_number>",
|
|
14
|
-
Short: "Reopen a card",
|
|
15
|
-
Long: `Reopen an existing closed card`,
|
|
16
|
-
Args: cobra.ExactArgs(1),
|
|
17
|
-
Run: func(cmd *cobra.Command, args []string) {
|
|
18
|
-
if err := handleReopenCard(cmd, args[0]); err != nil {
|
|
19
|
-
fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
func handleReopenCard(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.DeleteCardsClosure(context.Background(), cardNum)
|
|
36
|
-
if err != nil {
|
|
37
|
-
return fmt.Errorf("reopening card: %w", err)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
fmt.Fprintf(cmd.OutOrStdout(), "✓ Card #%d reopened successfully\n", cardNum)
|
|
41
|
-
return nil
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
func init() {
|
|
45
|
-
cardCmd.AddCommand(cardReopenCmd)
|
|
46
|
-
}
|