-
Notifications
You must be signed in to change notification settings - Fork 34
feat: add --app flag support to slack create for linking existing apps #565
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
srtaalej
wants to merge
12
commits into
main
Choose a base branch
from
ale-app-id-flag
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+134
−2
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
0d8bfd3
feat: add --app flag support to slack create for linking existing apps
srtaalej da2eb75
address pr feedback
srtaalej e57f7d5
Merge branch 'main' into ale-app-id-flag
srtaalej aceb7a4
Merge branch 'main' into ale-app-id-flag
srtaalej 906346a
simplify app creation with app link cmd
srtaalej 8128d5e
Merge branch 'main' into ale-app-id-flag
srtaalej 315c9bb
simplify redundant tests
srtaalej dc7d9f7
Merge branch 'main' into ale-app-id-flag
srtaalej 7386119
Merge branch 'main' into ale-app-id-flag
mwbrooks 818c87a
Merge branch 'main' into ale-app-id-flag
srtaalej 60d222a
feat: validate --environment flag values in create command
srtaalej 8ef2b29
feat: add happy path tests for --app flag and make LinkFunc mockable
srtaalej File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ import ( | |
| "github.com/slackapi/slack-cli/internal/iostreams" | ||
| "github.com/slackapi/slack-cli/internal/pkg/create" | ||
| "github.com/slackapi/slack-cli/internal/shared" | ||
| "github.com/slackapi/slack-cli/internal/shared/types" | ||
| "github.com/slackapi/slack-cli/internal/slackerror" | ||
| "github.com/slackapi/slack-cli/test/testutil" | ||
| "github.com/spf13/cobra" | ||
|
|
@@ -853,3 +854,92 @@ func TestCreateCommand_confirmExternalTemplateSelection(t *testing.T) { | |
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestCreateCommand_AppFlag(t *testing.T) { | ||
| var createClientMock *CreateClientMock | ||
|
|
||
| testutil.TableTestCommand(t, testutil.CommandTests{ | ||
| "app flag without template flag returns error": { | ||
| CmdArgs: []string{"my-app", "--app", "A0123456789"}, | ||
| Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { | ||
| createClientMock = new(CreateClientMock) | ||
| CreateFunc = createClientMock.Create | ||
| }, | ||
| ExpectedErrorStrings: []string{"The --app flag requires the --template flag when used with create"}, | ||
| ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { | ||
| createClientMock.AssertNotCalled(t, "Create", mock.Anything, mock.Anything, mock.Anything) | ||
| }, | ||
| }, | ||
| "environment flag without app flag returns error": { | ||
| CmdArgs: []string{"my-app", "--template", "slack-samples/bolt-js-starter-template", "--environment", "deployed"}, | ||
| Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { | ||
| createClientMock = new(CreateClientMock) | ||
| CreateFunc = createClientMock.Create | ||
| }, | ||
| ExpectedErrorStrings: []string{"The --environment flag requires the --app flag when used with create"}, | ||
| ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { | ||
| createClientMock.AssertNotCalled(t, "Create", mock.Anything, mock.Anything, mock.Anything) | ||
| }, | ||
| }, | ||
| "invalid environment flag returns error": { | ||
| CmdArgs: []string{"my-app", "--template", "slack-samples/bolt-js-starter-template", "--app", "A0123456789", "--environment", "invalid"}, | ||
| Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { | ||
| createClientMock = new(CreateClientMock) | ||
| CreateFunc = createClientMock.Create | ||
| }, | ||
| ExpectedErrorStrings: []string{"The --environment flag must be either 'local' or 'deployed'"}, | ||
| ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { | ||
| createClientMock.AssertNotCalled(t, "Create", mock.Anything, mock.Anything, mock.Anything) | ||
| }, | ||
| }, | ||
| "app flag with template creates project then calls link": { | ||
| CmdArgs: []string{"my-app", "--template", "slack-samples/bolt-js-starter-template", "--app", "A0123456789", "--environment", "local"}, | ||
| Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { | ||
| cm.IO.On("SelectPrompt", mock.Anything, mock.Anything, mock.Anything, mock.Anything). | ||
| Return(iostreams.SelectPromptResponse{Flag: true, Option: "slack-samples/bolt-js-starter-template"}, nil).Maybe() | ||
|
|
||
| createClientMock = new(CreateClientMock) | ||
| createClientMock.On("Create", mock.Anything, mock.Anything, mock.Anything).Return(t.TempDir(), nil) | ||
| CreateFunc = createClientMock.Create | ||
|
|
||
| linkCalled := false | ||
| LinkFunc = func(ctx context.Context, clients *shared.ClientFactory, a *types.App, shouldConfirm bool) error { | ||
| linkCalled = true | ||
| assert.False(t, shouldConfirm) | ||
| return nil | ||
| } | ||
| t.Cleanup(func() { | ||
| assert.True(t, linkCalled, "LinkFunc should have been called") | ||
| }) | ||
| }, | ||
| ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { | ||
| createClientMock.AssertCalled(t, "Create", mock.Anything, mock.Anything, mock.Anything) | ||
| }, | ||
| }, | ||
| "app flag without environment still calls link": { | ||
| CmdArgs: []string{"my-app", "--template", "slack-samples/bolt-js-starter-template", "--app", "A0123456789"}, | ||
| Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { | ||
| cm.IO.On("SelectPrompt", mock.Anything, mock.Anything, mock.Anything, mock.Anything). | ||
| Return(iostreams.SelectPromptResponse{Flag: true, Option: "slack-samples/bolt-js-starter-template"}, nil).Maybe() | ||
|
|
||
| createClientMock = new(CreateClientMock) | ||
| createClientMock.On("Create", mock.Anything, mock.Anything, mock.Anything).Return(t.TempDir(), nil) | ||
| CreateFunc = createClientMock.Create | ||
|
|
||
| linkCalled := false | ||
| LinkFunc = func(ctx context.Context, clients *shared.ClientFactory, a *types.App, shouldConfirm bool) error { | ||
| linkCalled = true | ||
| return nil | ||
| } | ||
| t.Cleanup(func() { | ||
| assert.True(t, linkCalled, "LinkFunc should have been called") | ||
| }) | ||
| }, | ||
| ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { | ||
| createClientMock.AssertCalled(t, "Create", mock.Anything, mock.Anything, mock.Anything) | ||
| }, | ||
| }, | ||
| }, func(cf *shared.ClientFactory) *cobra.Command { | ||
| return NewCreateCommand(cf) | ||
| }) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧪 suggestion: Adding cases to cover the expected happy paths might be meaningful to guarantee the |
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.