fizzy-cli 0.7.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/docs/API.md +63 -2
- package/package.json +2 -1
- package/.github/workflows/release.yml +0 -29
- package/.github/workflows/tests.yml +0 -24
- package/AGENTS.md +0 -33
- package/CHANGELOG.md +0 -168
- 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 -53
- package/cmd/card_list_test.go +0 -148
- package/cmd/card_not_now.go +0 -46
- package/cmd/card_not_now_test.go +0 -92
- 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/go.mod +0 -31
- package/go.sum +0 -53
- package/internal/api/boards.go +0 -93
- package/internal/api/cards.go +0 -288
- 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 -69
- package/internal/api/steps.go +0 -101
- package/internal/api/tags.go +0 -24
- package/internal/api/types.go +0 -190
- 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/cmd/card_close_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 TestCardCloseCommandSuccess(t *testing.T) {
|
|
14
|
-
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
15
|
-
if r.URL.Path != "/cards/123/closure" {
|
|
16
|
-
t.Errorf("expected /cards/123/closure, 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 := cardCloseCmd
|
|
35
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
36
|
-
|
|
37
|
-
if err := handleCloseCard(cmd, "123"); err != nil {
|
|
38
|
-
t.Fatalf("handleCloseCard failed: %v", err)
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
func TestCardCloseCommandInvalidCardNumber(t *testing.T) {
|
|
43
|
-
testApp := &app.App{}
|
|
44
|
-
|
|
45
|
-
cmd := cardCloseCmd
|
|
46
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
47
|
-
|
|
48
|
-
err := handleCloseCard(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 TestCardCloseCommandNoClient(t *testing.T) {
|
|
58
|
-
testApp := &app.App{}
|
|
59
|
-
|
|
60
|
-
cmd := cardCloseCmd
|
|
61
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
62
|
-
|
|
63
|
-
err := handleCloseCard(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 TestCardCloseCommandAPIError(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 := cardCloseCmd
|
|
83
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
84
|
-
|
|
85
|
-
err := handleCloseCard(cmd, "123")
|
|
86
|
-
if err == nil {
|
|
87
|
-
t.Errorf("expected error for API failure")
|
|
88
|
-
}
|
|
89
|
-
if err.Error() != "closing card: unexpected status code 500: Internal Server Error" {
|
|
90
|
-
t.Errorf("expected API error, got %v", err)
|
|
91
|
-
}
|
|
92
|
-
}
|
package/cmd/card_create.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 cardCreateCmd = &cobra.Command{
|
|
13
|
-
Use: "create",
|
|
14
|
-
Short: "Create a new card",
|
|
15
|
-
Long: `Create a new card in the selected board`,
|
|
16
|
-
Run: func(cmd *cobra.Command, args []string) {
|
|
17
|
-
if err := handleCreateCard(cmd); err != nil {
|
|
18
|
-
fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
func handleCreateCard(cmd *cobra.Command) error {
|
|
24
|
-
a := app.FromContext(cmd.Context())
|
|
25
|
-
if a == nil || a.Client == nil {
|
|
26
|
-
return fmt.Errorf("API client not available")
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if a.Config.SelectedBoard == "" {
|
|
30
|
-
return fmt.Errorf("no board selected")
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Read flag values directly from command
|
|
34
|
-
title, _ := cmd.Flags().GetString("title")
|
|
35
|
-
description, _ := cmd.Flags().GetString("description")
|
|
36
|
-
status, _ := cmd.Flags().GetString("status")
|
|
37
|
-
imageURL, _ := cmd.Flags().GetString("image-url")
|
|
38
|
-
tagIDs, _ := cmd.Flags().GetStringSlice("tag-id")
|
|
39
|
-
createdAt, _ := cmd.Flags().GetString("created-at")
|
|
40
|
-
lastActiveAt, _ := cmd.Flags().GetString("last-active-at")
|
|
41
|
-
|
|
42
|
-
payload := api.CreateCardPayload{
|
|
43
|
-
Title: title,
|
|
44
|
-
Description: description,
|
|
45
|
-
Status: status,
|
|
46
|
-
ImageURL: imageURL,
|
|
47
|
-
TagIDS: tagIDs,
|
|
48
|
-
CreatedAt: createdAt,
|
|
49
|
-
LastActiveAt: lastActiveAt,
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
_, err := a.Client.PostCards(context.Background(), payload)
|
|
53
|
-
if err != nil {
|
|
54
|
-
return fmt.Errorf("creating card: %w", err)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
fmt.Fprintf(cmd.OutOrStdout(), "✓ Card '%s' created successfully\n", title)
|
|
58
|
-
return nil
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
func init() {
|
|
62
|
-
cardCreateCmd.Flags().StringP("title", "t", "", "Card title (required)")
|
|
63
|
-
cardCreateCmd.MarkFlagRequired("title")
|
|
64
|
-
cardCreateCmd.Flags().StringP("description", "d", "", "Card description")
|
|
65
|
-
cardCreateCmd.Flags().String("status", "", "Card status")
|
|
66
|
-
cardCreateCmd.Flags().String("image-url", "", "Card image URL")
|
|
67
|
-
cardCreateCmd.Flags().StringSlice("tag-id", []string{}, "Tag ID (can be used multiple times)")
|
|
68
|
-
cardCreateCmd.Flags().String("created-at", "", "Creation timestamp")
|
|
69
|
-
cardCreateCmd.Flags().String("last-active-at", "", "Last active timestamp")
|
|
70
|
-
|
|
71
|
-
cardCmd.AddCommand(cardCreateCmd)
|
|
72
|
-
}
|
package/cmd/card_create_test.go
DELETED
|
@@ -1,186 +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/config"
|
|
14
|
-
"github.com/rogeriopvl/fizzy/internal/testutil"
|
|
15
|
-
)
|
|
16
|
-
|
|
17
|
-
func TestCardCreateCommandSuccess(t *testing.T) {
|
|
18
|
-
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
19
|
-
if r.URL.Path != "/boards/board-123/cards" {
|
|
20
|
-
t.Errorf("expected /boards/board-123/cards, got %s", r.URL.Path)
|
|
21
|
-
}
|
|
22
|
-
if r.Method != http.MethodPost {
|
|
23
|
-
t.Errorf("expected POST, 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]api.CreateCardPayload
|
|
37
|
-
if err := json.Unmarshal(body, &payload); err != nil {
|
|
38
|
-
t.Fatalf("failed to unmarshal request body: %v", err)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
cardPayload := payload["card"]
|
|
42
|
-
if cardPayload.Title != "Implement feature" {
|
|
43
|
-
t.Errorf("expected title 'Implement feature', got %s", cardPayload.Title)
|
|
44
|
-
}
|
|
45
|
-
if cardPayload.Description != "A detailed description" {
|
|
46
|
-
t.Errorf("expected description 'A detailed description', got %s", cardPayload.Description)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
w.WriteHeader(http.StatusCreated)
|
|
50
|
-
}))
|
|
51
|
-
defer server.Close()
|
|
52
|
-
|
|
53
|
-
client := testutil.NewTestClient(server.URL, "", "board-123", "test-token")
|
|
54
|
-
testApp := &app.App{
|
|
55
|
-
Client: client,
|
|
56
|
-
Config: &config.Config{SelectedBoard: "board-123"},
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
cmd := cardCreateCmd
|
|
60
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
61
|
-
cmd.ParseFlags([]string{
|
|
62
|
-
"--title", "Implement feature",
|
|
63
|
-
"--description", "A detailed description",
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
if err := handleCreateCard(cmd); err != nil {
|
|
67
|
-
t.Fatalf("handleCreateCard failed: %v", err)
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
func TestCardCreateCommandWithAllFields(t *testing.T) {
|
|
72
|
-
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
73
|
-
if r.Method != http.MethodPost {
|
|
74
|
-
t.Errorf("expected POST, got %s", r.Method)
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
body, _ := io.ReadAll(r.Body)
|
|
78
|
-
var payload map[string]api.CreateCardPayload
|
|
79
|
-
json.Unmarshal(body, &payload)
|
|
80
|
-
|
|
81
|
-
cardPayload := payload["card"]
|
|
82
|
-
if cardPayload.Title != "Fix bug" {
|
|
83
|
-
t.Errorf("expected title 'Fix bug', got %s", cardPayload.Title)
|
|
84
|
-
}
|
|
85
|
-
if cardPayload.Status != "in_progress" {
|
|
86
|
-
t.Errorf("expected status 'in_progress', got %s", cardPayload.Status)
|
|
87
|
-
}
|
|
88
|
-
if cardPayload.ImageURL != "https://example.com/image.jpg" {
|
|
89
|
-
t.Errorf("expected image URL 'https://example.com/image.jpg', got %s", cardPayload.ImageURL)
|
|
90
|
-
}
|
|
91
|
-
if len(cardPayload.TagIDS) != 2 || cardPayload.TagIDS[0] != "tag-1" || cardPayload.TagIDS[1] != "tag-2" {
|
|
92
|
-
t.Errorf("expected tag IDs [tag-1, tag-2], got %v", cardPayload.TagIDS)
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
w.WriteHeader(http.StatusCreated)
|
|
96
|
-
}))
|
|
97
|
-
defer server.Close()
|
|
98
|
-
|
|
99
|
-
client := testutil.NewTestClient(server.URL, "", "board-123", "test-token")
|
|
100
|
-
testApp := &app.App{
|
|
101
|
-
Client: client,
|
|
102
|
-
Config: &config.Config{SelectedBoard: "board-123"},
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
cmd := cardCreateCmd
|
|
106
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
107
|
-
cmd.ParseFlags([]string{
|
|
108
|
-
"--title", "Fix bug",
|
|
109
|
-
"--status", "in_progress",
|
|
110
|
-
"--image-url", "https://example.com/image.jpg",
|
|
111
|
-
"--tag-id", "tag-1",
|
|
112
|
-
"--tag-id", "tag-2",
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
if err := handleCreateCard(cmd); err != nil {
|
|
116
|
-
t.Fatalf("handleCreateCard failed: %v", err)
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
func TestCardCreateCommandNoBoard(t *testing.T) {
|
|
121
|
-
client := testutil.NewTestClient("http://localhost", "", "", "test-token")
|
|
122
|
-
testApp := &app.App{
|
|
123
|
-
Client: client,
|
|
124
|
-
Config: &config.Config{SelectedBoard: ""},
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
cmd := cardCreateCmd
|
|
128
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
129
|
-
cmd.ParseFlags([]string{
|
|
130
|
-
"--title", "Test",
|
|
131
|
-
})
|
|
132
|
-
|
|
133
|
-
err := handleCreateCard(cmd)
|
|
134
|
-
if err == nil {
|
|
135
|
-
t.Errorf("expected error when board not selected")
|
|
136
|
-
}
|
|
137
|
-
if err.Error() != "no board selected" {
|
|
138
|
-
t.Errorf("expected 'no board selected' error, got %v", err)
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
func TestCardCreateCommandNoClient(t *testing.T) {
|
|
143
|
-
testApp := &app.App{}
|
|
144
|
-
|
|
145
|
-
cmd := cardCreateCmd
|
|
146
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
147
|
-
cmd.ParseFlags([]string{
|
|
148
|
-
"--title", "Test",
|
|
149
|
-
})
|
|
150
|
-
|
|
151
|
-
err := handleCreateCard(cmd)
|
|
152
|
-
if err == nil {
|
|
153
|
-
t.Errorf("expected error when client not available")
|
|
154
|
-
}
|
|
155
|
-
if err.Error() != "API client not available" {
|
|
156
|
-
t.Errorf("expected 'client not available' error, got %v", err)
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
func TestCardCreateCommandAPIError(t *testing.T) {
|
|
161
|
-
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
162
|
-
w.WriteHeader(http.StatusInternalServerError)
|
|
163
|
-
w.Write([]byte("Internal Server Error"))
|
|
164
|
-
}))
|
|
165
|
-
defer server.Close()
|
|
166
|
-
|
|
167
|
-
client := testutil.NewTestClient(server.URL, "", "board-123", "test-token")
|
|
168
|
-
testApp := &app.App{
|
|
169
|
-
Client: client,
|
|
170
|
-
Config: &config.Config{SelectedBoard: "board-123"},
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
cmd := cardCreateCmd
|
|
174
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
175
|
-
cmd.ParseFlags([]string{
|
|
176
|
-
"--title", "Test",
|
|
177
|
-
})
|
|
178
|
-
|
|
179
|
-
err := handleCreateCard(cmd)
|
|
180
|
-
if err == nil {
|
|
181
|
-
t.Errorf("expected error for API failure")
|
|
182
|
-
}
|
|
183
|
-
if err.Error() != "creating card: unexpected status code 500: Internal Server Error" {
|
|
184
|
-
t.Errorf("expected API error, got %v", err)
|
|
185
|
-
}
|
|
186
|
-
}
|
package/cmd/card_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 cardDeleteCmd = &cobra.Command{
|
|
13
|
-
Use: "delete <card_number>",
|
|
14
|
-
Short: "Delete a card",
|
|
15
|
-
Long: `Delete an existing card permanently`,
|
|
16
|
-
Args: cobra.ExactArgs(1),
|
|
17
|
-
Run: func(cmd *cobra.Command, args []string) {
|
|
18
|
-
if err := handleDeleteCard(cmd, args[0]); err != nil {
|
|
19
|
-
fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
func handleDeleteCard(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.DeleteCard(context.Background(), cardNum)
|
|
36
|
-
if err != nil {
|
|
37
|
-
return fmt.Errorf("deleting card: %w", err)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
fmt.Fprintf(cmd.OutOrStdout(), "✓ Card #%d deleted successfully\n", cardNum)
|
|
41
|
-
return nil
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
func init() {
|
|
45
|
-
cardCmd.AddCommand(cardDeleteCmd)
|
|
46
|
-
}
|
package/cmd/card_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 TestCardDeleteCommand(t *testing.T) {
|
|
14
|
-
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
15
|
-
if r.URL.Path != "/cards/1" {
|
|
16
|
-
t.Errorf("expected /cards/1, 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 := cardDeleteCmd
|
|
35
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
36
|
-
|
|
37
|
-
if err := handleDeleteCard(cmd, "1"); err != nil {
|
|
38
|
-
t.Fatalf("handleDeleteCard failed: %v", err)
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
func TestCardDeleteCommandAPIError(t *testing.T) {
|
|
43
|
-
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
44
|
-
w.WriteHeader(http.StatusNotFound)
|
|
45
|
-
w.Write([]byte("Card not found"))
|
|
46
|
-
}))
|
|
47
|
-
defer server.Close()
|
|
48
|
-
|
|
49
|
-
client := testutil.NewTestClient(server.URL, "", "", "test-token")
|
|
50
|
-
testApp := &app.App{Client: client}
|
|
51
|
-
|
|
52
|
-
cmd := cardDeleteCmd
|
|
53
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
54
|
-
|
|
55
|
-
err := handleDeleteCard(cmd, "999")
|
|
56
|
-
if err == nil {
|
|
57
|
-
t.Errorf("expected error for API failure")
|
|
58
|
-
}
|
|
59
|
-
if err.Error() != "deleting card: unexpected status code 404: Card not found" {
|
|
60
|
-
t.Errorf("expected API error, got %v", err)
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
func TestCardDeleteCommandNoClient(t *testing.T) {
|
|
65
|
-
testApp := &app.App{}
|
|
66
|
-
|
|
67
|
-
cmd := cardDeleteCmd
|
|
68
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
69
|
-
|
|
70
|
-
err := handleDeleteCard(cmd, "1")
|
|
71
|
-
if err == nil {
|
|
72
|
-
t.Errorf("expected error when client not available")
|
|
73
|
-
}
|
|
74
|
-
if err.Error() != "API client not available" {
|
|
75
|
-
t.Errorf("expected 'client not available' error, got %v", err)
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
func TestCardDeleteCommandInvalidCardNumber(t *testing.T) {
|
|
80
|
-
testApp := &app.App{}
|
|
81
|
-
|
|
82
|
-
cmd := cardDeleteCmd
|
|
83
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
84
|
-
|
|
85
|
-
err := handleDeleteCard(cmd, "not-a-number")
|
|
86
|
-
if err == nil {
|
|
87
|
-
t.Errorf("expected error for invalid card number")
|
|
88
|
-
}
|
|
89
|
-
if err.Error() != "invalid card number: strconv.Atoi: parsing \"not-a-number\": invalid syntax" {
|
|
90
|
-
t.Errorf("expected invalid card number error, got %v", err)
|
|
91
|
-
}
|
|
92
|
-
}
|
package/cmd/card_golden.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 cardGoldenCmd = &cobra.Command{
|
|
13
|
-
Use: "golden <card_number>",
|
|
14
|
-
Short: "Mark a card as golden",
|
|
15
|
-
Long: `Mark an existing card as golden`,
|
|
16
|
-
Args: cobra.ExactArgs(1),
|
|
17
|
-
Run: func(cmd *cobra.Command, args []string) {
|
|
18
|
-
if err := handleGoldenCard(cmd, args[0]); err != nil {
|
|
19
|
-
fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
func handleGoldenCard(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.PostCardGoldenness(context.Background(), cardNum)
|
|
36
|
-
if err != nil {
|
|
37
|
-
return fmt.Errorf("marking card as golden: %w", err)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
fmt.Fprintf(cmd.OutOrStdout(), "✓ Card #%d marked as golden\n", cardNum)
|
|
41
|
-
return nil
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
func init() {
|
|
45
|
-
cardCmd.AddCommand(cardGoldenCmd)
|
|
46
|
-
}
|
package/cmd/card_golden_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 TestCardGoldenCommandSuccess(t *testing.T) {
|
|
14
|
-
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
15
|
-
if r.URL.Path != "/cards/123/goldness" {
|
|
16
|
-
t.Errorf("expected /cards/123/goldness, 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 := cardGoldenCmd
|
|
35
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
36
|
-
|
|
37
|
-
if err := handleGoldenCard(cmd, "123"); err != nil {
|
|
38
|
-
t.Fatalf("handleGoldenCard failed: %v", err)
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
func TestCardGoldenCommandInvalidCardNumber(t *testing.T) {
|
|
43
|
-
testApp := &app.App{}
|
|
44
|
-
|
|
45
|
-
cmd := cardGoldenCmd
|
|
46
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
47
|
-
|
|
48
|
-
err := handleGoldenCard(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 TestCardGoldenCommandNoClient(t *testing.T) {
|
|
58
|
-
testApp := &app.App{}
|
|
59
|
-
|
|
60
|
-
cmd := cardGoldenCmd
|
|
61
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
62
|
-
|
|
63
|
-
err := handleGoldenCard(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 TestCardGoldenCommandAPIError(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 := cardGoldenCmd
|
|
83
|
-
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
84
|
-
|
|
85
|
-
err := handleGoldenCard(cmd, "123")
|
|
86
|
-
if err == nil {
|
|
87
|
-
t.Errorf("expected error for API failure")
|
|
88
|
-
}
|
|
89
|
-
if err.Error() != "marking card as golden: unexpected status code 500: Internal Server Error" {
|
|
90
|
-
t.Errorf("expected API error, got %v", err)
|
|
91
|
-
}
|
|
92
|
-
}
|
package/cmd/card_list.go
DELETED
|
@@ -1,53 +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/rogeriopvl/fizzy/internal/ui"
|
|
10
|
-
"github.com/spf13/cobra"
|
|
11
|
-
)
|
|
12
|
-
|
|
13
|
-
var cardListCmd = &cobra.Command{
|
|
14
|
-
Use: "list",
|
|
15
|
-
Short: "List all cards",
|
|
16
|
-
Long: `Retrieve and display all cards from Fizzy`,
|
|
17
|
-
Run: func(cmd *cobra.Command, args []string) {
|
|
18
|
-
if err := handleListCards(cmd); err != nil {
|
|
19
|
-
fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
func handleListCards(cmd *cobra.Command) error {
|
|
25
|
-
a := app.FromContext(cmd.Context())
|
|
26
|
-
if a == nil || a.Client == nil {
|
|
27
|
-
return fmt.Errorf("API client not available")
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if a.Config.SelectedBoard == "" {
|
|
31
|
-
return fmt.Errorf("no board selected")
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
filters := api.CardFilters{
|
|
35
|
-
BoardIDs: []string{a.Config.SelectedBoard},
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
cards, err := a.Client.GetCards(context.Background(), filters)
|
|
39
|
-
if err != nil {
|
|
40
|
-
return fmt.Errorf("fetching cards: %w", err)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if len(cards) == 0 {
|
|
44
|
-
fmt.Println("No cards found")
|
|
45
|
-
return nil
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return ui.DisplayCards(cards)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
func init() {
|
|
52
|
-
cardCmd.AddCommand(cardListCmd)
|
|
53
|
-
}
|