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.
Files changed (159) hide show
  1. package/.golangci.yml +56 -0
  2. package/IMPLEMENTATION_PLAN.md +58 -0
  3. package/docs/API.md +89 -0
  4. package/package.json +2 -1
  5. package/.env +0 -1
  6. package/.github/workflows/release.yml +0 -29
  7. package/.github/workflows/tests.yml +0 -24
  8. package/AGENTS.md +0 -33
  9. package/CHANGELOG.md +0 -194
  10. package/Makefile +0 -43
  11. package/bin/fizzy +0 -0
  12. package/cmd/account.go +0 -14
  13. package/cmd/account_list.go +0 -44
  14. package/cmd/account_list_test.go +0 -118
  15. package/cmd/board.go +0 -49
  16. package/cmd/board_create.go +0 -59
  17. package/cmd/board_create_test.go +0 -141
  18. package/cmd/board_delete.go +0 -40
  19. package/cmd/board_delete_test.go +0 -121
  20. package/cmd/board_list.go +0 -44
  21. package/cmd/board_list_test.go +0 -115
  22. package/cmd/board_show.go +0 -40
  23. package/cmd/board_show_test.go +0 -113
  24. package/cmd/board_test.go +0 -92
  25. package/cmd/board_update.go +0 -72
  26. package/cmd/board_update_test.go +0 -233
  27. package/cmd/card.go +0 -24
  28. package/cmd/card_assign.go +0 -55
  29. package/cmd/card_assign_test.go +0 -130
  30. package/cmd/card_close.go +0 -46
  31. package/cmd/card_close_test.go +0 -92
  32. package/cmd/card_create.go +0 -72
  33. package/cmd/card_create_test.go +0 -186
  34. package/cmd/card_delete.go +0 -46
  35. package/cmd/card_delete_test.go +0 -92
  36. package/cmd/card_golden.go +0 -46
  37. package/cmd/card_golden_test.go +0 -92
  38. package/cmd/card_list.go +0 -114
  39. package/cmd/card_list_test.go +0 -373
  40. package/cmd/card_not_now.go +0 -46
  41. package/cmd/card_not_now_test.go +0 -92
  42. package/cmd/card_reaction.go +0 -13
  43. package/cmd/card_reaction_create.go +0 -46
  44. package/cmd/card_reaction_create_test.go +0 -148
  45. package/cmd/card_reaction_delete.go +0 -46
  46. package/cmd/card_reaction_delete_test.go +0 -112
  47. package/cmd/card_reaction_list.go +0 -51
  48. package/cmd/card_reaction_list_test.go +0 -127
  49. package/cmd/card_reopen.go +0 -46
  50. package/cmd/card_reopen_test.go +0 -92
  51. package/cmd/card_show.go +0 -46
  52. package/cmd/card_show_test.go +0 -92
  53. package/cmd/card_tag.go +0 -51
  54. package/cmd/card_tag_test.go +0 -112
  55. package/cmd/card_triage.go +0 -46
  56. package/cmd/card_ungolden.go +0 -46
  57. package/cmd/card_ungolden_test.go +0 -92
  58. package/cmd/card_untriage.go +0 -46
  59. package/cmd/card_untriage_test.go +0 -92
  60. package/cmd/card_unwatch.go +0 -46
  61. package/cmd/card_unwatch_test.go +0 -92
  62. package/cmd/card_update.go +0 -82
  63. package/cmd/card_update_test.go +0 -149
  64. package/cmd/card_watch.go +0 -46
  65. package/cmd/card_watch_test.go +0 -92
  66. package/cmd/column.go +0 -14
  67. package/cmd/column_create.go +0 -79
  68. package/cmd/column_create_test.go +0 -178
  69. package/cmd/column_delete.go +0 -40
  70. package/cmd/column_delete_test.go +0 -121
  71. package/cmd/column_list.go +0 -44
  72. package/cmd/column_list_test.go +0 -138
  73. package/cmd/column_show.go +0 -40
  74. package/cmd/column_show_test.go +0 -111
  75. package/cmd/column_update.go +0 -67
  76. package/cmd/column_update_test.go +0 -198
  77. package/cmd/comment.go +0 -14
  78. package/cmd/comment_create.go +0 -51
  79. package/cmd/comment_create_test.go +0 -129
  80. package/cmd/comment_delete.go +0 -46
  81. package/cmd/comment_delete_test.go +0 -92
  82. package/cmd/comment_list.go +0 -51
  83. package/cmd/comment_list_test.go +0 -132
  84. package/cmd/comment_show.go +0 -46
  85. package/cmd/comment_show_test.go +0 -104
  86. package/cmd/comment_update.go +0 -51
  87. package/cmd/comment_update_test.go +0 -130
  88. package/cmd/login.go +0 -81
  89. package/cmd/login_test.go +0 -98
  90. package/cmd/notification.go +0 -14
  91. package/cmd/notification_list.go +0 -69
  92. package/cmd/notification_list_test.go +0 -288
  93. package/cmd/notification_read.go +0 -51
  94. package/cmd/notification_read_all.go +0 -38
  95. package/cmd/notification_read_all_test.go +0 -75
  96. package/cmd/notification_read_test.go +0 -138
  97. package/cmd/notification_unread.go +0 -44
  98. package/cmd/notification_unread_test.go +0 -99
  99. package/cmd/reaction.go +0 -13
  100. package/cmd/reaction_create.go +0 -46
  101. package/cmd/reaction_create_test.go +0 -113
  102. package/cmd/reaction_delete.go +0 -46
  103. package/cmd/reaction_delete_test.go +0 -92
  104. package/cmd/reaction_list.go +0 -51
  105. package/cmd/reaction_list_test.go +0 -125
  106. package/cmd/root.go +0 -38
  107. package/cmd/step.go +0 -14
  108. package/cmd/step_create.go +0 -53
  109. package/cmd/step_create_test.go +0 -171
  110. package/cmd/step_delete.go +0 -46
  111. package/cmd/step_delete_test.go +0 -92
  112. package/cmd/step_update.go +0 -66
  113. package/cmd/step_update_test.go +0 -190
  114. package/cmd/tag.go +0 -15
  115. package/cmd/tag_list.go +0 -47
  116. package/cmd/tag_list_test.go +0 -109
  117. package/cmd/use.go +0 -85
  118. package/cmd/use_test.go +0 -186
  119. package/cmd/user.go +0 -22
  120. package/cmd/user_deactivate.go +0 -40
  121. package/cmd/user_deactivate_test.go +0 -121
  122. package/cmd/user_list.go +0 -44
  123. package/cmd/user_list_test.go +0 -126
  124. package/cmd/user_show.go +0 -40
  125. package/cmd/user_show_test.go +0 -110
  126. package/cmd/user_update.go +0 -71
  127. package/cmd/user_update_test.go +0 -177
  128. package/go.mod +0 -31
  129. package/go.sum +0 -53
  130. package/internal/api/boards.go +0 -93
  131. package/internal/api/cards.go +0 -322
  132. package/internal/api/client.go +0 -99
  133. package/internal/api/columns.go +0 -113
  134. package/internal/api/comments.go +0 -108
  135. package/internal/api/identity.go +0 -24
  136. package/internal/api/notifications.go +0 -89
  137. package/internal/api/reactions.go +0 -130
  138. package/internal/api/steps.go +0 -101
  139. package/internal/api/tags.go +0 -24
  140. package/internal/api/types.go +0 -195
  141. package/internal/api/users.go +0 -75
  142. package/internal/app/app.go +0 -49
  143. package/internal/colors/colors.go +0 -32
  144. package/internal/config/config.go +0 -70
  145. package/internal/testutil/client.go +0 -26
  146. package/internal/ui/account_list.go +0 -14
  147. package/internal/ui/account_selector.go +0 -63
  148. package/internal/ui/board_list.go +0 -14
  149. package/internal/ui/board_show.go +0 -17
  150. package/internal/ui/card_list.go +0 -14
  151. package/internal/ui/card_show.go +0 -23
  152. package/internal/ui/column_list.go +0 -28
  153. package/internal/ui/column_show.go +0 -16
  154. package/internal/ui/comment_list.go +0 -25
  155. package/internal/ui/format.go +0 -27
  156. package/internal/ui/notification_list.go +0 -27
  157. package/internal/ui/reaction_list.go +0 -14
  158. package/internal/ui/user_list.go +0 -19
  159. package/internal/ui/user_show.go +0 -23
@@ -1,132 +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 TestCommentListCommandSuccess(t *testing.T) {
16
- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
17
- if r.URL.Path != "/cards/123/comments" {
18
- t.Errorf("expected /cards/123/comments, got %s", r.URL.Path)
19
- }
20
- if r.Method != http.MethodGet {
21
- t.Errorf("expected GET, got %s", r.Method)
22
- }
23
-
24
- auth := r.Header.Get("Authorization")
25
- if auth != "Bearer test-token" {
26
- t.Errorf("expected Bearer test-token, got %s", auth)
27
- }
28
-
29
- w.Header().Set("Content-Type", "application/json")
30
- response := []api.Comment{
31
- {
32
- ID: "comment-123",
33
- CreatedAt: "2025-01-01T00:00:00Z",
34
- UpdatedAt: "2025-01-01T00:00:00Z",
35
- Creator: api.User{ID: "user-1", Name: "John Doe"},
36
- },
37
- {
38
- ID: "comment-456",
39
- CreatedAt: "2025-01-02T00:00:00Z",
40
- UpdatedAt: "2025-01-02T00:00:00Z",
41
- Creator: api.User{ID: "user-2", Name: "Jane Doe"},
42
- },
43
- }
44
- // Set the body field manually since it's a struct
45
- response[0].Body.PlainText = "First comment"
46
- response[0].Body.HTML = "<p>First comment</p>"
47
- response[1].Body.PlainText = "Second comment"
48
- response[1].Body.HTML = "<p>Second comment</p>"
49
- json.NewEncoder(w).Encode(response)
50
- }))
51
- defer server.Close()
52
-
53
- client := testutil.NewTestClient(server.URL, "", "", "test-token")
54
- testApp := &app.App{Client: client}
55
-
56
- cmd := commentListCmd
57
- cmd.SetContext(testApp.ToContext(context.Background()))
58
-
59
- if err := handleListComments(cmd, "123"); err != nil {
60
- t.Fatalf("handleListComments failed: %v", err)
61
- }
62
- }
63
-
64
- func TestCommentListCommandNoComments(t *testing.T) {
65
- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
66
- w.Header().Set("Content-Type", "application/json")
67
- json.NewEncoder(w).Encode([]api.Comment{})
68
- }))
69
- defer server.Close()
70
-
71
- client := testutil.NewTestClient(server.URL, "", "", "test-token")
72
- testApp := &app.App{Client: client}
73
-
74
- cmd := commentListCmd
75
- cmd.SetContext(testApp.ToContext(context.Background()))
76
-
77
- if err := handleListComments(cmd, "123"); err != nil {
78
- t.Fatalf("handleListComments failed: %v", err)
79
- }
80
- }
81
-
82
- func TestCommentListCommandInvalidCardNumber(t *testing.T) {
83
- testApp := &app.App{}
84
-
85
- cmd := commentListCmd
86
- cmd.SetContext(testApp.ToContext(context.Background()))
87
-
88
- err := handleListComments(cmd, "not-a-number")
89
- if err == nil {
90
- t.Errorf("expected error for invalid card number")
91
- }
92
- if err.Error() != "invalid card number: strconv.Atoi: parsing \"not-a-number\": invalid syntax" {
93
- t.Errorf("expected invalid card number error, got %v", err)
94
- }
95
- }
96
-
97
- func TestCommentListCommandNoClient(t *testing.T) {
98
- testApp := &app.App{}
99
-
100
- cmd := commentListCmd
101
- cmd.SetContext(testApp.ToContext(context.Background()))
102
-
103
- err := handleListComments(cmd, "123")
104
- if err == nil {
105
- t.Errorf("expected error when client not available")
106
- }
107
- if err.Error() != "API client not available" {
108
- t.Errorf("expected 'client not available' error, got %v", err)
109
- }
110
- }
111
-
112
- func TestCommentListCommandAPIError(t *testing.T) {
113
- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
114
- w.WriteHeader(http.StatusInternalServerError)
115
- w.Write([]byte("Internal Server Error"))
116
- }))
117
- defer server.Close()
118
-
119
- client := testutil.NewTestClient(server.URL, "", "", "test-token")
120
- testApp := &app.App{Client: client}
121
-
122
- cmd := commentListCmd
123
- cmd.SetContext(testApp.ToContext(context.Background()))
124
-
125
- err := handleListComments(cmd, "123")
126
- if err == nil {
127
- t.Errorf("expected error for API failure")
128
- }
129
- if err.Error() != "fetching comments: unexpected status code 500: Internal Server Error" {
130
- t.Errorf("expected API error, got %v", err)
131
- }
132
- }
@@ -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/rogeriopvl/fizzy/internal/ui"
10
- "github.com/spf13/cobra"
11
- )
12
-
13
- var commentShowCmd = &cobra.Command{
14
- Use: "show <card_number> <comment_id>",
15
- Short: "Show a specific comment",
16
- Long: `Display details of a specific comment on a card`,
17
- Args: cobra.ExactArgs(2),
18
- Run: func(cmd *cobra.Command, args []string) {
19
- if err := handleShowComment(cmd, args[0], args[1]); err != nil {
20
- fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
21
- }
22
- },
23
- }
24
-
25
- func handleShowComment(cmd *cobra.Command, cardNumber, commentID 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
- comment, err := a.Client.GetCardComment(context.Background(), cardNum, commentID)
37
- if err != nil {
38
- return fmt.Errorf("fetching comment: %w", err)
39
- }
40
-
41
- return ui.DisplayComment(comment)
42
- }
43
-
44
- func init() {
45
- commentCmd.AddCommand(commentShowCmd)
46
- }
@@ -1,104 +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 TestCommentShowCommandSuccess(t *testing.T) {
16
- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
17
- if r.URL.Path != "/cards/123/comments/comment-456" {
18
- t.Errorf("expected /cards/123/comments/comment-456, got %s", r.URL.Path)
19
- }
20
- if r.Method != http.MethodGet {
21
- t.Errorf("expected GET, got %s", r.Method)
22
- }
23
-
24
- auth := r.Header.Get("Authorization")
25
- if auth != "Bearer test-token" {
26
- t.Errorf("expected Bearer test-token, got %s", auth)
27
- }
28
-
29
- w.Header().Set("Content-Type", "application/json")
30
- response := api.Comment{
31
- ID: "comment-456",
32
- CreatedAt: "2025-01-01T00:00:00Z",
33
- UpdatedAt: "2025-01-01T00:00:00Z",
34
- Creator: api.User{ID: "user-1", Name: "John Doe"},
35
- Card: api.CardReference{ID: "card-123", Title: "Test Card"},
36
- }
37
- response.Body.PlainText = "This is a test comment"
38
- response.Body.HTML = "<p>This is a test comment</p>"
39
- json.NewEncoder(w).Encode(response)
40
- }))
41
- defer server.Close()
42
-
43
- client := testutil.NewTestClient(server.URL, "", "", "test-token")
44
- testApp := &app.App{Client: client}
45
-
46
- cmd := commentShowCmd
47
- cmd.SetContext(testApp.ToContext(context.Background()))
48
-
49
- if err := handleShowComment(cmd, "123", "comment-456"); err != nil {
50
- t.Fatalf("handleShowComment failed: %v", err)
51
- }
52
- }
53
-
54
- func TestCommentShowCommandInvalidCardNumber(t *testing.T) {
55
- testApp := &app.App{}
56
-
57
- cmd := commentShowCmd
58
- cmd.SetContext(testApp.ToContext(context.Background()))
59
-
60
- err := handleShowComment(cmd, "not-a-number", "comment-456")
61
- if err == nil {
62
- t.Errorf("expected error for invalid card number")
63
- }
64
- if err.Error() != "invalid card number: strconv.Atoi: parsing \"not-a-number\": invalid syntax" {
65
- t.Errorf("expected invalid card number error, got %v", err)
66
- }
67
- }
68
-
69
- func TestCommentShowCommandNoClient(t *testing.T) {
70
- testApp := &app.App{}
71
-
72
- cmd := commentShowCmd
73
- cmd.SetContext(testApp.ToContext(context.Background()))
74
-
75
- err := handleShowComment(cmd, "123", "comment-456")
76
- if err == nil {
77
- t.Errorf("expected error when client not available")
78
- }
79
- if err.Error() != "API client not available" {
80
- t.Errorf("expected 'client not available' error, got %v", err)
81
- }
82
- }
83
-
84
- func TestCommentShowCommandAPIError(t *testing.T) {
85
- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
86
- w.WriteHeader(http.StatusNotFound)
87
- w.Write([]byte("Comment not found"))
88
- }))
89
- defer server.Close()
90
-
91
- client := testutil.NewTestClient(server.URL, "", "", "test-token")
92
- testApp := &app.App{Client: client}
93
-
94
- cmd := commentShowCmd
95
- cmd.SetContext(testApp.ToContext(context.Background()))
96
-
97
- err := handleShowComment(cmd, "123", "comment-456")
98
- if err == nil {
99
- t.Errorf("expected error for API failure")
100
- }
101
- if err.Error() != "fetching comment: unexpected status code 404: Comment not found" {
102
- t.Errorf("expected API error, got %v", err)
103
- }
104
- }
@@ -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/spf13/cobra"
10
- )
11
-
12
- var commentUpdateCmd = &cobra.Command{
13
- Use: "update <card_number> <comment_id>",
14
- Short: "Update an existing comment",
15
- Long: `Update the body of an existing comment on a card`,
16
- Args: cobra.ExactArgs(2),
17
- Run: func(cmd *cobra.Command, args []string) {
18
- if err := handleUpdateComment(cmd, args[0], args[1]); err != nil {
19
- fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
20
- }
21
- },
22
- }
23
-
24
- func handleUpdateComment(cmd *cobra.Command, cardNumber, commentID 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
- body, _ := cmd.Flags().GetString("body")
36
-
37
- comment, err := a.Client.PutCardComment(context.Background(), cardNum, commentID, body)
38
- if err != nil {
39
- return fmt.Errorf("updating comment: %w", err)
40
- }
41
-
42
- fmt.Fprintf(cmd.OutOrStdout(), "✓ Comment updated successfully (id: %s)\n", comment.ID)
43
- return nil
44
- }
45
-
46
- func init() {
47
- commentUpdateCmd.Flags().StringP("body", "b", "", "New comment body (required)")
48
- commentUpdateCmd.MarkFlagRequired("body")
49
-
50
- commentCmd.AddCommand(commentUpdateCmd)
51
- }
@@ -1,130 +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 TestCommentUpdateCommandSuccess(t *testing.T) {
17
- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
18
- if r.URL.Path != "/cards/123/comments/comment-456" {
19
- t.Errorf("expected /cards/123/comments/comment-456, got %s", r.URL.Path)
20
- }
21
- if r.Method != http.MethodPut {
22
- t.Errorf("expected PUT, 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]string
36
- if err := json.Unmarshal(body, &payload); err != nil {
37
- t.Fatalf("failed to unmarshal request body: %v", err)
38
- }
39
-
40
- commentPayload := payload["comment"]
41
- if commentPayload["body"] != "Updated comment text" {
42
- t.Errorf("expected body 'Updated comment text', got %s", commentPayload["body"])
43
- }
44
-
45
- w.Header().Set("Content-Type", "application/json")
46
- response := api.Comment{
47
- ID: "comment-456",
48
- CreatedAt: "2025-01-01T00:00:00Z",
49
- UpdatedAt: "2025-01-02T00:00:00Z",
50
- Creator: api.User{ID: "user-1", Name: "John Doe"},
51
- }
52
- response.Body.PlainText = "Updated comment text"
53
- json.NewEncoder(w).Encode(response)
54
- }))
55
- defer server.Close()
56
-
57
- client := testutil.NewTestClient(server.URL, "", "", "test-token")
58
- testApp := &app.App{Client: client}
59
-
60
- cmd := commentUpdateCmd
61
- cmd.SetContext(testApp.ToContext(context.Background()))
62
- cmd.ParseFlags([]string{
63
- "--body", "Updated comment text",
64
- })
65
-
66
- if err := handleUpdateComment(cmd, "123", "comment-456"); err != nil {
67
- t.Fatalf("handleUpdateComment failed: %v", err)
68
- }
69
- }
70
-
71
- func TestCommentUpdateCommandInvalidCardNumber(t *testing.T) {
72
- testApp := &app.App{}
73
-
74
- cmd := commentUpdateCmd
75
- cmd.SetContext(testApp.ToContext(context.Background()))
76
- cmd.ParseFlags([]string{
77
- "--body", "Updated text",
78
- })
79
-
80
- err := handleUpdateComment(cmd, "not-a-number", "comment-456")
81
- if err == nil {
82
- t.Errorf("expected error for invalid card number")
83
- }
84
- if err.Error() != "invalid card number: strconv.Atoi: parsing \"not-a-number\": invalid syntax" {
85
- t.Errorf("expected invalid card number error, got %v", err)
86
- }
87
- }
88
-
89
- func TestCommentUpdateCommandNoClient(t *testing.T) {
90
- testApp := &app.App{}
91
-
92
- cmd := commentUpdateCmd
93
- cmd.SetContext(testApp.ToContext(context.Background()))
94
- cmd.ParseFlags([]string{
95
- "--body", "Updated text",
96
- })
97
-
98
- err := handleUpdateComment(cmd, "123", "comment-456")
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 TestCommentUpdateCommandAPIError(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("Comment 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 := commentUpdateCmd
118
- cmd.SetContext(testApp.ToContext(context.Background()))
119
- cmd.ParseFlags([]string{
120
- "--body", "Updated text",
121
- })
122
-
123
- err := handleUpdateComment(cmd, "123", "comment-456")
124
- if err == nil {
125
- t.Errorf("expected error for API failure")
126
- }
127
- if err.Error() != "updating comment: unexpected status code 404: Comment not found" {
128
- t.Errorf("expected API error, got %v", err)
129
- }
130
- }
package/cmd/login.go DELETED
@@ -1,81 +0,0 @@
1
- package cmd
2
-
3
- import (
4
- "context"
5
- "fmt"
6
- "os"
7
-
8
- "github.com/rogeriopvl/fizzy/internal/api"
9
- "github.com/rogeriopvl/fizzy/internal/app"
10
- "github.com/rogeriopvl/fizzy/internal/ui"
11
- "github.com/spf13/cobra"
12
- )
13
-
14
- var loginCmd = &cobra.Command{
15
- Use: "login",
16
- Short: "Prints instructions on how to authenticate with the Fizzy API",
17
- Long: `Prints intructions on how to authenticate with the Fizzy API`,
18
- Run: func(cmd *cobra.Command, args []string) {
19
- if err := handleLogin(cmd); err != nil {
20
- fmt.Fprintf(os.Stderr, "Error: %v\n", err)
21
- }
22
- },
23
- }
24
-
25
- func handleLogin(cmd *cobra.Command) error {
26
- token, isSet := os.LookupEnv("FIZZY_ACCESS_TOKEN")
27
- if !isSet || token == "" {
28
- return printAuthInstructions(cmd)
29
- }
30
-
31
- fmt.Fprintf(cmd.OutOrStdout(), "✓ Authenticated with access token: %s\n", token[:6]+"...")
32
-
33
- a := app.FromContext(cmd.Context())
34
- if a == nil || a.Client == nil {
35
- return fmt.Errorf("API client not available")
36
- }
37
-
38
- identity, err := a.Client.GetMyIdentity(context.Background())
39
- if err != nil {
40
- return fmt.Errorf("fetching identity: %w", err)
41
- }
42
-
43
- selected, err := chooseAccount(cmd, identity.Accounts)
44
- if err != nil {
45
- return err
46
- }
47
-
48
- fmt.Fprintf(cmd.OutOrStdout(), "\nSelected account: %s (%s)\n", selected.Name, selected.Slug)
49
-
50
- // Save the selected account and current user ID to config
51
- a.Config.SelectedAccount = selected.Slug
52
- a.Config.CurrentUserID = selected.User.ID
53
- if err := a.Config.Save(); err != nil {
54
- return fmt.Errorf("saving config: %w", err)
55
- }
56
-
57
- return nil
58
- }
59
-
60
- func chooseAccount(cmd *cobra.Command, accounts []api.Account) (api.Account, error) {
61
- if len(accounts) == 1 {
62
- selected := accounts[0]
63
- return selected, nil
64
- }
65
-
66
- fmt.Fprintf(cmd.OutOrStdout(), "\nAvailable accounts:\n")
67
- return ui.SelectAccount(accounts)
68
- }
69
-
70
- func printAuthInstructions(cmd *cobra.Command) error {
71
- fmt.Fprintf(cmd.OutOrStdout(), "To authenticate with Fizzy's API you need an access token.\n")
72
- fmt.Fprintf(cmd.OutOrStdout(), "\nGo to https://app.fizzy.do/<account_slug>/my/access_tokens and follow the instructions...\n")
73
- fmt.Fprintf(cmd.OutOrStdout(), "(Replace <account_slug> with your account slug)\n")
74
- fmt.Fprintf(cmd.OutOrStdout(), "\nThen export it as an environment variable in your shell, with the name FIZZY_ACCESS_TOKEN\n")
75
- fmt.Fprintf(cmd.OutOrStdout(), "And re-run this command.\n")
76
- return nil
77
- }
78
-
79
- func init() {
80
- rootCmd.AddCommand(loginCmd)
81
- }
package/cmd/login_test.go DELETED
@@ -1,98 +0,0 @@
1
- package cmd
2
-
3
- import (
4
- "context"
5
- "encoding/json"
6
- "net/http"
7
- "net/http/httptest"
8
- "os"
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 TestLoginCommand(t *testing.T) {
18
- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
19
- if r.URL.Path != "/my/identity" {
20
- t.Errorf("expected /my/identity, got %s", r.URL.Path)
21
- }
22
- if r.Method != http.MethodGet {
23
- t.Errorf("expected GET, got %s", r.Method)
24
- }
25
-
26
- auth := r.Header.Get("Authorization")
27
- if auth == "" {
28
- t.Error("missing Authorization header")
29
- w.WriteHeader(http.StatusUnauthorized)
30
- return
31
- }
32
- if auth != "Bearer test-token" {
33
- t.Errorf("expected Bearer test-token, got %s", auth)
34
- }
35
-
36
- if r.Header.Get("Accept") != "application/json" {
37
- t.Errorf("expected Accept: application/json, got %s", r.Header.Get("Accept"))
38
- }
39
-
40
- w.Header().Set("Content-Type", "application/json")
41
- response := api.GetMyIdentityResponse{
42
- Accounts: []api.Account{
43
- {
44
- ID: "acc-123",
45
- Name: "Test Account",
46
- Slug: "test-account",
47
- User: api.User{
48
- ID: "user-123",
49
- Email: "test@example.com",
50
- Name: "Test User",
51
- },
52
- },
53
- },
54
- }
55
- json.NewEncoder(w).Encode(response)
56
- }))
57
- defer server.Close()
58
-
59
- tmpDir := t.TempDir()
60
- configPath := tmpDir + "/.config/fizzy-cli/config.json"
61
-
62
- t.Setenv("FIZZY_ACCESS_TOKEN", "test-token")
63
- t.Setenv("HOME", tmpDir)
64
-
65
- client := testutil.NewTestClient(server.URL, "", "", "test-token")
66
-
67
- cfg := &config.Config{}
68
- testApp := &app.App{
69
- Client: client,
70
- Config: cfg,
71
- }
72
-
73
- cmd := loginCmd
74
- cmd.SetContext(testApp.ToContext(context.Background()))
75
-
76
- if err := handleLogin(cmd); err != nil {
77
- t.Fatalf("handleLogin failed: %v", err)
78
- }
79
-
80
- if cfg.SelectedAccount != "test-account" {
81
- t.Errorf("expected SelectedAccount=test-account, got %s", cfg.SelectedAccount)
82
- }
83
-
84
- if _, err := os.Stat(configPath); err != nil {
85
- t.Errorf("config file not created at %s: %v", configPath, err)
86
- }
87
- }
88
-
89
- func TestLoginCommandWithoutToken(t *testing.T) {
90
- t.Setenv("FIZZY_ACCESS_TOKEN", "")
91
-
92
- cmd := loginCmd
93
- err := handleLogin(cmd)
94
-
95
- if err != nil {
96
- t.Errorf("expected no error when token is missing, got %v", err)
97
- }
98
- }
@@ -1,14 +0,0 @@
1
- // Package cmd
2
- package cmd
3
-
4
- import "github.com/spf13/cobra"
5
-
6
- var notificationCmd = &cobra.Command{
7
- Use: "notification",
8
- Short: "Manage notifications",
9
- Long: `Manage notifications in Fizzy`,
10
- }
11
-
12
- func init() {
13
- rootCmd.AddCommand(notificationCmd)
14
- }