Skip to content

Commit 192ab46

Browse files
authored
feat: add support for 'feedback --name slack-platform' (#70)
* 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 * feat: add support for 'feedback --name slack-platform' * feat: add deprecation message * test: fix tests that clobber global * feat: print deprecation message to stdout
1 parent 9bb1d69 commit 192ab46

File tree

2 files changed

+75
-3
lines changed

2 files changed

+75
-3
lines changed

cmd/feedback/feedback.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ const (
6868

6969
// Supported survey names
7070
const (
71-
SlackCLIFeedback = "slack-cli"
72-
SlackPlatformFeedback = "platform-improvements"
71+
SlackCLIFeedback = "slack-cli"
72+
SlackPlatformFeedback = "slack-platform"
73+
SlackPlatformFeedbackDeprecated = "platform-improvements" // DEPRECATED(semver:major)
7374
)
7475

7576
type SurveyConfigInterface interface {
@@ -92,7 +93,7 @@ var SurveyStore = map[string]SlackSurvey{
9293
Info: func(ctx context.Context, clients *shared.ClientFactory) {
9394
clients.IO.PrintInfo(ctx, false, fmt.Sprintf(
9495
"%s\n%s\n",
95-
style.Secondary("Ask questions, submit issues, or suggest features for the SLack CLI:"),
96+
style.Secondary("Ask questions, submit issues, or suggest features for the Slack CLI:"),
9697
style.Secondary(style.Highlight("https://github.com/slackapi/slack-cli/issues")),
9798
))
9899
},
@@ -242,6 +243,12 @@ func runFeedbackCommand(ctx context.Context, clients *shared.ClientFactory, cmd
242243
return nil
243244
}
244245

246+
// DEPRECATED(semver:major): Support the deprecated survey name for backwards compatibility
247+
if surveyNameFlag == SlackPlatformFeedbackDeprecated {
248+
surveyNameFlag = SlackPlatformFeedback
249+
clients.IO.PrintWarning(ctx, "DEPRECATED: The '--name %s' flag is deprecated; use '--name %s' instead", SlackPlatformFeedbackDeprecated, SlackPlatformFeedback)
250+
}
251+
245252
surveyNames, surveyPromptOptions := initSurveyOpts(ctx, clients, SurveyStore)
246253

247254
if _, ok := SurveyStore[surveyNameFlag]; !ok && surveyNameFlag != "" {

cmd/feedback/feedback_test.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import (
2828
"github.com/slackapi/slack-cli/internal/slackerror"
2929
"github.com/slackapi/slack-cli/internal/slacktrace"
3030
"github.com/slackapi/slack-cli/internal/style"
31+
"github.com/slackapi/slack-cli/test/testutil"
32+
"github.com/spf13/cobra"
3133
"github.com/stretchr/testify/assert"
3234
"github.com/stretchr/testify/mock"
3335
)
@@ -66,7 +68,9 @@ func TestFeedbackCommand(t *testing.T) {
6668

6769
clients := shared.NewClientFactory(clientsMock.MockClientFactory())
6870

71+
_surveys := SurveyStore
6972
SurveyStore = surveys
73+
defer func() { SurveyStore = _surveys }()
7074

7175
// Execute test
7276
cmd := NewFeedbackCommand(clients)
@@ -134,7 +138,9 @@ func TestFeedbackCommand(t *testing.T) {
134138

135139
clients := shared.NewClientFactory(clientsMock.MockClientFactory())
136140

141+
_surveys := SurveyStore
137142
SurveyStore = surveys
143+
defer func() { SurveyStore = _surveys }()
138144

139145
// Execute test
140146
cmd := NewFeedbackCommand(clients)
@@ -243,7 +249,9 @@ func TestShowSurveyMessages(t *testing.T) {
243249

244250
clients := shared.NewClientFactory(clientsMock.MockClientFactory())
245251

252+
_surveys := SurveyStore
246253
SurveyStore = surveys
254+
defer func() { SurveyStore = _surveys }()
247255

248256
// Execute test
249257
err := ShowSurveyMessages(ctx, clients)
@@ -252,3 +260,60 @@ func TestShowSurveyMessages(t *testing.T) {
252260
clientsMock.Browser.AssertCalled(t, "OpenURL", "https://C.com?project_id=projectID&system_id=systemID&utm_medium=cli&utm_source=cli")
253261
})
254262
}
263+
264+
func Test_Feedback_FeedbackCommand(t *testing.T) {
265+
testutil.TableTestCommand(t, testutil.CommandTests{
266+
// DEPRECATED(semver:major): Support the deprecated survey name for backwards compatibility
267+
"supports deprecated --name platform-improvements": {
268+
CmdArgs: []string{"--name", "platform-improvements"},
269+
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
270+
setupFeedbackCommandMocks(t, ctx, cm, cf)
271+
},
272+
ExpectedOutputs: []string{
273+
274+
"https://docs.slack.dev/developer-support",
275+
},
276+
},
277+
"supports --name slack-cli": {
278+
CmdArgs: []string{"--name", "slack-cli"},
279+
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
280+
setupFeedbackCommandMocks(t, ctx, cm, cf)
281+
},
282+
ExpectedOutputs: []string{
283+
"Ask questions, submit issues, or suggest features for the Slack CLI",
284+
"https://github.com/slackapi/slack-cli/issues",
285+
},
286+
},
287+
"supports --name slack-platform": {
288+
CmdArgs: []string{"--name", "slack-platform"},
289+
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
290+
setupFeedbackCommandMocks(t, ctx, cm, cf)
291+
},
292+
ExpectedOutputs: []string{
293+
294+
"https://docs.slack.dev/developer-support",
295+
},
296+
},
297+
}, func(cf *shared.ClientFactory) *cobra.Command {
298+
cmd := NewFeedbackCommand(cf)
299+
return cmd
300+
})
301+
}
302+
303+
// setupFeedbackCommandMocks prepares common mocks for these tests
304+
func setupFeedbackCommandMocks(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
305+
cm.AddDefaultMocks()
306+
307+
scm := &config.SystemConfigMock{}
308+
scm.On("GetSurveyConfig", mock.Anything, mock.Anything).Return(config.SurveyConfig{}, nil)
309+
scm.On("GetSystemID", mock.Anything).Return("systemID", nil)
310+
scm.On("SetSurveyConfig", mock.Anything, mock.Anything, mock.Anything).Return(nil)
311+
cm.Config.SystemConfig = scm
312+
313+
pcm := &config.ProjectConfigMock{}
314+
pcm.On("GetSurveyConfig", mock.Anything, mock.Anything).Return(config.SurveyConfig{}, nil)
315+
pcm.On("GetProjectID", mock.Anything).Return("projectID", nil)
316+
cm.Config.ProjectConfig = pcm
317+
318+
cm.IO.On("ConfirmPrompt", mock.Anything, "Open in browser?", mock.Anything).Return(false)
319+
}

0 commit comments

Comments
 (0)