-
Notifications
You must be signed in to change notification settings - Fork 31
feat: 'app link' supports run-on-slack apps with local manifest source #56
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
Changes from all commits
471a848
9a5be4c
cec1f5f
ce180eb
30e69a7
5f30426
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ import ( | |
| "testing" | ||
|
|
||
| "github.com/slackapi/slack-cli/internal/api" | ||
| "github.com/slackapi/slack-cli/internal/app" | ||
| "github.com/slackapi/slack-cli/internal/config" | ||
| "github.com/slackapi/slack-cli/internal/iostreams" | ||
| "github.com/slackapi/slack-cli/internal/shared" | ||
|
|
@@ -430,7 +431,7 @@ func Test_Apps_Link(t *testing.T) { | |
| CmdArgs: []string{}, | ||
| ExpectedError: slackerror.New(slackerror.ErrAppNotFound), | ||
| }, | ||
| "accept manifest source prompt and saves information about the provided deployed app": { | ||
| "accepting manifest source prompt should save information about the provided deployed app": { | ||
|
Member
Author
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. note: Just re-wording after reading over the test cases for clarity.
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.
Member
Author
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. |
||
| Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { | ||
| cm.AuthInterface.On("Auths", mock.Anything).Return([]types.SlackAuth{ | ||
| mockLinkSlackAuth2, | ||
|
|
@@ -503,7 +504,7 @@ func Test_Apps_Link(t *testing.T) { | |
| ) | ||
| }, | ||
| }, | ||
| "decline manifest source prompt should not link app": { | ||
| "declining manifest source prompt should not link app": { | ||
| Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { | ||
| cm.AddDefaultMocks() | ||
| setupAppLinkCommandMocks(t, ctx, cm, cf) | ||
|
|
@@ -537,6 +538,159 @@ func Test_Apps_Link(t *testing.T) { | |
| require.Len(t, apps, 0) | ||
| }, | ||
| }, | ||
| "manifest source prompt should not display for Run-on-Slack apps with local manifest source": { | ||
|
Member
Author
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. note: New test case to assert that the manifest update prompt is NOT displayed for ROSI apps with a local manifest. I don't check for remote manifests, because that's handled in an existing test-case. |
||
| Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { | ||
| cm.AuthInterface.On("Auths", mock.Anything).Return([]types.SlackAuth{ | ||
| mockLinkSlackAuth1, | ||
| mockLinkSlackAuth2, | ||
| }, nil) | ||
| cm.AddDefaultMocks() | ||
| setupAppLinkCommandMocks(t, ctx, cm, cf) | ||
| // Set manifest source to local | ||
| if err := cm.Config.ProjectConfig.SetManifestSource(ctx, config.MANIFEST_SOURCE_LOCAL); err != nil { | ||
| require.FailNow(t, fmt.Sprintf("Failed to set the manifest source in the memory-based file system: %s", err)) | ||
| } | ||
| // Mock manifest for Run-on-Slack app | ||
| manifestMock := &app.ManifestMockObject{} | ||
| manifestMock.On("GetManifestLocal", mock.Anything, mock.Anything, mock.Anything).Return(types.SlackYaml{ | ||
| AppManifest: types.AppManifest{ | ||
| Settings: &types.AppSettings{ | ||
| FunctionRuntime: types.SLACK_HOSTED, | ||
| }, | ||
| }, | ||
| }, nil) | ||
| cf.AppClient().Manifest = manifestMock | ||
| cm.IO.On("SelectPrompt", | ||
| mock.Anything, | ||
| "Select the existing app team", | ||
| mock.Anything, | ||
| mock.Anything, | ||
| mock.Anything, | ||
| ).Return(iostreams.SelectPromptResponse{ | ||
| Flag: true, | ||
| Option: mockLinkSlackAuth1.TeamDomain, | ||
| }, nil) | ||
| cm.IO.On("InputPrompt", | ||
| mock.Anything, | ||
| "Enter the existing app ID", | ||
| mock.Anything, | ||
| ).Return(mockLinkAppID1, nil) | ||
| cm.IO.On("SelectPrompt", | ||
| mock.Anything, | ||
| "Choose the app environment", | ||
| mock.Anything, | ||
| mock.Anything, | ||
| mock.Anything, | ||
| ).Return(iostreams.SelectPromptResponse{ | ||
| Flag: true, | ||
| Option: "deployed", | ||
| }, nil) | ||
| cm.ApiInterface.On( | ||
| "GetAppStatus", | ||
| mock.Anything, | ||
| mockLinkSlackAuth1.Token, | ||
| []string{mockLinkAppID1}, | ||
| mockLinkSlackAuth1.TeamID, | ||
| ).Return(api.GetAppStatusResult{}, nil) | ||
| }, | ||
| CmdArgs: []string{}, | ||
| ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { | ||
| expectedApp := types.App{ | ||
| AppID: mockLinkAppID1, | ||
| TeamDomain: mockLinkSlackAuth1.TeamDomain, | ||
| TeamID: mockLinkSlackAuth1.TeamID, | ||
| EnterpriseID: mockLinkSlackAuth1.EnterpriseID, | ||
| } | ||
| actualApp, err := cm.AppClient.GetDeployed( | ||
| ctx, | ||
| mockLinkSlackAuth1.TeamID, | ||
| ) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, expectedApp, actualApp) | ||
| // Assert manifest confirmation prompt was not displayed | ||
| cm.IO.AssertNotCalled(t, "ConfirmPrompt", | ||
| mock.Anything, | ||
| LinkAppManifestSourceConfirmPromptText, | ||
| mock.Anything, | ||
| ) | ||
| }, | ||
| }, | ||
| "manifest source prompt should display for GBP apps with local manifest source": { | ||
|
Member
Author
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. note: Added a test-case to assert that the manifest update prompt is still displayed for GBP apps with a local manifest. This case might be redundant, but I felt high confidence after adding it.
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. Thanks for adding it! I had a good feeling when running the The |
||
| Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { | ||
| cm.AuthInterface.On("Auths", mock.Anything).Return([]types.SlackAuth{ | ||
| mockLinkSlackAuth1, | ||
| mockLinkSlackAuth2, | ||
| }, nil) | ||
| cm.AddDefaultMocks() | ||
| setupAppLinkCommandMocks(t, ctx, cm, cf) | ||
| // Set manifest source to local | ||
| if err := cm.Config.ProjectConfig.SetManifestSource(ctx, config.MANIFEST_SOURCE_LOCAL); err != nil { | ||
| require.FailNow(t, fmt.Sprintf("Failed to set the manifest source in the memory-based file system: %s", err)) | ||
| } | ||
| // Mock manifest for Run-on-Slack app | ||
| manifestMock := &app.ManifestMockObject{} | ||
| manifestMock.On("GetManifestLocal", mock.Anything, mock.Anything, mock.Anything).Return(types.SlackYaml{}, nil) | ||
| cf.AppClient().Manifest = manifestMock | ||
| cm.IO.On("ConfirmPrompt", | ||
| mock.Anything, | ||
| LinkAppManifestSourceConfirmPromptText, | ||
| mock.Anything, | ||
| ).Return(true, nil) | ||
| cm.IO.On("SelectPrompt", | ||
| mock.Anything, | ||
| "Select the existing app team", | ||
| mock.Anything, | ||
| mock.Anything, | ||
| mock.Anything, | ||
| ).Return(iostreams.SelectPromptResponse{ | ||
| Flag: true, | ||
| Option: mockLinkSlackAuth1.TeamDomain, | ||
| }, nil) | ||
| cm.IO.On("InputPrompt", | ||
| mock.Anything, | ||
| "Enter the existing app ID", | ||
| mock.Anything, | ||
| ).Return(mockLinkAppID1, nil) | ||
| cm.IO.On("SelectPrompt", | ||
| mock.Anything, | ||
| "Choose the app environment", | ||
| mock.Anything, | ||
| mock.Anything, | ||
| mock.Anything, | ||
| ).Return(iostreams.SelectPromptResponse{ | ||
| Flag: true, | ||
| Option: "deployed", | ||
| }, nil) | ||
| cm.ApiInterface.On( | ||
| "GetAppStatus", | ||
| mock.Anything, | ||
| mockLinkSlackAuth1.Token, | ||
| []string{mockLinkAppID1}, | ||
| mockLinkSlackAuth1.TeamID, | ||
| ).Return(api.GetAppStatusResult{}, nil) | ||
| }, | ||
| CmdArgs: []string{}, | ||
| ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { | ||
| expectedApp := types.App{ | ||
| AppID: mockLinkAppID1, | ||
| TeamDomain: mockLinkSlackAuth1.TeamDomain, | ||
| TeamID: mockLinkSlackAuth1.TeamID, | ||
| EnterpriseID: mockLinkSlackAuth1.EnterpriseID, | ||
| } | ||
| actualApp, err := cm.AppClient.GetDeployed( | ||
| ctx, | ||
| mockLinkSlackAuth1.TeamID, | ||
| ) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, expectedApp, actualApp) | ||
| // Assert manifest confirmation prompt was displayed | ||
| cm.IO.AssertCalled(t, "ConfirmPrompt", | ||
| mock.Anything, | ||
| LinkAppManifestSourceConfirmPromptText, | ||
| mock.Anything, | ||
| ) | ||
| }, | ||
| }, | ||
| }, func(clients *shared.ClientFactory) *cobra.Command { | ||
| clients.SDKConfig.WorkingDirectory = "." | ||
| return NewLinkCommand(clients) | ||
|
|
@@ -552,7 +706,7 @@ func Test_Apps_LinkAppHeaderSection(t *testing.T) { | |
| "When shouldConfirm is false": { | ||
| shouldConfirm: false, | ||
| expectedOutputs: []string{ | ||
| "Add an existing app created on app settings", | ||
| "Add an existing app from app settings", | ||
| "Find your existing apps at: https://api.slack.com/apps", | ||
| }, | ||
| unexpectedOutputs: []string{ | ||
|
|
@@ -562,7 +716,7 @@ func Test_Apps_LinkAppHeaderSection(t *testing.T) { | |
| "When shouldConfirm is true": { | ||
| shouldConfirm: true, | ||
| expectedOutputs: []string{ | ||
| "Add an existing app created on app settings", | ||
| "Add an existing app from app settings", | ||
| "Find your existing apps at: https://api.slack.com/apps", | ||
| "Manually add apps later with", | ||
| }, | ||
|
|
@@ -609,4 +763,9 @@ func setupAppLinkCommandMocks(t *testing.T, ctx context.Context, cm *shared.Clie | |
| if err := cm.Config.ProjectConfig.SetManifestSource(ctx, config.MANIFEST_SOURCE_REMOTE); err != nil { | ||
| require.FailNow(t, fmt.Sprintf("Failed to set the manifest source in the memory-based file system: %s", err)) | ||
| } | ||
|
|
||
| // Mock manifest | ||
| manifestMock := &app.ManifestMockObject{} | ||
| manifestMock.On("GetManifestLocal", mock.Anything, mock.Anything, mock.Anything).Return(types.SlackYaml{}, nil) | ||
| cf.AppClient().Manifest = manifestMock | ||
|
Comment on lines
+767
to
+770
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. π Perhaps personal preference, but I'm curious what you think about: Having standalone and shared "setup"..."mock" functions I find to be confusing, even if convenient. IMO inlining mocks is super helpful in table tests to keep each unit separate. No blocker at all for this PR, but does this seem like a longterm idea we should nudge towards?
Member
Author
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. π§ I agree with you. I also find the It would be nice to settle on some practice that keeps the tests short(er) while explicit. |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: App Settings now displays Slack CLI created apps as read-only, un-clickable. So, I figured we should update this text to not be restricted to "created on app settings" because the app may be created by the CLI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
β What an eye for good readings!