Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions cmd/feedback/feedback.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Comment on lines +71 to +73
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: Added a DEPRECATED(semver:X) comment to make this easier to find in the future. We are a little consistent with our deprecation comments - TODO(semver:major) and others also exist. Preference?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for both this comment and calling out the formatting!

IIRC we are using TODO(semver:major) more often, but this is often for internal breaking changes AFAICT.

I think DEPRECATED is meaningful here since it captures the ongoing support with an existing alternative option, but IMO the semver:major part is the most important! This is what I would use in searching for these 😉

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I learned in review of #71 that go has a convention around making machine-readable comments that I'm interested in exploring:

...this comment directives are line comments that start with //go:, with no space between the // and the go:.

https://go.dev/wiki/Comments#directives

Using a similar pattern might be interesting for these more "conventional" comments, but I don't believe we have explicit notes on how these should be used overall...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One addition to this comment might also note the deprecated suggestions? 📚

Edit: I realize you make a similar comment a few lines down - no blocker here!

Suggested change
SlackCLIFeedback = "slack-cli"
SlackPlatformFeedback = "slack-platform"
SlackPlatformFeedbackDeprecated = "platform-improvements" // DEPRECATED(semver:major)
SlackCLIFeedback = "slack-cli"
SlackPlatformFeedback = "slack-platform"
SlackPlatformFeedbackDeprecated = "platform-improvements" // DEPRECATED(semver:major) - Replaced with the "slack-platform" option

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The //go: directive is interesting. It led me down a path to find the use of the // DEPRECATED: comment in Golang. So, perhaps we can start to use that convention to signal deprecated code. I definitely agree that the (semver:major) scope is most important though!

)

type SurveyConfigInterface interface {
Expand All @@ -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:"),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: Writing tests found a typo!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mwbrooks Whew great catch! It's nice to know this wasn't released, but darn that's an L for sure 😉

style.Secondary(style.Highlight("https://github.com/slackapi/slack-cli/issues")),
))
},
Expand Down Expand Up @@ -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 != "" {
Expand Down
65 changes: 65 additions & 0 deletions cmd/feedback/feedback_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -66,7 +68,9 @@ func TestFeedbackCommand(t *testing.T) {

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

_surveys := SurveyStore
SurveyStore = surveys
defer func() { SurveyStore = _surveys }()
Comment on lines +71 to +73
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: After adding some Command Table Tests, I noticed that the tests started failing when ran together. The reason is that the current tests clobber the global SurveyStore. This code backs up and restores the original SurveyStore after each test.

🧪 In a follow-up PR, I'd like to refactor these tests to all use the Command Table Test.


// Execute test
cmd := NewFeedbackCommand(clients)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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{
"[email protected]",
"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{
"[email protected]",
"https://docs.slack.dev/developer-support",
},
},
Comment on lines +287 to +296
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💌 👏

}, 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)
}
Loading