diff --git a/cmd/feedback/feedback.go b/cmd/feedback/feedback.go index 4716705a..3eb6b349 100644 --- a/cmd/feedback/feedback.go +++ b/cmd/feedback/feedback.go @@ -68,8 +68,9 @@ const ( // Supported survey names const ( - SlackCLIFeedback = "slack-cli" - SlackPlatformFeedback = "platform-improvements" + SlackCLIFeedback = "slack-cli" + SlackPlatformFeedback = "slack-platform" + SlackPlatformFeedbackDeprecated = "platform-improvements" // DEPRECATED(semver:major) ) type SurveyConfigInterface interface { @@ -92,7 +93,7 @@ var SurveyStore = map[string]SlackSurvey{ Info: func(ctx context.Context, clients *shared.ClientFactory) { clients.IO.PrintInfo(ctx, false, fmt.Sprintf( "%s\n%s\n", - style.Secondary("Ask questions, submit issues, or suggest features for the SLack CLI:"), + style.Secondary("Ask questions, submit issues, or suggest features for the Slack CLI:"), style.Secondary(style.Highlight("https://github.com/slackapi/slack-cli/issues")), )) }, @@ -242,6 +243,12 @@ func runFeedbackCommand(ctx context.Context, clients *shared.ClientFactory, cmd return nil } + // DEPRECATED(semver:major): Support the deprecated survey name for backwards compatibility + if surveyNameFlag == SlackPlatformFeedbackDeprecated { + surveyNameFlag = SlackPlatformFeedback + clients.IO.PrintWarning(ctx, "DEPRECATED: The '--name %s' flag is deprecated; use '--name %s' instead", SlackPlatformFeedbackDeprecated, SlackPlatformFeedback) + } + surveyNames, surveyPromptOptions := initSurveyOpts(ctx, clients, SurveyStore) if _, ok := SurveyStore[surveyNameFlag]; !ok && surveyNameFlag != "" { diff --git a/cmd/feedback/feedback_test.go b/cmd/feedback/feedback_test.go index 75e8b09f..7a63d4cf 100644 --- a/cmd/feedback/feedback_test.go +++ b/cmd/feedback/feedback_test.go @@ -28,6 +28,8 @@ import ( "github.com/slackapi/slack-cli/internal/slackerror" "github.com/slackapi/slack-cli/internal/slacktrace" "github.com/slackapi/slack-cli/internal/style" + "github.com/slackapi/slack-cli/test/testutil" + "github.com/spf13/cobra" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) @@ -66,7 +68,9 @@ func TestFeedbackCommand(t *testing.T) { clients := shared.NewClientFactory(clientsMock.MockClientFactory()) + _surveys := SurveyStore SurveyStore = surveys + defer func() { SurveyStore = _surveys }() // Execute test cmd := NewFeedbackCommand(clients) @@ -134,7 +138,9 @@ func TestFeedbackCommand(t *testing.T) { clients := shared.NewClientFactory(clientsMock.MockClientFactory()) + _surveys := SurveyStore SurveyStore = surveys + defer func() { SurveyStore = _surveys }() // Execute test cmd := NewFeedbackCommand(clients) @@ -243,7 +249,9 @@ func TestShowSurveyMessages(t *testing.T) { clients := shared.NewClientFactory(clientsMock.MockClientFactory()) + _surveys := SurveyStore SurveyStore = surveys + defer func() { SurveyStore = _surveys }() // Execute test err := ShowSurveyMessages(ctx, clients) @@ -252,3 +260,60 @@ func TestShowSurveyMessages(t *testing.T) { clientsMock.Browser.AssertCalled(t, "OpenURL", "https://C.com?project_id=projectID&system_id=systemID&utm_medium=cli&utm_source=cli") }) } + +func Test_Feedback_FeedbackCommand(t *testing.T) { + testutil.TableTestCommand(t, testutil.CommandTests{ + // DEPRECATED(semver:major): Support the deprecated survey name for backwards compatibility + "supports deprecated --name platform-improvements": { + CmdArgs: []string{"--name", "platform-improvements"}, + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { + setupFeedbackCommandMocks(t, ctx, cm, cf) + }, + ExpectedOutputs: []string{ + "feedback@slack.com", + "https://docs.slack.dev/developer-support", + }, + }, + "supports --name slack-cli": { + CmdArgs: []string{"--name", "slack-cli"}, + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { + setupFeedbackCommandMocks(t, ctx, cm, cf) + }, + ExpectedOutputs: []string{ + "Ask questions, submit issues, or suggest features for the Slack CLI", + "https://github.com/slackapi/slack-cli/issues", + }, + }, + "supports --name slack-platform": { + CmdArgs: []string{"--name", "slack-platform"}, + Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { + setupFeedbackCommandMocks(t, ctx, cm, cf) + }, + ExpectedOutputs: []string{ + "feedback@slack.com", + "https://docs.slack.dev/developer-support", + }, + }, + }, func(cf *shared.ClientFactory) *cobra.Command { + cmd := NewFeedbackCommand(cf) + return cmd + }) +} + +// setupFeedbackCommandMocks prepares common mocks for these tests +func setupFeedbackCommandMocks(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { + cm.AddDefaultMocks() + + scm := &config.SystemConfigMock{} + scm.On("GetSurveyConfig", mock.Anything, mock.Anything).Return(config.SurveyConfig{}, nil) + scm.On("GetSystemID", mock.Anything).Return("systemID", nil) + scm.On("SetSurveyConfig", mock.Anything, mock.Anything, mock.Anything).Return(nil) + cm.Config.SystemConfig = scm + + pcm := &config.ProjectConfigMock{} + pcm.On("GetSurveyConfig", mock.Anything, mock.Anything).Return(config.SurveyConfig{}, nil) + pcm.On("GetProjectID", mock.Anything).Return("projectID", nil) + cm.Config.ProjectConfig = pcm + + cm.IO.On("ConfirmPrompt", mock.Anything, "Open in browser?", mock.Anything).Return(false) +}