-
Notifications
You must be signed in to change notification settings - Fork 30
feat: update 'app link' to not change the app manifest source #396
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
base: mwbrooks-default-bolt-manifest-source-local
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -431,135 +431,18 @@ func Test_Apps_Link(t *testing.T) { | |
| CmdArgs: []string{}, | ||
| ExpectedError: slackerror.New(slackerror.ErrAppNotFound), | ||
| }, | ||
| "accepting manifest source prompt should save information about the provided deployed app": { | ||
| "links app when manifest source is local": { | ||
|
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: Test linking an app when the manifest source is local (manifest file). |
||
| Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { | ||
| cm.Auth.On("Auths", mock.Anything).Return([]types.SlackAuth{ | ||
| mockLinkSlackAuth2, | ||
| mockLinkSlackAuth1, | ||
| }, nil) | ||
| cm.AddDefaultMocks() | ||
| setupAppLinkCommandMocks(t, ctx, cm, cf) | ||
| // Set manifest source to project to trigger confirmation prompt | ||
| if err := config.SetManifestSource(ctx, cm.Fs, cm.Os, config.ManifestSourceLocal); err != nil { | ||
| require.FailNow(t, fmt.Sprintf("Failed to set the manifest source in the memory-based file system: %s", err)) | ||
| } | ||
| // Accept manifest source confirmation prompt | ||
| 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.API.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 accepted | ||
| cm.IO.AssertCalled(t, "ConfirmPrompt", | ||
| mock.Anything, | ||
| LinkAppManifestSourceConfirmPromptText, | ||
| mock.Anything, | ||
| ) | ||
| }, | ||
| }, | ||
| "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) | ||
| // Set manifest source to project to trigger confirmation prompt | ||
| if err := config.SetManifestSource(ctx, cm.Fs, cm.Os, config.ManifestSourceLocal); err != nil { | ||
| require.FailNow(t, fmt.Sprintf("Failed to set the manifest source in the memory-based file system: %s", err)) | ||
| } | ||
| // Decline manifest source confirmation prompt | ||
| cm.IO.On("ConfirmPrompt", | ||
| mock.Anything, | ||
| LinkAppManifestSourceConfirmPromptText, | ||
| mock.Anything, | ||
| ).Return(false, nil) | ||
| }, | ||
| CmdArgs: []string{}, | ||
| ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { | ||
| // Assert manifest confirmation prompt accepted | ||
| cm.IO.AssertCalled(t, "ConfirmPrompt", | ||
| mock.Anything, | ||
| LinkAppManifestSourceConfirmPromptText, | ||
| mock.Anything, | ||
| ) | ||
|
|
||
| // Assert no apps saved | ||
| apps, _, err := cm.AppClient.GetDeployedAll(ctx) | ||
| require.NoError(t, err) | ||
| require.Len(t, apps, 0) | ||
|
|
||
| apps, err = cm.AppClient.GetLocalAll(ctx) | ||
| require.NoError(t, err) | ||
| require.Len(t, apps, 0) | ||
| }, | ||
| }, | ||
| "manifest source prompt should not display for Run-on-Slack apps with local manifest source": { | ||
| Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { | ||
| cm.Auth.On("Auths", mock.Anything).Return([]types.SlackAuth{ | ||
| mockLinkSlackAuth1, | ||
| mockLinkSlackAuth2, | ||
| }, nil) | ||
| cm.AddDefaultMocks() | ||
| setupAppLinkCommandMocks(t, ctx, cm, cf) | ||
| // Set manifest source to local | ||
| if err := config.SetManifestSource(ctx, cm.Fs, cm.Os, config.ManifestSourceLocal); 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.SlackHosted, | ||
| }, | ||
| }, | ||
| }, nil) | ||
| cf.AppClient().Manifest = manifestMock | ||
| cm.IO.On("SelectPrompt", | ||
| mock.Anything, | ||
| "Select the existing app team", | ||
|
|
@@ -583,7 +466,7 @@ func Test_Apps_Link(t *testing.T) { | |
| mock.Anything, | ||
| ).Return(iostreams.SelectPromptResponse{ | ||
| Flag: true, | ||
| Option: "deployed", | ||
| Option: "local", | ||
| }, nil) | ||
| cm.API.On( | ||
| "GetAppStatus", | ||
|
|
@@ -600,42 +483,33 @@ func Test_Apps_Link(t *testing.T) { | |
| TeamDomain: mockLinkSlackAuth1.TeamDomain, | ||
| TeamID: mockLinkSlackAuth1.TeamID, | ||
| EnterpriseID: mockLinkSlackAuth1.EnterpriseID, | ||
| UserID: mockLinkSlackAuth1.UserID, | ||
| IsDev: true, | ||
| } | ||
| actualApp, err := cm.AppClient.GetDeployed( | ||
| actualApp, err := cm.AppClient.GetLocal( | ||
| 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, | ||
| ) | ||
| // Assert manifest source info is displayed | ||
| output := cm.GetCombinedOutput() | ||
| assert.Contains(t, output, "App Manifest") | ||
| assert.Contains(t, output, `"project" (local)`) | ||
| }, | ||
| }, | ||
| "manifest source prompt should display for GBP apps with local manifest source": { | ||
| "links app when manifest source is remote": { | ||
|
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: Test linking an app when the manifest source is remote (app settings). |
||
| Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { | ||
| cm.Auth.On("Auths", mock.Anything).Return([]types.SlackAuth{ | ||
| mockLinkSlackAuth1, | ||
| mockLinkSlackAuth2, | ||
| mockLinkSlackAuth1, | ||
| }, nil) | ||
| cm.AddDefaultMocks() | ||
| setupAppLinkCommandMocks(t, ctx, cm, cf) | ||
| // Set manifest source to local | ||
| if err := config.SetManifestSource(ctx, cm.Fs, cm.Os, config.ManifestSourceLocal); err != nil { | ||
| // Set manifest source to remote | ||
| if err := config.SetManifestSource(ctx, cm.Fs, cm.Os, config.ManifestSourceRemote); 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", | ||
|
|
@@ -659,7 +533,7 @@ func Test_Apps_Link(t *testing.T) { | |
| mock.Anything, | ||
| ).Return(iostreams.SelectPromptResponse{ | ||
| Flag: true, | ||
| Option: "deployed", | ||
| Option: "local", | ||
| }, nil) | ||
| cm.API.On( | ||
| "GetAppStatus", | ||
|
|
@@ -676,19 +550,19 @@ func Test_Apps_Link(t *testing.T) { | |
| TeamDomain: mockLinkSlackAuth1.TeamDomain, | ||
| TeamID: mockLinkSlackAuth1.TeamID, | ||
| EnterpriseID: mockLinkSlackAuth1.EnterpriseID, | ||
| UserID: mockLinkSlackAuth1.UserID, | ||
| IsDev: true, | ||
| } | ||
| actualApp, err := cm.AppClient.GetDeployed( | ||
| actualApp, err := cm.AppClient.GetLocal( | ||
| 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, | ||
| ) | ||
| // Assert manifest source info is displayed | ||
| output := cm.GetCombinedOutput() | ||
| assert.Contains(t, output, "App Manifest") | ||
| assert.Contains(t, output, `"app settings" (remote)`) | ||
| }, | ||
| }, | ||
| }, func(clients *shared.ClientFactory) *cobra.Command { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -752,7 +752,7 @@ func shouldUpdateManifest(ctx context.Context, clients *shared.ClientFactory, ap | |
| case saved.Equals(""): | ||
| notice = "Manifest values for this app are overwritten on reinstall" | ||
| default: | ||
| notice = "The manifest on app settings has been changed since last update!" | ||
| notice = style.Yellow("The manifest on app settings has been changed since last update") | ||
|
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: I'm open to other formatting (Red?) but I think we should make this pop and stand out in some way. |
||
| } | ||
| clients.IO.PrintInfo(ctx, false, "\n%s", style.Sectionf(style.TextSection{ | ||
| Emoji: "books", | ||
|
|
@@ -764,10 +764,7 @@ func shouldUpdateManifest(ctx context.Context, clients *shared.ClientFactory, ap | |
| } | ||
| continues, err := clients.IO.ConfirmPrompt( | ||
| ctx, | ||
| fmt.Sprintf( | ||
| "Update app settings with changes to the %s manifest?", | ||
| config.ManifestSourceLocal.String(), | ||
| ), | ||
| "Overwrite manifest on app settings with the project's manifest file?", | ||
| false, | ||
| ) | ||
| if err != nil { | ||
|
|
||
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(out-of-scope): We should have the default manifest source return by a common method instead of manually setting it in each spot.