Skip to content

Commit 9bb1d69

Browse files
mwbrookszimeg
andauthored
refactor: 'feedback' command trace and error handling (#68)
* feat: update 'feedback' command to include feedback about the Slack CLI * fix: update survey output to feedback output * refactor: rename PlatformSurvey to SlackPlatformFeedback * feat: support skipping query params for feedback urls * test: add feedback name to trace * test: fix failing tests * chore: tweak comment * refactor: 'feedback' command always traces with slacktrace.FeedbackMessage * refactor: add slackerrors for 'feedback' error handling * refactor: clarify the ErrFeedbackNameRequired message * Update internal/slackerror/errors.go Co-authored-by: Eden Zimbelman <eden.zimbelman@salesforce.com> * fix: update error code messages to be consistent --------- Co-authored-by: Eden Zimbelman <eden.zimbelman@salesforce.com>
1 parent bd2b344 commit 9bb1d69

3 files changed

Lines changed: 29 additions & 16 deletions

File tree

cmd/feedback/feedback.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ type SlackSurvey struct {
5151
// Info prints additional information about the survey; displayed when the option is selected in `feedback`
5252
// Info is optional
5353
Info func(ctx context.Context, clients *shared.ClientFactory)
54-
// Trace is a string consumed by tests to confirm that the Info text was displayed
55-
Trace string
5654
// Ask either prints text or prompts the user to complete the survey
5755
// Potentially displayed after `run`/`deploy`/`doctor` (or other places where ShowSurveyMessages is called)
5856
Ask func(ctx context.Context, clients *shared.ClientFactory) (bool, error)
@@ -98,7 +96,6 @@ var SurveyStore = map[string]SlackSurvey{
9896
style.Secondary(style.Highlight("https://github.com/slackapi/slack-cli/issues")),
9997
))
10098
},
101-
Trace: slacktrace.FeedbackMessage,
10299
Ask: func(ctx context.Context, clients *shared.ClientFactory) (bool, error) {
103100
clients.IO.PrintInfo(ctx, false, style.Sectionf(style.TextSection{
104101
Emoji: "love_letter",
@@ -127,7 +124,6 @@ var SurveyStore = map[string]SlackSurvey{
127124
style.Secondary("Or, share your experiences at "+style.Highlight("https://docs.slack.dev/developer-support")),
128125
))
129126
},
130-
Trace: slacktrace.FeedbackMessage,
131127
Ask: func(ctx context.Context, clients *shared.ClientFactory) (bool, error) {
132128
clients.IO.PrintInfo(ctx, false, style.Sectionf(style.TextSection{
133129
Emoji: "love_letter",
@@ -249,15 +245,12 @@ func runFeedbackCommand(ctx context.Context, clients *shared.ClientFactory, cmd
249245
surveyNames, surveyPromptOptions := initSurveyOpts(ctx, clients, SurveyStore)
250246

251247
if _, ok := SurveyStore[surveyNameFlag]; !ok && surveyNameFlag != "" {
252-
return slackerror.New("invalid_survey_name").
253-
WithMessage("Invalid feedback name provided: %s", surveyNameFlag).
254-
WithRemediation("View the feedback options with %s", style.Commandf("feedback --help", false))
248+
return slackerror.New(slackerror.ErrFeedbackNameInvalid).
249+
WithMessage("Invalid feedback name provided: %s", surveyNameFlag)
255250
}
256251

257252
if surveyNameFlag == "" && noPromptFlag {
258-
return slackerror.New("survey_name_required").
259-
WithMessage("Please provide a feedback name or remove the --no-prompt flag").
260-
WithRemediation("View feedback options with %s", style.Commandf("feedback --help", false))
253+
return slackerror.New(slackerror.ErrFeedbackNameRequired)
261254
}
262255

263256
clients.IO.PrintInfo(ctx, false, style.Sectionf(style.TextSection{
@@ -338,7 +331,8 @@ func executeSurvey(ctx context.Context, clients *shared.ClientFactory, s SlackSu
338331
if s.Info != nil {
339332
s.Info(ctx, clients)
340333
}
341-
clients.IO.PrintTrace(ctx, s.Trace, s.Name)
334+
335+
clients.IO.PrintTrace(ctx, slacktrace.FeedbackMessage, s.Name)
342336

343337
var err error
344338
var ok bool

cmd/feedback/feedback_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,14 @@ import (
2626
"github.com/slackapi/slack-cli/internal/shared"
2727
"github.com/slackapi/slack-cli/internal/slackcontext"
2828
"github.com/slackapi/slack-cli/internal/slackerror"
29+
"github.com/slackapi/slack-cli/internal/slacktrace"
2930
"github.com/slackapi/slack-cli/internal/style"
3031
"github.com/stretchr/testify/assert"
3132
"github.com/stretchr/testify/mock"
3233
)
3334

3435
func TestFeedbackCommand(t *testing.T) {
35-
3636
t.Run("when there is only one survey option", func(t *testing.T) {
37-
3837
surveys := map[string]SlackSurvey{
3938
SlackPlatformFeedback: {
4039
Name: SlackPlatformFeedback,
@@ -72,12 +71,14 @@ func TestFeedbackCommand(t *testing.T) {
7271
// Execute test
7372
cmd := NewFeedbackCommand(clients)
7473
err := runFeedbackCommand(ctx, clients, cmd)
74+
75+
// Assertions
7576
assert.NoError(t, err)
7677
clientsMock.Browser.AssertCalled(t, "OpenURL", "https://survey.com?project_id=projectID&system_id=systemID&utm_medium=cli&utm_source=cli")
78+
clientsMock.IO.AssertCalled(t, "PrintTrace", mock.Anything, slacktrace.FeedbackMessage, []string{SlackPlatformFeedback})
7779
})
7880

7981
t.Run("when there are multiple survey options", func(t *testing.T) {
80-
8182
surveys := map[string]SlackSurvey{
8283
"A_test": {
8384
Name: "A_test",
@@ -139,12 +140,14 @@ func TestFeedbackCommand(t *testing.T) {
139140
cmd := NewFeedbackCommand(clients)
140141
err := runFeedbackCommand(ctx, clients, cmd)
141142
assert.NoError(t, err)
143+
144+
// Assertions
142145
clientsMock.Browser.AssertCalled(t, "OpenURL", "https://survey.com?project_id=projectID&system_id=systemID&utm_medium=cli&utm_source=cli")
146+
clientsMock.IO.AssertCalled(t, "PrintTrace", mock.Anything, slacktrace.FeedbackMessage, []string{SlackPlatformFeedback})
143147
})
144148
}
145149

146150
func TestShowSurveyMessages(t *testing.T) {
147-
148151
t.Run("surveys asked or not asked based on the stored config", func(t *testing.T) {
149152
surveys := map[string]SlackSurvey{
150153
// Should be asked once; already asked
@@ -248,5 +251,4 @@ func TestShowSurveyMessages(t *testing.T) {
248251
clientsMock.Browser.AssertCalled(t, "OpenURL", "https://B.com?project_id=projectID&system_id=systemID&utm_medium=cli&utm_source=cli")
249252
clientsMock.Browser.AssertCalled(t, "OpenURL", "https://C.com?project_id=projectID&system_id=systemID&utm_medium=cli&utm_source=cli")
250253
})
251-
252254
}

internal/slackerror/errors.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ const (
103103
ErrFailedToGetUser = "failed_to_get_user"
104104
ErrFailedToSaveExtensionLogs = "failed_to_save_extension_logs"
105105
ErrFailToGetTeamsForRestrictedUser = "fail_to_get_teams_for_restricted_user"
106+
ErrFeedbackNameInvalid = "feedback_name_invalid"
107+
ErrFeedbackNameRequired = "feedback_name_required"
106108
ErrFileRejected = "file_rejected"
107109
ErrForbiddenTeam = "forbidden_team"
108110
ErrFreeTeamNotAllowed = "free_team_not_allowed"
@@ -711,6 +713,21 @@ Otherwise start your app for local development with: %s`,
711713
Message: "Failed to get teams for restricted user",
712714
},
713715

716+
ErrFeedbackNameInvalid: {
717+
Code: ErrFeedbackNameInvalid,
718+
Message: "The name of the feedback is invalid",
719+
Remediation: fmt.Sprintf("View the feedback options with %s", style.Commandf("feedback --help", false)),
720+
},
721+
722+
ErrFeedbackNameRequired: {
723+
Code: ErrFeedbackNameRequired,
724+
Message: "The name of the feedback is required",
725+
Remediation: strings.Join([]string{
726+
"Please provide a --name <string> flag or remove the --no-prompt flag",
727+
fmt.Sprintf("View feedback options with %s", style.Commandf("feedback --help", false)),
728+
}, "\n"),
729+
},
730+
714731
ErrFileRejected: {
715732
Code: ErrFileRejected,
716733
Message: "Not an acceptable S3 file",

0 commit comments

Comments
 (0)