diff --git a/cmd/app/add.go b/cmd/app/add.go index 406bf37d..3ed3857d 100644 --- a/cmd/app/add.go +++ b/cmd/app/add.go @@ -36,7 +36,7 @@ import ( var runAddCommandFunc = RunAddCommand var appInstallProdAppFunc = apps.Add var appInstallDevAppFunc = apps.InstallLocalApp -var teamAppSelectPromptFunc = prompts.TeamAppSelectPrompt +var appSelectPromptFunc = prompts.AppSelectPrompt // Flags @@ -111,7 +111,7 @@ func preRunAddCommand(ctx context.Context, clients *shared.ClientFactory) error // RunAddCommand executes the workspace install command, prints output, and returns any errors. func RunAddCommand(ctx context.Context, clients *shared.ClientFactory, selection *prompts.SelectedApp, orgGrantWorkspaceID string) (context.Context, types.InstallState, types.App, error) { if selection == nil { - selected, err := teamAppSelectPromptFunc(ctx, clients, prompts.ShowHostedOnly, prompts.ShowAllApps) + selected, err := appSelectPromptFunc(ctx, clients, prompts.ShowHostedOnly, prompts.ShowAllApps) if err != nil { return ctx, "", types.App{}, err } diff --git a/cmd/app/add_test.go b/cmd/app/add_test.go index 6f06597e..ab9fa903 100644 --- a/cmd/app/add_test.go +++ b/cmd/app/add_test.go @@ -140,8 +140,8 @@ func TestAppAddCommand(t *testing.T) { // Mock TeamSelector prompt to return "team1" appSelectMock := prompts.NewAppSelectMock() - teamAppSelectPromptFunc = appSelectMock.TeamAppSelectPrompt - appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{Auth: mockAuthTeam1}, nil) + appSelectPromptFunc = appSelectMock.AppSelectPrompt + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowHostedOnly, prompts.ShowAllApps).Return(prompts.SelectedApp{Auth: mockAuthTeam1}, nil) // Mock valid session for team1 cm.API.On("ValidateSession", mock.Anything, mock.Anything).Return(api.AuthSession{ @@ -212,8 +212,8 @@ func TestAppAddCommand(t *testing.T) { // Mock TeamSelector prompt to return "team1" appSelectMock := prompts.NewAppSelectMock() - teamAppSelectPromptFunc = appSelectMock.TeamAppSelectPrompt - appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{App: mockAppTeam1, Auth: mockAuthTeam1}, nil) + appSelectPromptFunc = appSelectMock.AppSelectPrompt + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowHostedOnly, prompts.ShowAllApps).Return(prompts.SelectedApp{App: mockAppTeam1, Auth: mockAuthTeam1}, nil) // Mock valid session for team1 cm.API.On("ValidateSession", mock.Anything, mock.Anything).Return(api.AuthSession{ @@ -292,8 +292,8 @@ func TestAppAddCommand(t *testing.T) { Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { prepareAddMocks(t, cf, cm) appSelectMock := prompts.NewAppSelectMock() - teamAppSelectPromptFunc = appSelectMock.TeamAppSelectPrompt - appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{App: mockAppTeam1}, nil) + appSelectPromptFunc = appSelectMock.AppSelectPrompt + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowHostedOnly, prompts.ShowAllApps).Return(prompts.SelectedApp{App: mockAppTeam1}, nil) }, }, "adds a new deployed app to an org with a workspace grant": { @@ -303,8 +303,8 @@ func TestAppAddCommand(t *testing.T) { prepareAddMocks(t, cf, cm) // Select workspace appSelectMock := prompts.NewAppSelectMock() - teamAppSelectPromptFunc = appSelectMock.TeamAppSelectPrompt - appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{App: types.NewApp(), Auth: mockOrgAuth}, nil) + appSelectPromptFunc = appSelectMock.AppSelectPrompt + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowHostedOnly, prompts.ShowAllApps).Return(prompts.SelectedApp{App: types.NewApp(), Auth: mockOrgAuth}, nil) // Mock calls cm.API.On("ValidateSession", mock.Anything, mock.Anything).Return(api.AuthSession{ UserID: &mockOrgAuth.UserID, @@ -363,8 +363,8 @@ func TestAppAddCommand(t *testing.T) { prepareAddMocks(t, cf, cm) // Select workspace appSelectMock := prompts.NewAppSelectMock() - teamAppSelectPromptFunc = appSelectMock.TeamAppSelectPrompt - appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{App: types.NewApp(), Auth: mockOrgAuth}, nil) + appSelectPromptFunc = appSelectMock.AppSelectPrompt + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowHostedOnly, prompts.ShowAllApps).Return(prompts.SelectedApp{App: types.NewApp(), Auth: mockOrgAuth}, nil) // Mock calls cm.API.On("ValidateSession", mock.Anything, mock.Anything).Return(api.AuthSession{ UserID: &mockOrgAuth.UserID, @@ -419,8 +419,8 @@ func TestAppAddCommand(t *testing.T) { prepareAddMocks(t, cf, cm) // Select workspace appSelectMock := prompts.NewAppSelectMock() - teamAppSelectPromptFunc = appSelectMock.TeamAppSelectPrompt - appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{App: types.NewApp(), Auth: mockOrgAuth}, nil) + appSelectPromptFunc = appSelectMock.AppSelectPrompt + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowHostedOnly, prompts.ShowAllApps).Return(prompts.SelectedApp{App: types.NewApp(), Auth: mockOrgAuth}, nil) // Mock calls cm.API.On("ValidateSession", mock.Anything, mock.Anything).Return(api.AuthSession{ UserID: &mockOrgAuth.UserID, diff --git a/cmd/app/delete.go b/cmd/app/delete.go index 73f74076..e272f6e9 100644 --- a/cmd/app/delete.go +++ b/cmd/app/delete.go @@ -71,7 +71,7 @@ func RunDeleteCommand(ctx context.Context, clients *shared.ClientFactory, cmd *c } // Get the app auth selection from the flag or prompt - selection, err := deleteAppSelectPromptFunc(ctx, clients, prompts.ShowInstalledAndUninstalledApps) + selection, err := deleteAppSelectPromptFunc(ctx, clients, prompts.ShowAllEnvironments, prompts.ShowInstalledAndUninstalledApps) if err != nil { if slackerror.ToSlackError(err).Code == slackerror.ErrInstallationRequired { return types.App{}, nil diff --git a/cmd/app/delete_test.go b/cmd/app/delete_test.go index 6ce94da9..a0c8e8c6 100644 --- a/cmd/app/delete_test.go +++ b/cmd/app/delete_test.go @@ -55,7 +55,7 @@ func TestAppsDeleteCommand(t *testing.T) { // Mock App Selection appSelectMock := prompts.NewAppSelectMock() deleteAppSelectPromptFunc = appSelectMock.AppSelectPrompt - appSelectMock.On("AppSelectPrompt").Return(prompts.SelectedApp{ + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowAllEnvironments, prompts.ShowInstalledAndUninstalledApps).Return(prompts.SelectedApp{ Auth: types.SlackAuth{TeamDomain: fakeDeployedApp.TeamDomain}, App: fakeDeployedApp, }, nil) @@ -89,7 +89,7 @@ func TestAppsDeleteCommand(t *testing.T) { // Mock App Selection appSelectMock := prompts.NewAppSelectMock() deleteAppSelectPromptFunc = appSelectMock.AppSelectPrompt - appSelectMock.On("AppSelectPrompt").Return(prompts.SelectedApp{ + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowAllEnvironments, prompts.ShowInstalledAndUninstalledApps).Return(prompts.SelectedApp{ Auth: types.SlackAuth{TeamDomain: fakeLocalApp.TeamDomain}, App: fakeLocalApp, }, nil) @@ -122,7 +122,7 @@ func TestAppsDeleteCommand(t *testing.T) { // Mock App Selection appSelectMock := prompts.NewAppSelectMock() deleteAppSelectPromptFunc = appSelectMock.AppSelectPrompt - appSelectMock.On("AppSelectPrompt").Return(prompts.SelectedApp{ + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowAllEnvironments, prompts.ShowInstalledAndUninstalledApps).Return(prompts.SelectedApp{ Auth: types.SlackAuth{TeamDomain: fakeDeployedApp.TeamDomain}, App: fakeDeployedApp, }, nil) @@ -149,7 +149,7 @@ func TestAppsDeleteCommand(t *testing.T) { cm.API.On("ValidateSession", mock.Anything, mock.Anything).Return(api.AuthSession{}, nil) appSelectMock := prompts.NewAppSelectMock() deleteAppSelectPromptFunc = appSelectMock.AppSelectPrompt - appSelectMock.On("AppSelectPrompt").Return(prompts.SelectedApp{App: fakeDeployedApp}, nil) + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowAllEnvironments, prompts.ShowInstalledAndUninstalledApps).Return(prompts.SelectedApp{App: fakeDeployedApp}, nil) }, }, }, func(cf *shared.ClientFactory) *cobra.Command { diff --git a/cmd/app/settings.go b/cmd/app/settings.go index 38da92c7..f57813f9 100644 --- a/cmd/app/settings.go +++ b/cmd/app/settings.go @@ -96,7 +96,7 @@ func appSettingsCommandRunE(clients *shared.ClientFactory, cmd *cobra.Command, a ctx := cmd.Context() clients.IO.PrintTrace(ctx, slacktrace.AppSettingsStart) - app, err := settingsAppSelectPromptFunc(ctx, clients, prompts.ShowInstalledAndUninstalledApps) + app, err := settingsAppSelectPromptFunc(ctx, clients, prompts.ShowAllEnvironments, prompts.ShowInstalledAndUninstalledApps) if err != nil { return err } diff --git a/cmd/app/settings_test.go b/cmd/app/settings_test.go index d1203589..dad286ae 100644 --- a/cmd/app/settings_test.go +++ b/cmd/app/settings_test.go @@ -96,6 +96,10 @@ func Test_App_SettingsCommand(t *testing.T) { appSelectMock := prompts.NewAppSelectMock() appSelectMock.On( "AppSelectPrompt", + mock.Anything, + mock.Anything, + prompts.ShowAllEnvironments, + prompts.ShowInstalledAndUninstalledApps, ).Return( prompts.SelectedApp{App: types.App{AppID: "A0101010101"}}, nil, @@ -124,6 +128,10 @@ func Test_App_SettingsCommand(t *testing.T) { appSelectMock := prompts.NewAppSelectMock() appSelectMock.On( "AppSelectPrompt", + mock.Anything, + mock.Anything, + prompts.ShowAllEnvironments, + prompts.ShowInstalledAndUninstalledApps, ).Return( prompts.SelectedApp{}, slackerror.New(slackerror.ErrInstallationRequired), @@ -147,6 +155,10 @@ func Test_App_SettingsCommand(t *testing.T) { appSelectMock := prompts.NewAppSelectMock() appSelectMock.On( "AppSelectPrompt", + mock.Anything, + mock.Anything, + prompts.ShowAllEnvironments, + prompts.ShowInstalledAndUninstalledApps, ).Return( prompts.SelectedApp{App: types.App{AppID: "A0123456789"}}, nil, @@ -176,6 +188,10 @@ func Test_App_SettingsCommand(t *testing.T) { appSelectMock := prompts.NewAppSelectMock() appSelectMock.On( "AppSelectPrompt", + mock.Anything, + mock.Anything, + prompts.ShowAllEnvironments, + prompts.ShowInstalledAndUninstalledApps, ).Return( prompts.SelectedApp{ App: types.App{AppID: "A0123456789"}, diff --git a/cmd/app/uninstall.go b/cmd/app/uninstall.go index fc3b0d7d..ba20af14 100644 --- a/cmd/app/uninstall.go +++ b/cmd/app/uninstall.go @@ -66,7 +66,7 @@ func RunUninstallCommand(ctx context.Context, clients *shared.ClientFactory, cmd } // Get the workspace from the flag or prompt - selection, err := uninstallAppSelectPromptFunc(ctx, clients, prompts.ShowInstalledAppsOnly) + selection, err := uninstallAppSelectPromptFunc(ctx, clients, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly) if err != nil { if slackerror.ToSlackError(err).Code == slackerror.ErrInstallationRequired { return types.App{}, nil diff --git a/cmd/app/uninstall_test.go b/cmd/app/uninstall_test.go index 5819ae97..84d8d2ff 100644 --- a/cmd/app/uninstall_test.go +++ b/cmd/app/uninstall_test.go @@ -84,7 +84,7 @@ func TestAppsUninstall(t *testing.T) { prepareCommonUninstallMocks(ctx, cf, cm) appSelectMock := prompts.NewAppSelectMock() uninstallAppSelectPromptFunc = appSelectMock.AppSelectPrompt - appSelectMock.On("AppSelectPrompt").Return(prompts.SelectedApp{App: fakeApp}, nil) + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly).Return(prompts.SelectedApp{App: fakeApp}, nil) }, }, }, func(clients *shared.ClientFactory) *cobra.Command { @@ -99,7 +99,7 @@ func prepareCommonUninstallMocks(ctx context.Context, clients *shared.ClientFact // Mock App Selection appSelectMock := prompts.NewAppSelectMock() uninstallAppSelectPromptFunc = appSelectMock.AppSelectPrompt - appSelectMock.On("AppSelectPrompt").Return(selectedProdApp, nil) + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly).Return(selectedProdApp, nil) // Mock API calls clientsMock.Auth.On("ResolveAPIHost", mock.Anything, mock.Anything, mock.Anything). diff --git a/cmd/collaborators/add.go b/cmd/collaborators/add.go index 4404a02e..c0b07800 100644 --- a/cmd/collaborators/add.go +++ b/cmd/collaborators/add.go @@ -74,7 +74,7 @@ func runAddCommandFunc(ctx context.Context, clients *shared.ClientFactory, cmd * defer span.Finish() // Get the app auth selection from the flag or prompt - selection, err := teamAppSelectPromptFunc(ctx, clients, prompts.ShowHostedOnly, prompts.ShowInstalledAndUninstalledApps) + selection, err := appSelectPromptFunc(ctx, clients, prompts.ShowHostedOnly, prompts.ShowInstalledAndUninstalledApps) if err != nil { return err } diff --git a/cmd/collaborators/add_test.go b/cmd/collaborators/add_test.go index 26bfff0b..69139d99 100644 --- a/cmd/collaborators/add_test.go +++ b/cmd/collaborators/add_test.go @@ -35,8 +35,8 @@ func TestAddCommand(t *testing.T) { cm.AddDefaultMocks() // Mock App Selection appSelectMock := prompts.NewAppSelectMock() - teamAppSelectPromptFunc = appSelectMock.TeamAppSelectPrompt - appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{App: types.App{AppID: "A123"}, Auth: types.SlackAuth{}}, nil) + appSelectPromptFunc = appSelectMock.AppSelectPrompt + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowHostedOnly, prompts.ShowInstalledAndUninstalledApps).Return(prompts.SelectedApp{App: types.App{AppID: "A123"}, Auth: types.SlackAuth{}}, nil) // Set experiment flag cm.Config.ExperimentsFlag = append(cm.Config.ExperimentsFlag, "read-only-collaborators") cm.Config.LoadExperiments(ctx, cm.IO.PrintDebug) @@ -59,8 +59,8 @@ func TestAddCommand(t *testing.T) { cm.AddDefaultMocks() // Mock App Selection appSelectMock := prompts.NewAppSelectMock() - teamAppSelectPromptFunc = appSelectMock.TeamAppSelectPrompt - appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{App: types.App{AppID: "A123"}, Auth: types.SlackAuth{}}, nil) + appSelectPromptFunc = appSelectMock.AppSelectPrompt + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowHostedOnly, prompts.ShowInstalledAndUninstalledApps).Return(prompts.SelectedApp{App: types.App{AppID: "A123"}, Auth: types.SlackAuth{}}, nil) // Set experiment flag cm.Config.ExperimentsFlag = append(cm.Config.ExperimentsFlag, "read-only-collaborators") cm.Config.LoadExperiments(ctx, cm.IO.PrintDebug) @@ -84,8 +84,8 @@ func TestAddCommand(t *testing.T) { cm.AddDefaultMocks() // Mock App Selection appSelectMock := prompts.NewAppSelectMock() - teamAppSelectPromptFunc = appSelectMock.TeamAppSelectPrompt - appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{App: types.App{AppID: "A123"}, Auth: types.SlackAuth{}}, nil) + appSelectPromptFunc = appSelectMock.AppSelectPrompt + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowHostedOnly, prompts.ShowInstalledAndUninstalledApps).Return(prompts.SelectedApp{App: types.App{AppID: "A123"}, Auth: types.SlackAuth{}}, nil) // Mock API call cm.API.On("AddCollaborator", mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(nil) diff --git a/cmd/collaborators/collaborators.go b/cmd/collaborators/collaborators.go index 52c85834..8a155f0e 100644 --- a/cmd/collaborators/collaborators.go +++ b/cmd/collaborators/collaborators.go @@ -26,8 +26,8 @@ import ( "github.com/spf13/cobra" ) -// teamAppSelectPromptFunc is a handle to the TeamAppSelectPrompt that can be mocked in tests -var teamAppSelectPromptFunc = prompts.TeamAppSelectPrompt +// appSelectPromptFunc is a handle to the AppSelectPrompt that can be mocked in tests +var appSelectPromptFunc = prompts.AppSelectPrompt func NewCommand(clients *shared.ClientFactory) *cobra.Command { cmd := &cobra.Command{ diff --git a/cmd/collaborators/collaborators_test.go b/cmd/collaborators/collaborators_test.go index 886a10c9..4b0bf1a5 100644 --- a/cmd/collaborators/collaborators_test.go +++ b/cmd/collaborators/collaborators_test.go @@ -102,8 +102,8 @@ func TestCollaboratorsCommand(t *testing.T) { t.Run(name, func(t *testing.T) { ctx := slackcontext.MockContext(t.Context()) appSelectMock := prompts.NewAppSelectMock() - teamAppSelectPromptFunc = appSelectMock.TeamAppSelectPrompt - appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{App: tt.app, Auth: types.SlackAuth{}}, nil) + appSelectPromptFunc = appSelectMock.AppSelectPrompt + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowHostedOnly, prompts.ShowInstalledAndUninstalledApps).Return(prompts.SelectedApp{App: tt.app, Auth: types.SlackAuth{}}, nil) clientsMock := shared.NewClientsMock() clientsMock.AddDefaultMocks() clientsMock.API.On("ListCollaborators", mock.Anything, mock.Anything, mock.Anything). diff --git a/cmd/collaborators/list.go b/cmd/collaborators/list.go index 0881bcfc..e12fc35d 100644 --- a/cmd/collaborators/list.go +++ b/cmd/collaborators/list.go @@ -58,7 +58,7 @@ func runListCommand(cmd *cobra.Command, clients *shared.ClientFactory) error { defer span.Finish() // Get the app auth selection from the flag or prompt - selection, err := teamAppSelectPromptFunc(ctx, clients, prompts.ShowHostedOnly, prompts.ShowInstalledAndUninstalledApps) + selection, err := appSelectPromptFunc(ctx, clients, prompts.ShowHostedOnly, prompts.ShowInstalledAndUninstalledApps) if err != nil { return err } diff --git a/cmd/collaborators/list_test.go b/cmd/collaborators/list_test.go index 7b08dc46..1d4e7a9d 100644 --- a/cmd/collaborators/list_test.go +++ b/cmd/collaborators/list_test.go @@ -102,8 +102,8 @@ func TestListCommand(t *testing.T) { t.Run(name, func(t *testing.T) { ctx := slackcontext.MockContext(t.Context()) appSelectMock := prompts.NewAppSelectMock() - teamAppSelectPromptFunc = appSelectMock.TeamAppSelectPrompt - appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{App: tt.app, Auth: types.SlackAuth{}}, nil) + appSelectPromptFunc = appSelectMock.AppSelectPrompt + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowHostedOnly, prompts.ShowInstalledAndUninstalledApps).Return(prompts.SelectedApp{App: tt.app, Auth: types.SlackAuth{}}, nil) clientsMock := shared.NewClientsMock() clientsMock.AddDefaultMocks() clientsMock.API.On("ListCollaborators", mock.Anything, mock.Anything, mock.Anything). diff --git a/cmd/collaborators/remove.go b/cmd/collaborators/remove.go index bea987ca..955ac330 100644 --- a/cmd/collaborators/remove.go +++ b/cmd/collaborators/remove.go @@ -59,7 +59,7 @@ func runRemoveCommandFunc(ctx context.Context, clients *shared.ClientFactory, cm var span opentracing.Span span, ctx = opentracing.StartSpanFromContext(ctx, "cmd.Collaborators.Remove") defer span.Finish() - selection, err := teamAppSelectPromptFunc(ctx, clients, prompts.ShowHostedOnly, prompts.ShowInstalledAndUninstalledApps) + selection, err := appSelectPromptFunc(ctx, clients, prompts.ShowHostedOnly, prompts.ShowInstalledAndUninstalledApps) if err != nil { return err } diff --git a/cmd/collaborators/remove_test.go b/cmd/collaborators/remove_test.go index af5ee8c9..0877fe64 100644 --- a/cmd/collaborators/remove_test.go +++ b/cmd/collaborators/remove_test.go @@ -53,8 +53,8 @@ func TestRemoveCommand(t *testing.T) { CmdArgs: []string{"USLACKBOT"}, Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { appSelectMock := prompts.NewAppSelectMock() - teamAppSelectPromptFunc = appSelectMock.TeamAppSelectPrompt - appSelectMock.On("TeamAppSelectPrompt"). + appSelectPromptFunc = appSelectMock.AppSelectPrompt + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowHostedOnly, prompts.ShowInstalledAndUninstalledApps). Return(mockSelection, nil) cm.API.On("RemoveCollaborator", mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(nil) @@ -72,8 +72,8 @@ func TestRemoveCommand(t *testing.T) { CmdArgs: []string{}, Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { appSelectMock := prompts.NewAppSelectMock() - teamAppSelectPromptFunc = appSelectMock.TeamAppSelectPrompt - appSelectMock.On("TeamAppSelectPrompt"). + appSelectPromptFunc = appSelectMock.AppSelectPrompt + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowHostedOnly, prompts.ShowInstalledAndUninstalledApps). Return(mockSelection, nil) cm.API.On("RemoveCollaborator", mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(nil) @@ -93,8 +93,8 @@ func TestRemoveCommand(t *testing.T) { CmdArgs: []string{}, Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { appSelectMock := prompts.NewAppSelectMock() - teamAppSelectPromptFunc = appSelectMock.TeamAppSelectPrompt - appSelectMock.On("TeamAppSelectPrompt"). + appSelectPromptFunc = appSelectMock.AppSelectPrompt + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowHostedOnly, prompts.ShowInstalledAndUninstalledApps). Return(mockSelection, nil) cm.API.On("RemoveCollaborator", mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(nil) diff --git a/cmd/collaborators/update.go b/cmd/collaborators/update.go index f4efa674..78e056bb 100644 --- a/cmd/collaborators/update.go +++ b/cmd/collaborators/update.go @@ -97,7 +97,7 @@ func runUpdateCommand(cmd *cobra.Command, clients *shared.ClientFactory, args [] } // Get the app auth selection from the flag or prompt - selection, err := teamAppSelectPromptFunc(ctx, clients, prompts.ShowHostedOnly, prompts.ShowInstalledAndUninstalledApps) + selection, err := appSelectPromptFunc(ctx, clients, prompts.ShowHostedOnly, prompts.ShowInstalledAndUninstalledApps) if err != nil { return err } diff --git a/cmd/collaborators/update_test.go b/cmd/collaborators/update_test.go index 32872edd..f2ab1ed4 100644 --- a/cmd/collaborators/update_test.go +++ b/cmd/collaborators/update_test.go @@ -35,8 +35,8 @@ func TestUpdateCommand(t *testing.T) { clientsMock.AddDefaultMocks() // Mock App Selection appSelectMock := prompts.NewAppSelectMock() - teamAppSelectPromptFunc = appSelectMock.TeamAppSelectPrompt - appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{App: types.App{AppID: "A123"}, Auth: types.SlackAuth{}}, nil) + appSelectPromptFunc = appSelectMock.AppSelectPrompt + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowHostedOnly, prompts.ShowInstalledAndUninstalledApps).Return(prompts.SelectedApp{App: types.App{AppID: "A123"}, Auth: types.SlackAuth{}}, nil) // Set experiment flag clientsMock.Config.ExperimentsFlag = append(clientsMock.Config.ExperimentsFlag, "read-only-collaborators") clientsMock.Config.LoadExperiments(ctx, clientsMock.IO.PrintDebug) @@ -53,8 +53,8 @@ func TestUpdateCommand(t *testing.T) { clientsMock.AddDefaultMocks() // Mock App Selection appSelectMock := prompts.NewAppSelectMock() - teamAppSelectPromptFunc = appSelectMock.TeamAppSelectPrompt - appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{App: types.App{AppID: "A123"}, Auth: types.SlackAuth{}}, nil) + appSelectPromptFunc = appSelectMock.AppSelectPrompt + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowHostedOnly, prompts.ShowInstalledAndUninstalledApps).Return(prompts.SelectedApp{App: types.App{AppID: "A123"}, Auth: types.SlackAuth{}}, nil) // Set experiment flag clientsMock.Config.ExperimentsFlag = append(clientsMock.Config.ExperimentsFlag, "read-only-collaborators") clientsMock.Config.LoadExperiments(ctx, clientsMock.IO.PrintDebug) diff --git a/cmd/datastore/bulk_delete.go b/cmd/datastore/bulk_delete.go index 6a3111e0..8684dc39 100644 --- a/cmd/datastore/bulk_delete.go +++ b/cmd/datastore/bulk_delete.go @@ -73,7 +73,7 @@ func NewBulkDeleteCommand(clients *shared.ClientFactory) *cobra.Command { } // Get the app auth selection from the flag or prompt - selection, err := appSelectPromptFunc(ctx, clients, prompts.ShowInstalledAppsOnly) + selection, err := appSelectPromptFunc(ctx, clients, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly) if err != nil { return err } diff --git a/cmd/datastore/bulk_get.go b/cmd/datastore/bulk_get.go index 4bab47e8..e293f3ff 100644 --- a/cmd/datastore/bulk_get.go +++ b/cmd/datastore/bulk_get.go @@ -75,7 +75,7 @@ func NewBulkGetCommand(clients *shared.ClientFactory) *cobra.Command { } // Get the app auth selection from the flag or prompt - selection, err := appSelectPromptFunc(ctx, clients, prompts.ShowInstalledAppsOnly) + selection, err := appSelectPromptFunc(ctx, clients, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly) if err != nil { return err } diff --git a/cmd/datastore/bulk_put.go b/cmd/datastore/bulk_put.go index 16cbddbd..a86c130a 100644 --- a/cmd/datastore/bulk_put.go +++ b/cmd/datastore/bulk_put.go @@ -88,7 +88,7 @@ func NewBulkPutCommand(clients *shared.ClientFactory) *cobra.Command { } // Get the selection from the flag or prompt - selection, err := appSelectPromptFunc(ctx, clients, prompts.ShowInstalledAppsOnly) + selection, err := appSelectPromptFunc(ctx, clients, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly) if err != nil { return err } diff --git a/cmd/datastore/count.go b/cmd/datastore/count.go index d8d33288..cc175897 100644 --- a/cmd/datastore/count.go +++ b/cmd/datastore/count.go @@ -113,7 +113,7 @@ func runCountCommandFunc( } // Get the app from the flag or prompt - selection, err := appSelectPromptFunc(ctx, clients, prompts.ShowInstalledAppsOnly) + selection, err := appSelectPromptFunc(ctx, clients, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly) if err != nil { return err } diff --git a/cmd/datastore/count_test.go b/cmd/datastore/count_test.go index e2b85ad2..7a52b2c5 100644 --- a/cmd/datastore/count_test.go +++ b/cmd/datastore/count_test.go @@ -348,7 +348,7 @@ func TestCountCommand(t *testing.T) { } appSelectMock := prompts.NewAppSelectMock() appSelectPromptFunc = appSelectMock.AppSelectPrompt - appSelectMock.On("AppSelectPrompt"). + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly). Return(prompts.SelectedApp{App: types.App{AppID: "A001"}}, nil) return cmd }) diff --git a/cmd/datastore/datastore_test.go b/cmd/datastore/datastore_test.go index 1b5c2bbf..5d47c5d5 100644 --- a/cmd/datastore/datastore_test.go +++ b/cmd/datastore/datastore_test.go @@ -59,7 +59,7 @@ func setupDatastoreMocks() *shared.ClientsMock { // Select the same example app each time appSelectMock := prompts.NewAppSelectMock() appSelectPromptFunc = appSelectMock.AppSelectPrompt - appSelectMock.On("AppSelectPrompt").Return(prompts.SelectedApp{ + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly).Return(prompts.SelectedApp{ App: types.App{AppID: mockAppID}, }, nil) diff --git a/cmd/datastore/delete.go b/cmd/datastore/delete.go index a36831a3..1a13954b 100644 --- a/cmd/datastore/delete.go +++ b/cmd/datastore/delete.go @@ -75,7 +75,7 @@ func NewDeleteCommand(clients *shared.ClientFactory) *cobra.Command { } // Get the app auth selection from the flag or prompt - selection, err := appSelectPromptFunc(ctx, clients, prompts.ShowInstalledAppsOnly) + selection, err := appSelectPromptFunc(ctx, clients, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly) if err != nil { return err } diff --git a/cmd/datastore/get.go b/cmd/datastore/get.go index 659d9bdf..2a75f706 100644 --- a/cmd/datastore/get.go +++ b/cmd/datastore/get.go @@ -77,7 +77,7 @@ func NewGetCommand(clients *shared.ClientFactory) *cobra.Command { } // Get the app auth selection from the flag or prompt - selection, err := appSelectPromptFunc(ctx, clients, prompts.ShowInstalledAppsOnly) + selection, err := appSelectPromptFunc(ctx, clients, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly) if err != nil { return err } diff --git a/cmd/datastore/put.go b/cmd/datastore/put.go index 564df6f5..e3a5bce7 100644 --- a/cmd/datastore/put.go +++ b/cmd/datastore/put.go @@ -76,7 +76,7 @@ func NewPutCommand(clients *shared.ClientFactory) *cobra.Command { } // Get the selection from the flag or prompt - selection, err := appSelectPromptFunc(ctx, clients, prompts.ShowInstalledAppsOnly) + selection, err := appSelectPromptFunc(ctx, clients, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly) if err != nil { return err } diff --git a/cmd/datastore/query.go b/cmd/datastore/query.go index 082d0ef2..776a93d5 100644 --- a/cmd/datastore/query.go +++ b/cmd/datastore/query.go @@ -99,7 +99,7 @@ func NewQueryCommand(clients *shared.ClientFactory) *cobra.Command { } // Get the selection from the flag or prompt - selection, err := appSelectPromptFunc(ctx, clients, prompts.ShowInstalledAppsOnly) + selection, err := appSelectPromptFunc(ctx, clients, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly) if err != nil { return err } diff --git a/cmd/datastore/update.go b/cmd/datastore/update.go index 344ea012..cb2633ea 100644 --- a/cmd/datastore/update.go +++ b/cmd/datastore/update.go @@ -76,7 +76,7 @@ func NewUpdateCommand(clients *shared.ClientFactory) *cobra.Command { } // Get the selection and auth selection from the flag or prompt - selection, err := appSelectPromptFunc(ctx, clients, prompts.ShowInstalledAppsOnly) + selection, err := appSelectPromptFunc(ctx, clients, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly) if err != nil { return err } diff --git a/cmd/env/add.go b/cmd/env/add.go index efe76909..dbd0e6a3 100644 --- a/cmd/env/add.go +++ b/cmd/env/add.go @@ -88,7 +88,7 @@ func runEnvAddCommandFunc(clients *shared.ClientFactory, cmd *cobra.Command, arg ctx := cmd.Context() // Get the workspace from the flag or prompt - selection, err := teamAppSelectPromptFunc(ctx, clients, prompts.ShowHostedOnly, prompts.ShowInstalledAppsOnly) + selection, err := appSelectPromptFunc(ctx, clients, prompts.ShowHostedOnly, prompts.ShowInstalledAppsOnly) if err != nil { return err } diff --git a/cmd/env/add_test.go b/cmd/env/add_test.go index b8caa592..9e8f8f1d 100644 --- a/cmd/env/add_test.go +++ b/cmd/env/add_test.go @@ -283,8 +283,8 @@ func setupEnvAddCommandMocks(ctx context.Context, cm *shared.ClientsMock, cf *sh _ = cf.AppClient().SaveDeployed(ctx, mockApp) appSelectMock := prompts.NewAppSelectMock() - teamAppSelectPromptFunc = appSelectMock.TeamAppSelectPrompt - appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{Auth: mockAuth, App: mockApp}, nil) + appSelectPromptFunc = appSelectMock.AppSelectPrompt + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowHostedOnly, prompts.ShowInstalledAppsOnly).Return(prompts.SelectedApp{Auth: mockAuth, App: mockApp}, nil) cm.Config.Flags.String("value", "", "mock value flag") diff --git a/cmd/env/env.go b/cmd/env/env.go index 43998107..2fa27cab 100644 --- a/cmd/env/env.go +++ b/cmd/env/env.go @@ -27,8 +27,8 @@ import ( var variableNameFlag string var variableValueFlag string -// teamAppSelectPromptFunc is a handle to the TeamAppSelectPrompt that can be mocked in tests -var teamAppSelectPromptFunc = prompts.TeamAppSelectPrompt +// appSelectPromptFunc is a handle to the AppSelectPrompt that can be mocked in tests +var appSelectPromptFunc = prompts.AppSelectPrompt func NewCommand(clients *shared.ClientFactory) *cobra.Command { cmd := &cobra.Command{ diff --git a/cmd/env/list.go b/cmd/env/list.go index beb98862..faa3f2dc 100644 --- a/cmd/env/list.go +++ b/cmd/env/list.go @@ -78,7 +78,7 @@ func runEnvListCommandFunc( ) error { ctx := cmd.Context() - selection, err := teamAppSelectPromptFunc( + selection, err := appSelectPromptFunc( ctx, clients, prompts.ShowHostedOnly, diff --git a/cmd/env/list_test.go b/cmd/env/list_test.go index 803a98ee..1b64c78b 100644 --- a/cmd/env/list_test.go +++ b/cmd/env/list_test.go @@ -146,8 +146,8 @@ func Test_Env_ListCommand(t *testing.T) { nil, ) appSelectMock := prompts.NewAppSelectMock() - teamAppSelectPromptFunc = appSelectMock.TeamAppSelectPrompt - appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{}, nil) + appSelectPromptFunc = appSelectMock.AppSelectPrompt + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowHostedOnly, prompts.ShowInstalledAppsOnly).Return(prompts.SelectedApp{}, nil) }, ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { cm.API.AssertCalled( diff --git a/cmd/env/remove.go b/cmd/env/remove.go index 509f9b84..17711302 100644 --- a/cmd/env/remove.go +++ b/cmd/env/remove.go @@ -85,7 +85,7 @@ func runEnvRemoveCommandFunc(clients *shared.ClientFactory, cmd *cobra.Command, var ctx = cmd.Context() // Get the workspace from the flag or prompt - selection, err := teamAppSelectPromptFunc(ctx, clients, prompts.ShowHostedOnly, prompts.ShowInstalledAppsOnly) + selection, err := appSelectPromptFunc(ctx, clients, prompts.ShowHostedOnly, prompts.ShowInstalledAppsOnly) if err != nil { return err } diff --git a/cmd/env/remove_test.go b/cmd/env/remove_test.go index f2e79d43..57d8aac3 100644 --- a/cmd/env/remove_test.go +++ b/cmd/env/remove_test.go @@ -153,8 +153,8 @@ func Test_Env_RemoveCommand(t *testing.T) { nil, ) appSelectMock := prompts.NewAppSelectMock() - teamAppSelectPromptFunc = appSelectMock.TeamAppSelectPrompt - appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{}, nil) + appSelectPromptFunc = appSelectMock.AppSelectPrompt + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowHostedOnly, prompts.ShowInstalledAppsOnly).Return(prompts.SelectedApp{}, nil) }, ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { cm.API.AssertCalled( @@ -212,8 +212,8 @@ func Test_Env_RemoveCommand(t *testing.T) { nil, ) appSelectMock := prompts.NewAppSelectMock() - teamAppSelectPromptFunc = appSelectMock.TeamAppSelectPrompt - appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{}, nil) + appSelectPromptFunc = appSelectMock.AppSelectPrompt + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowHostedOnly, prompts.ShowInstalledAppsOnly).Return(prompts.SelectedApp{}, nil) }, ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { cm.API.AssertCalled( @@ -246,8 +246,8 @@ func Test_Env_RemoveCommand(t *testing.T) { nil, ) appSelectMock := prompts.NewAppSelectMock() - teamAppSelectPromptFunc = appSelectMock.TeamAppSelectPrompt - appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{}, nil) + appSelectPromptFunc = appSelectMock.AppSelectPrompt + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowHostedOnly, prompts.ShowInstalledAppsOnly).Return(prompts.SelectedApp{}, nil) }, ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) { cm.API.AssertCalled( diff --git a/cmd/externalauth/add.go b/cmd/externalauth/add.go index 06d9e165..5be8c038 100644 --- a/cmd/externalauth/add.go +++ b/cmd/externalauth/add.go @@ -83,7 +83,7 @@ func runAddCommand(clients *shared.ClientFactory, cmd *cobra.Command) error { // Get the app selection and accompanying auth from the prompt // Note: Only installed apps will be shown in the prompt as installation is required for this command. // This is consistent with the experience for other commands that require installation. - selection, err := appSelectPromptFunc(ctx, clients, prompts.ShowInstalledAppsOnly) + selection, err := appSelectPromptFunc(ctx, clients, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly) if err != nil { return err } diff --git a/cmd/externalauth/add_secret.go b/cmd/externalauth/add_secret.go index 1fb657bf..fa339ed5 100644 --- a/cmd/externalauth/add_secret.go +++ b/cmd/externalauth/add_secret.go @@ -86,7 +86,7 @@ func runAddClientSecretCommand(clients *shared.ClientFactory, cmd *cobra.Command ctx := cmd.Context() // Get the app selection and accompanying auth from the prompt - selection, err := appSelectPromptFunc(ctx, clients, prompts.ShowInstalledAppsOnly) + selection, err := appSelectPromptFunc(ctx, clients, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly) if err != nil { return err } diff --git a/cmd/externalauth/helpers_test.go b/cmd/externalauth/helpers_test.go index 6434696f..c0db69c2 100644 --- a/cmd/externalauth/helpers_test.go +++ b/cmd/externalauth/helpers_test.go @@ -17,6 +17,7 @@ package externalauth import ( "github.com/slackapi/slack-cli/internal/prompts" "github.com/slackapi/slack-cli/internal/shared/types" + "github.com/stretchr/testify/mock" ) var fakeAppID = "A1234" @@ -38,7 +39,7 @@ func setupMockAppSelection(selectedApp prompts.SelectedApp) func() { appSelectMock := prompts.NewAppSelectMock() var originalPromptFunc = appSelectPromptFunc appSelectPromptFunc = appSelectMock.AppSelectPrompt - appSelectMock.On("AppSelectPrompt").Return(selectedApp, nil) + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly).Return(selectedApp, nil) return func() { appSelectPromptFunc = originalPromptFunc } diff --git a/cmd/externalauth/remove.go b/cmd/externalauth/remove.go index 7740b776..4fece1d2 100644 --- a/cmd/externalauth/remove.go +++ b/cmd/externalauth/remove.go @@ -95,7 +95,7 @@ func runRemoveCommand(clients *shared.ClientFactory, cmd *cobra.Command) error { ctx := cmd.Context() // Get the app selection and accompanying auth from the prompt - selection, err := appSelectPromptFunc(ctx, clients, prompts.ShowInstalledAppsOnly) + selection, err := appSelectPromptFunc(ctx, clients, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly) if err != nil { return err } diff --git a/cmd/externalauth/select_auth.go b/cmd/externalauth/select_auth.go index e44aed14..9ce1bf7b 100644 --- a/cmd/externalauth/select_auth.go +++ b/cmd/externalauth/select_auth.go @@ -86,7 +86,7 @@ func runSelectAuthCommand(clients *shared.ClientFactory, cmd *cobra.Command) err ctx := cmd.Context() // Get the app selection and accompanying auth from the prompt - selection, err := appSelectPromptFunc(ctx, clients, prompts.ShowInstalledAppsOnly) + selection, err := appSelectPromptFunc(ctx, clients, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly) if err != nil { return err } diff --git a/cmd/function/access.go b/cmd/function/access.go index 1c0ba42a..4c0b1a9e 100644 --- a/cmd/function/access.go +++ b/cmd/function/access.go @@ -91,7 +91,7 @@ func runDistributeCommand(cmd *cobra.Command, clients *shared.ClientFactory) err ctx := cmd.Context() // Get the app selection and accompanying auth from the prompt - selectedApp, err := appSelectPromptFunc(ctx, clients, prompts.ShowInstalledAppsOnly) + selectedApp, err := appSelectPromptFunc(ctx, clients, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly) if err != nil { return err } diff --git a/cmd/function/helpers_test.go b/cmd/function/helpers_test.go index 749cbb59..44b9a627 100644 --- a/cmd/function/helpers_test.go +++ b/cmd/function/helpers_test.go @@ -17,6 +17,7 @@ package function import ( "github.com/slackapi/slack-cli/internal/prompts" "github.com/slackapi/slack-cli/internal/shared/types" + "github.com/stretchr/testify/mock" ) var ( @@ -37,7 +38,7 @@ func setupMockAppSelection(selectedApp prompts.SelectedApp) func() { appSelectMock := prompts.NewAppSelectMock() var originalPromptFunc = appSelectPromptFunc appSelectPromptFunc = appSelectMock.AppSelectPrompt - appSelectMock.On("AppSelectPrompt").Return(selectedApp, nil) + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly).Return(selectedApp, nil) return func() { appSelectPromptFunc = originalPromptFunc } diff --git a/cmd/manifest/info.go b/cmd/manifest/info.go index b8e6126e..2603d076 100644 --- a/cmd/manifest/info.go +++ b/cmd/manifest/info.go @@ -129,7 +129,7 @@ func getManifestInfoProject(ctx context.Context, clients *shared.ClientFactory) // getManifestInfoRemote gathers app manifest information from app settings func getManifestInfoRemote(ctx context.Context, clients *shared.ClientFactory) (types.AppManifest, error) { - selection, err := appSelectPromptFunc(ctx, clients, prompts.ShowInstalledAndUninstalledApps) + selection, err := appSelectPromptFunc(ctx, clients, prompts.ShowAllEnvironments, prompts.ShowInstalledAndUninstalledApps) if err != nil { return types.AppManifest{}, err } diff --git a/cmd/manifest/info_test.go b/cmd/manifest/info_test.go index 0c77d100..590e2671 100644 --- a/cmd/manifest/info_test.go +++ b/cmd/manifest/info_test.go @@ -82,7 +82,7 @@ func TestInfoCommand(t *testing.T) { Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { appSelectMock := prompts.NewAppSelectMock() appSelectPromptFunc = appSelectMock.AppSelectPrompt - appSelectMock.On("AppSelectPrompt").Return( + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowAllEnvironments, prompts.ShowInstalledAndUninstalledApps).Return( prompts.SelectedApp{ App: types.App{AppID: "A001"}, Auth: types.SlackAuth{Token: "xapp"}}, nil) @@ -112,7 +112,7 @@ func TestInfoCommand(t *testing.T) { Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { appSelectMock := prompts.NewAppSelectMock() appSelectPromptFunc = appSelectMock.AppSelectPrompt - appSelectMock.On("AppSelectPrompt").Return( + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowAllEnvironments, prompts.ShowInstalledAndUninstalledApps).Return( prompts.SelectedApp{ App: types.App{AppID: "A004"}, Auth: types.SlackAuth{Token: "xapp"}}, nil) @@ -163,7 +163,7 @@ func TestInfoCommand(t *testing.T) { cf.AppClient().Manifest = manifestMock appSelectMock := prompts.NewAppSelectMock() appSelectPromptFunc = appSelectMock.AppSelectPrompt - appSelectMock.On("AppSelectPrompt").Return(prompts.SelectedApp{ + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowAllEnvironments, prompts.ShowInstalledAndUninstalledApps).Return(prompts.SelectedApp{ App: types.App{AppID: "A005"}, Auth: types.SlackAuth{Token: "xapp-example-005"}, }, nil) diff --git a/cmd/manifest/manifest_test.go b/cmd/manifest/manifest_test.go index 75a30488..9dda661d 100644 --- a/cmd/manifest/manifest_test.go +++ b/cmd/manifest/manifest_test.go @@ -38,7 +38,7 @@ func TestManifestCommand(t *testing.T) { Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) { appSelectMock := prompts.NewAppSelectMock() appSelectPromptFunc = appSelectMock.AppSelectPrompt - appSelectMock.On("AppSelectPrompt").Return( + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowAllEnvironments, prompts.ShowInstalledAndUninstalledApps).Return( prompts.SelectedApp{ App: types.App{AppID: "A001"}, Auth: types.SlackAuth{Token: "xapp"}, diff --git a/cmd/manifest/validate.go b/cmd/manifest/validate.go index 36af907e..4ac7634d 100644 --- a/cmd/manifest/validate.go +++ b/cmd/manifest/validate.go @@ -62,7 +62,7 @@ func NewValidateCommand(clients *shared.ClientFactory) *cobra.Command { // Get the app selection and accompanying auth of an installed app or gather // some other authentication token var token string - selection, err := appSelectPromptFunc(ctx, clients, prompts.ShowInstalledAppsOnly) + selection, err := appSelectPromptFunc(ctx, clients, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly) if err != nil { if slackerror.ToSlackError(err).Code != slackerror.ErrInstallationRequired { return err diff --git a/cmd/manifest/validate_test.go b/cmd/manifest/validate_test.go index 7c9e69cb..3f58a3c5 100644 --- a/cmd/manifest/validate_test.go +++ b/cmd/manifest/validate_test.go @@ -58,7 +58,7 @@ func TestManifestValidateCommand(t *testing.T) { appSelectMock := prompts.NewAppSelectMock() appSelectPromptFunc = appSelectMock.AppSelectPrompt - appSelectMock.On("AppSelectPrompt").Return(prompts.SelectedApp{}, nil) + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly).Return(prompts.SelectedApp{}, nil) manifestValidatePkgMock := new(ManifestValidatePkgMock) manifestValidateFunc = manifestValidatePkgMock.ManifestValidate @@ -89,7 +89,7 @@ func TestManifestValidateCommand_HandleMissingAppInstallError_ZeroUserAuth(t *te // Mock a failed AppSelectPrompt appSelectMock := prompts.NewAppSelectMock() appSelectPromptFunc = appSelectMock.AppSelectPrompt - appSelectMock.On("AppSelectPrompt").Return(prompts.SelectedApp{}, slackerror.New(slackerror.ErrInstallationRequired)) + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly).Return(prompts.SelectedApp{}, slackerror.New(slackerror.ErrInstallationRequired)) // Mock zero user auths mockAuths := []types.SlackAuth{} @@ -133,7 +133,7 @@ func TestManifestValidateCommand_HandleMissingAppInstallError_OneUserAuth(t *tes // Mock a failed AppSelectPrompt appSelectMock := prompts.NewAppSelectMock() appSelectPromptFunc = appSelectMock.AppSelectPrompt - appSelectMock.On("AppSelectPrompt").Return(prompts.SelectedApp{}, slackerror.New(slackerror.ErrInstallationRequired)) + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly).Return(prompts.SelectedApp{}, slackerror.New(slackerror.ErrInstallationRequired)) // Mock the manifest validate package manifestValidatePkgMock := new(ManifestValidatePkgMock) @@ -163,7 +163,7 @@ func TestManifestValidateCommand_HandleMissingAppInstallError_MoreThanOneUserAut // Mock a failed AppSelectPrompt appSelectMock := prompts.NewAppSelectMock() appSelectPromptFunc = appSelectMock.AppSelectPrompt - appSelectMock.On("AppSelectPrompt").Return(prompts.SelectedApp{}, slackerror.New(slackerror.ErrInstallationRequired)) + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly).Return(prompts.SelectedApp{}, slackerror.New(slackerror.ErrInstallationRequired)) clientsMock.IO.On("SelectPrompt", mock.Anything, prompts.SelectTeamPrompt, mock.Anything, iostreams.MatchPromptConfig(iostreams.SelectPromptConfig{ Flag: clients.Config.Flags.Lookup("team"), })).Return(iostreams.SelectPromptResponse{ @@ -227,7 +227,7 @@ func TestManifestValidateCommand_HandleOtherErrors(t *testing.T) { appSelectMock := prompts.NewAppSelectMock() appSelectPromptFunc = appSelectMock.AppSelectPrompt errMsg := "Unrelated error" - appSelectMock.On("AppSelectPrompt").Return(prompts.SelectedApp{}, slackerror.New(errMsg)) + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly).Return(prompts.SelectedApp{}, slackerror.New(errMsg)) err := cmd.ExecuteContext(ctx) require.ErrorContains(t, err, errMsg) diff --git a/cmd/openformresponse/export.go b/cmd/openformresponse/export.go index 1f6895db..25952879 100644 --- a/cmd/openformresponse/export.go +++ b/cmd/openformresponse/export.go @@ -68,7 +68,7 @@ func runExportCommand(clients *shared.ClientFactory, cmd *cobra.Command) error { var span, _ = opentracing.StartSpanFromContext(ctx, "cmd.open-form-response.export") defer span.Finish() - selection, err := exportAppSelectPromptFunc(ctx, clients, prompts.ShowInstalledAppsOnly) + selection, err := exportAppSelectPromptFunc(ctx, clients, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly) if err != nil { return err } diff --git a/cmd/openformresponse/export_test.go b/cmd/openformresponse/export_test.go index 596fec45..46671a7d 100644 --- a/cmd/openformresponse/export_test.go +++ b/cmd/openformresponse/export_test.go @@ -83,7 +83,7 @@ func setupMockCreateAppSelection(selectedApp prompts.SelectedApp) func() { appSelectMock := prompts.NewAppSelectMock() var originalPromptFunc = exportAppSelectPromptFunc exportAppSelectPromptFunc = appSelectMock.AppSelectPrompt - appSelectMock.On("AppSelectPrompt").Return(selectedApp, nil) + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly).Return(selectedApp, nil) return func() { exportAppSelectPromptFunc = originalPromptFunc } diff --git a/cmd/platform/activity.go b/cmd/platform/activity.go index 01a67c2e..96162a2f 100644 --- a/cmd/platform/activity.go +++ b/cmd/platform/activity.go @@ -105,7 +105,7 @@ func runActivityCommand(clients *shared.ClientFactory, cmd *cobra.Command, args } // Prompt for an installed app - selection, err := appSelectPromptFunc(ctx, clients, prompts.ShowInstalledAppsOnly) + selection, err := appSelectPromptFunc(ctx, clients, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly) if err != nil { return err } diff --git a/cmd/platform/activity_test.go b/cmd/platform/activity_test.go index ba9919d9..e947e868 100644 --- a/cmd/platform/activity_test.go +++ b/cmd/platform/activity_test.go @@ -65,7 +65,7 @@ func TestActivity_Command(t *testing.T) { appSelectMock := prompts.NewAppSelectMock() appSelectPromptFunc = appSelectMock.AppSelectPrompt - appSelectMock.On("AppSelectPrompt").Return(prompts.SelectedApp{}, nil) + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly).Return(prompts.SelectedApp{}, nil) err := cmd.ExecuteContext(ctx) if err != nil { diff --git a/cmd/platform/deploy.go b/cmd/platform/deploy.go index 4d2fb191..0a15b78e 100644 --- a/cmd/platform/deploy.go +++ b/cmd/platform/deploy.go @@ -41,7 +41,6 @@ import ( // Create handle to Deploy function for testing // TODO - Stopgap until we learn the correct way to structure our code for testing. var deployFunc = platform.Deploy -var teamAppSelectPromptFunc = prompts.TeamAppSelectPrompt // TODO - Same as above, but probably even worse var runAddCommandFunc = app.RunAddCommand @@ -79,7 +78,7 @@ func NewDeployCommand(clients *shared.ClientFactory) *cobra.Command { deploySpinner.Stop() }() - selection, err := teamAppSelectPromptFunc(ctx, clients, prompts.ShowHostedOnly, prompts.ShowAllApps) + selection, err := appSelectPromptFunc(ctx, clients, prompts.ShowHostedOnly, prompts.ShowAllApps) if err != nil { return err } diff --git a/cmd/platform/deploy_test.go b/cmd/platform/deploy_test.go index e3706abc..f30451d8 100644 --- a/cmd/platform/deploy_test.go +++ b/cmd/platform/deploy_test.go @@ -84,8 +84,8 @@ func TestDeployCommand(t *testing.T) { }, nil) appSelectMock := prompts.NewAppSelectMock() - appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{}, nil) - teamAppSelectPromptFunc = appSelectMock.TeamAppSelectPrompt + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowHostedOnly, prompts.ShowAllApps).Return(prompts.SelectedApp{}, nil) + appSelectPromptFunc = appSelectMock.AppSelectPrompt manifestMock := &app.ManifestMockObject{} manifestMock.On("GetManifestLocal", mock.Anything, mock.Anything, mock.Anything).Return(types.SlackYaml{ diff --git a/cmd/platform/run.go b/cmd/platform/run.go index c424b037..a755a559 100644 --- a/cmd/platform/run.go +++ b/cmd/platform/run.go @@ -45,7 +45,7 @@ var runFlags runCmdFlags // TODO - Stopgap until we learn the correct way to structure our code for testing. var runFunc = platform.Run var runRunCommandFunc = RunRunCommand -var runTeamAppSelectPromptFunc = prompts.TeamAppSelectPrompt +var runAppSelectPromptFunc = prompts.AppSelectPrompt func NewRunCommand(clients *shared.ClientFactory) *cobra.Command { cmd := &cobra.Command{ @@ -99,7 +99,7 @@ func RunRunCommand(clients *shared.ClientFactory, cmd *cobra.Command, args []str ctx := cmd.Context() // Get the workspace from the flag or prompt - selection, err := runTeamAppSelectPromptFunc(ctx, clients, prompts.ShowLocalOnly, prompts.ShowAllApps) + selection, err := runAppSelectPromptFunc(ctx, clients, prompts.ShowLocalOnly, prompts.ShowAllApps) if err != nil { switch slackerror.ToSlackError(err).Code { case slackerror.ErrDeployedAppNotSupported: diff --git a/cmd/platform/run_test.go b/cmd/platform/run_test.go index 5f867a2c..8d478df7 100644 --- a/cmd/platform/run_test.go +++ b/cmd/platform/run_test.go @@ -217,8 +217,8 @@ func TestRunCommand_Flags(t *testing.T) { }) appSelectMock := prompts.NewAppSelectMock() - appSelectMock.On("TeamAppSelectPrompt").Return(tt.selectedAppAuth, tt.selectedAppErr) - runTeamAppSelectPromptFunc = appSelectMock.TeamAppSelectPrompt + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowLocalOnly, prompts.ShowAllApps).Return(tt.selectedAppAuth, tt.selectedAppErr) + runAppSelectPromptFunc = appSelectMock.AppSelectPrompt runPkgMock := new(RunPkgMock) runFunc = runPkgMock.Run diff --git a/cmd/triggers/access.go b/cmd/triggers/access.go index 1e8f05a7..1fd0567e 100644 --- a/cmd/triggers/access.go +++ b/cmd/triggers/access.go @@ -102,7 +102,7 @@ func runAccessCommand(cmd *cobra.Command, clients *shared.ClientFactory) error { defer span.Finish() // Get the app selection and accompanying auth from the flag or prompt - selection, err := accessAppSelectPromptFunc(ctx, clients, prompts.ShowInstalledAppsOnly) + selection, err := accessAppSelectPromptFunc(ctx, clients, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly) if err != nil { return err } diff --git a/cmd/triggers/access_test.go b/cmd/triggers/access_test.go index c8abacb5..18a5f3fd 100644 --- a/cmd/triggers/access_test.go +++ b/cmd/triggers/access_test.go @@ -601,7 +601,7 @@ func setupMockAccessAppSelection(selectedApp prompts.SelectedApp) func() { appSelectMock := prompts.NewAppSelectMock() var originalPromptFunc = accessAppSelectPromptFunc accessAppSelectPromptFunc = appSelectMock.AppSelectPrompt - appSelectMock.On("AppSelectPrompt").Return(selectedApp, nil) + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly).Return(selectedApp, nil) return func() { accessAppSelectPromptFunc = originalPromptFunc } diff --git a/cmd/triggers/create.go b/cmd/triggers/create.go index e93bae83..ed78fd6b 100644 --- a/cmd/triggers/create.go +++ b/cmd/triggers/create.go @@ -94,7 +94,7 @@ func runCreateCommand(clients *shared.ClientFactory, cmd *cobra.Command) error { defer span.Finish() // Get the app selection and accompanying auth from the flag or prompt - selection, err := createAppSelectPromptFunc(ctx, clients, prompts.ShowInstalledAndNewApps) + selection, err := createAppSelectPromptFunc(ctx, clients, prompts.ShowAllEnvironments, prompts.ShowInstalledAndNewApps) if err != nil { return err } diff --git a/cmd/triggers/create_test.go b/cmd/triggers/create_test.go index a3e389cb..cdd93aea 100644 --- a/cmd/triggers/create_test.go +++ b/cmd/triggers/create_test.go @@ -468,7 +468,7 @@ func TestTriggersCreateCommand_AppSelection(t *testing.T) { appSelectMock := prompts.NewAppSelectMock() var originalPromptFunc = createAppSelectPromptFunc createAppSelectPromptFunc = appSelectMock.AppSelectPrompt - appSelectMock.On("AppSelectPrompt").Return(prompts.SelectedApp{}, errors.New("selection error")) + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowAllEnvironments, prompts.ShowInstalledAndNewApps).Return(prompts.SelectedApp{}, errors.New("selection error")) appSelectTeardown = func() { createAppSelectPromptFunc = originalPromptFunc } @@ -673,7 +673,7 @@ func setupMockCreateAppSelection(selectedApp prompts.SelectedApp) func() { appSelectMock := prompts.NewAppSelectMock() var originalPromptFunc = createAppSelectPromptFunc createAppSelectPromptFunc = appSelectMock.AppSelectPrompt - appSelectMock.On("AppSelectPrompt").Return(selectedApp, nil) + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowAllEnvironments, prompts.ShowInstalledAndNewApps).Return(selectedApp, nil) return func() { createAppSelectPromptFunc = originalPromptFunc } diff --git a/cmd/triggers/delete.go b/cmd/triggers/delete.go index 0d133316..5523cfa3 100644 --- a/cmd/triggers/delete.go +++ b/cmd/triggers/delete.go @@ -66,7 +66,7 @@ func runDeleteCommand(clients *shared.ClientFactory, cmd *cobra.Command) error { defer span.Finish() // Get the app from the flag or prompt - selection, err := deleteAppSelectPromptFunc(ctx, clients, prompts.ShowInstalledAppsOnly) + selection, err := deleteAppSelectPromptFunc(ctx, clients, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly) if err != nil { return err } diff --git a/cmd/triggers/delete_test.go b/cmd/triggers/delete_test.go index 96786f94..cb70a0d3 100644 --- a/cmd/triggers/delete_test.go +++ b/cmd/triggers/delete_test.go @@ -117,7 +117,7 @@ func TestTriggersDeleteCommand_AppSelection(t *testing.T) { appSelectTeardown = setupMockDeleteAppSelection(installedProdApp) appSelectMock := prompts.NewAppSelectMock() deleteAppSelectPromptFunc = appSelectMock.AppSelectPrompt - appSelectMock.On("AppSelectPrompt").Return(prompts.SelectedApp{}, errors.New("selection error")) + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly).Return(prompts.SelectedApp{}, errors.New("selection error")) }, Teardown: func() { appSelectTeardown() @@ -166,7 +166,7 @@ func setupMockDeleteAppSelection(selectedApp prompts.SelectedApp) func() { appSelectMock := prompts.NewAppSelectMock() var originalPromptFunc = deleteAppSelectPromptFunc deleteAppSelectPromptFunc = appSelectMock.AppSelectPrompt - appSelectMock.On("AppSelectPrompt").Return(selectedApp, nil) + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly).Return(selectedApp, nil) return func() { deleteAppSelectPromptFunc = originalPromptFunc } diff --git a/cmd/triggers/info.go b/cmd/triggers/info.go index 788f75ea..5c3f1599 100644 --- a/cmd/triggers/info.go +++ b/cmd/triggers/info.go @@ -65,7 +65,7 @@ func runInfoCommand(cmd *cobra.Command, clients *shared.ClientFactory) error { defer span.Finish() // Get the app from the flag or prompt - selection, err := infoAppSelectPromptFunc(ctx, clients, prompts.ShowInstalledAppsOnly) + selection, err := infoAppSelectPromptFunc(ctx, clients, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly) if err != nil { return err } diff --git a/cmd/triggers/info_test.go b/cmd/triggers/info_test.go index b518a111..cc95fc71 100644 --- a/cmd/triggers/info_test.go +++ b/cmd/triggers/info_test.go @@ -181,7 +181,7 @@ func TestTriggersInfoCommand_AppSelection(t *testing.T) { appSelectMock := prompts.NewAppSelectMock() var originalPromptFunc = createAppSelectPromptFunc createAppSelectPromptFunc = appSelectMock.AppSelectPrompt - appSelectMock.On("AppSelectPrompt").Return(prompts.SelectedApp{}, errors.New("error")) + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly).Return(prompts.SelectedApp{}, errors.New("error")) appSelectTeardown = func() { createAppSelectPromptFunc = originalPromptFunc } @@ -233,7 +233,7 @@ func setupMockInfoAppSelection(selectedApp prompts.SelectedApp) func() { appSelectMock := prompts.NewAppSelectMock() var originalPromptFunc = infoAppSelectPromptFunc infoAppSelectPromptFunc = appSelectMock.AppSelectPrompt - appSelectMock.On("AppSelectPrompt").Return(selectedApp, nil) + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly).Return(selectedApp, nil) return func() { infoAppSelectPromptFunc = originalPromptFunc } diff --git a/cmd/triggers/list.go b/cmd/triggers/list.go index 1c68c2e4..0bce5aca 100644 --- a/cmd/triggers/list.go +++ b/cmd/triggers/list.go @@ -76,7 +76,7 @@ func runListCommand(cmd *cobra.Command, clients *shared.ClientFactory) error { defer span.Finish() // Get the app selection and accompanying auth from the flag or prompt - selection, err := listAppSelectPromptFunc(ctx, clients, prompts.ShowInstalledAppsOnly) + selection, err := listAppSelectPromptFunc(ctx, clients, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly) if err != nil { return err } diff --git a/cmd/triggers/list_test.go b/cmd/triggers/list_test.go index 6309bd79..e6680489 100644 --- a/cmd/triggers/list_test.go +++ b/cmd/triggers/list_test.go @@ -183,7 +183,7 @@ func setupMockListAppSelection(selectedApp prompts.SelectedApp) func() { appSelectMock := prompts.NewAppSelectMock() var originalPromptFunc = listAppSelectPromptFunc listAppSelectPromptFunc = appSelectMock.AppSelectPrompt - appSelectMock.On("AppSelectPrompt").Return(selectedApp, nil) + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly).Return(selectedApp, nil) return func() { listAppSelectPromptFunc = originalPromptFunc } diff --git a/cmd/triggers/update.go b/cmd/triggers/update.go index 535bf534..e459c20d 100644 --- a/cmd/triggers/update.go +++ b/cmd/triggers/update.go @@ -78,7 +78,7 @@ func runUpdateCommand(clients *shared.ClientFactory, cmd *cobra.Command) error { defer span.Finish() // Get the app selection and accompanying auth from the flag or prompt - selection, err := updateAppSelectPromptFunc(ctx, clients, prompts.ShowInstalledAppsOnly) + selection, err := updateAppSelectPromptFunc(ctx, clients, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly) if err != nil { return err } diff --git a/cmd/triggers/update_test.go b/cmd/triggers/update_test.go index a56420e4..9421ac28 100644 --- a/cmd/triggers/update_test.go +++ b/cmd/triggers/update_test.go @@ -509,7 +509,7 @@ func setupMockUpdateAppSelection(selectedApp prompts.SelectedApp) func() { appSelectMock := prompts.NewAppSelectMock() var originalPromptFunc = updateAppSelectPromptFunc updateAppSelectPromptFunc = appSelectMock.AppSelectPrompt - appSelectMock.On("AppSelectPrompt").Return(selectedApp, nil) + appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly).Return(selectedApp, nil) return func() { updateAppSelectPromptFunc = originalPromptFunc } diff --git a/internal/app/app_client.go b/internal/app/app_client.go index a0df3a36..41df7ac1 100644 --- a/internal/app/app_client.go +++ b/internal/app/app_client.go @@ -458,7 +458,7 @@ func (ac *AppClient) migrateToAppByTeamIDLocal() error { // as team domain is not guaranteed to be unique func (ac *AppClient) getDeployedAppTeamDomain(ctx context.Context) string { // Find the app team using the priority: - // 1. Team Flag (set by the user or prompts.TeamAppSelectPrompt) + // 1. Team Flag (set by the user) if ac.config.TeamFlag != "" { return ac.config.TeamFlag } diff --git a/internal/prompts/app_select.go b/internal/prompts/app_select.go index 2abe2628..9dde242a 100644 --- a/internal/prompts/app_select.go +++ b/internal/prompts/app_select.go @@ -374,8 +374,8 @@ func showOptionsForNewAppCreation(app types.App, status AppInstallStatus) bool { return !appExists(app) && (status == ShowAllApps || status == ShowInstalledAndNewApps) } -// flatAppSelectPrompt reveals options for apps that match the install status -func flatAppSelectPrompt( +// AppSelectPrompt reveals options for apps that match the install status +func AppSelectPrompt( ctx context.Context, clients *shared.ClientFactory, environment AppEnvironmentType, @@ -388,14 +388,16 @@ func flatAppSelectPrompt( case environment.Equals(ShowAllEnvironments) && types.IsAppFlagEnvironment(clients.Config.AppFlag): switch { case types.IsAppFlagDeploy(clients.Config.AppFlag): - return flatAppSelectPrompt(ctx, clients, ShowHostedOnly, status) + return AppSelectPrompt(ctx, clients, ShowHostedOnly, status) case types.IsAppFlagLocal(clients.Config.AppFlag): - return flatAppSelectPrompt(ctx, clients, ShowLocalOnly, status) + return AppSelectPrompt(ctx, clients, ShowLocalOnly, status) } case environment.Equals(ShowLocalOnly) && types.IsAppFlagDeploy(clients.Config.AppFlag): return SelectedApp{}, slackerror.New(slackerror.ErrDeployedAppNotSupported) case environment.Equals(ShowHostedOnly) && types.IsAppFlagLocal(clients.Config.AppFlag): return SelectedApp{}, slackerror.New(slackerror.ErrLocalAppNotSupported) + case clients.Config.AppFlag != "" && !types.IsAppFlagValid(clients.Config.AppFlag): + return SelectedApp{}, slackerror.New(slackerror.ErrInvalidAppFlag) } defer func() { if err != nil { @@ -622,7 +624,7 @@ func flatAppSelectPrompt( case selection.Prompt && options[selection.Index].label != creation: return options[selection.Index].app, nil case selection.Prompt && options[selection.Index].label == creation: - team, err := flatTeamSelectPrompt(ctx, clients) + team, err := teamSelectPrompt(ctx, clients) if err != nil { return SelectedApp{}, err } @@ -648,30 +650,8 @@ func flatAppSelectPrompt( return SelectedApp{}, slackerror.New(slackerror.ErrAppNotFound) } -// AppSelectPrompt prompts the user to select a workspace then environment for the current command, -// returning the selected app. This app might require installation before use if `status == ShowAllApps`. -func AppSelectPrompt(ctx context.Context, clients *shared.ClientFactory, status AppInstallStatus) (SelectedApp, error) { - var appFlag = clients.Config.AppFlag // e.g. 'local', 'deploy', 'deployed', A12345 - var tokenFlag = clients.Config.TokenFlag // e.g. xoxe.xoxp.xxxx - - if clients.Config.SkipLocalFs() { - clients.IO.PrintDebug(ctx, "selecting app based on token value and app id value '%s'", appFlag) - selection, err := getTokenApp(ctx, clients, tokenFlag, appFlag) - if err != nil { - return SelectedApp{}, err - } - if status == ShowInstalledAppsOnly && selection.App.InstallStatus != types.AppStatusInstalled { - return SelectedApp{}, slackerror.New(slackerror.ErrInstallationRequired) - } - clients.Auth().SetSelectedAuth(ctx, selection.Auth, clients.Config, clients.Os) - return selection, nil - } - - return flatAppSelectPrompt(ctx, clients, ShowAllEnvironments, status) -} - -// flatTeamSelectPrompt shows choices for authenticated teams -func flatTeamSelectPrompt( +// teamSelectPrompt shows choices for authenticated teams +func teamSelectPrompt( ctx context.Context, clients *shared.ClientFactory, ) ( @@ -753,50 +733,6 @@ func flatTeamSelectPrompt( return types.SlackAuth{}, slackerror.New(slackerror.ErrTeamNotFound) } -// TeamAppSelectPrompt prompts the user to select an app from a specified team environment, -// returning the selected app. This app might require installation before use if `status == ShowAllApps`. -func TeamAppSelectPrompt(ctx context.Context, clients *shared.ClientFactory, env AppEnvironmentType, status AppInstallStatus) (SelectedApp, error) { - var appFlag = clients.Config.AppFlag - var tokenFlag = clients.Config.TokenFlag - - // Error if an invalid or mismatched --app flag is provided - if appFlag != "" && !types.IsAppFlagValid(appFlag) { - return SelectedApp{}, slackerror.New(slackerror.ErrInvalidAppFlag). - WithRemediation("Choose a specific app with %s", style.Highlight("--app ")) - } - if env == ShowHostedOnly && types.IsAppFlagLocal(appFlag) { - return SelectedApp{}, slackerror.New(slackerror.ErrLocalAppNotSupported) - } - if env == ShowLocalOnly && types.IsAppFlagDeploy(appFlag) { - return SelectedApp{}, slackerror.New(slackerror.ErrDeployedAppNotSupported) - } - - if clients.Config.SkipLocalFs() { - clients.IO.PrintDebug(ctx, "selecting app based on token value and app id value '%s'", appFlag) - selection, err := getTokenApp(ctx, clients, tokenFlag, appFlag) - if err != nil { - return SelectedApp{}, err - } - if status == ShowInstalledAppsOnly && selection.App.InstallStatus != types.AppStatusInstalled { - return SelectedApp{}, slackerror.New(slackerror.ErrInstallationRequired) - } - clients.Auth().SetSelectedAuth(ctx, selection.Auth, clients.Config, clients.Os) - // The development status of an app cannot be determined when local app files - // do not exist. This defaults to "false" for these cases. - // - // Commands such as "platform run" might allow unknown development statuses so - // we return both the selection and an error here. - if selection.App.IsDev && env == ShowHostedOnly { - return selection, slackerror.New(slackerror.ErrLocalAppNotSupported) - } else if !selection.App.IsDev && env == ShowLocalOnly { - return selection, slackerror.New(slackerror.ErrDeployedAppNotSupported) - } - return selection, nil - } - - return flatAppSelectPrompt(ctx, clients, env, status) -} - // OrgSelectWorkspacePrompt prompts the user to select a single workspace to grant app access to, or grant all workspaces within the org. func OrgSelectWorkspacePrompt(ctx context.Context, clients *shared.ClientFactory, orgDomain, token string, topOptionAllWorkspaces bool) (string, error) { teams, paginationCursor, err := clients.API().AuthTeamsList(ctx, token, api.DefaultAuthTeamsListPageSize) diff --git a/internal/prompts/app_select_mock.go b/internal/prompts/app_select_mock.go index ac72c2f0..369ff711 100644 --- a/internal/prompts/app_select_mock.go +++ b/internal/prompts/app_select_mock.go @@ -31,14 +31,8 @@ func NewAppSelectMock() *AppSelectMock { return &AppSelectMock{} } -// TeamAppSelectPrompt mocks the workspace selection prompt -func (m *AppSelectMock) TeamAppSelectPrompt(ctx context.Context, clients *shared.ClientFactory, runEnv AppEnvironmentType, status AppInstallStatus) (SelectedApp, error) { - args := m.Called() - return args.Get(0).(SelectedApp), args.Error(1) -} - // AppSelectPrompt mocks the app selection prompt -func (m *AppSelectMock) AppSelectPrompt(ctx context.Context, clients *shared.ClientFactory, status AppInstallStatus) (SelectedApp, error) { - args := m.Called() +func (m *AppSelectMock) AppSelectPrompt(ctx context.Context, clients *shared.ClientFactory, env AppEnvironmentType, status AppInstallStatus) (SelectedApp, error) { + args := m.Called(ctx, clients, env, status) return args.Get(0).(SelectedApp), args.Error(1) } diff --git a/internal/prompts/app_select_test.go b/internal/prompts/app_select_test.go index d623a9dd..64275dbf 100644 --- a/internal/prompts/app_select_test.go +++ b/internal/prompts/app_select_test.go @@ -281,21 +281,22 @@ func TestGetTokenApp(t *testing.T) { func TestPrompt_AppSelectPrompt_TokenAppFlag(t *testing.T) { tests := map[string]struct { - tokenFlag string - tokenAuth types.SlackAuth - appFlag string - appStatus api.GetAppStatusResult - statusErr error - selectStatus AppInstallStatus - expectedApp SelectedApp - expectedErr error + tokenFlag string + tokenAuth types.SlackAuth + appFlag string + appStatus api.GetAppStatusResult + appStatusErr error + selectEnvironment AppEnvironmentType + selectStatus AppInstallStatus + expectedApp SelectedApp + expectedErr error }{ "error if an error occurred while collecting app info": { tokenFlag: team1Token, tokenAuth: fakeAuthsByTeamDomain[team1TeamDomain], appFlag: localTeam1UninstalledApp.AppID, appStatus: api.GetAppStatusResult{}, - statusErr: slackerror.New(slackerror.ErrAppNotFound), + appStatusErr: slackerror.New(slackerror.ErrAppNotFound), selectStatus: ShowAllApps, expectedApp: SelectedApp{}, expectedErr: slackerror.New(slackerror.ErrAppNotFound), @@ -311,7 +312,7 @@ func TestPrompt_AppSelectPrompt_TokenAppFlag(t *testing.T) { Hosted: true, }}, }, - statusErr: nil, + appStatusErr: nil, selectStatus: ShowInstalledAppsOnly, expectedApp: SelectedApp{}, expectedErr: slackerror.New(slackerror.ErrInstallationRequired), @@ -324,10 +325,10 @@ func TestPrompt_AppSelectPrompt_TokenAppFlag(t *testing.T) { Apps: []api.AppStatusResultAppInfo{{ AppID: deployedTeam1InstalledAppID, Installed: deployedTeam1AppIsInstalled, - Hosted: true, + Hosted: false, }}, }, - statusErr: nil, + appStatusErr: nil, selectStatus: ShowInstalledAppsOnly, expectedApp: SelectedApp{ Auth: fakeAuthsByTeamDomain[team1TeamDomain], @@ -335,6 +336,26 @@ func TestPrompt_AppSelectPrompt_TokenAppFlag(t *testing.T) { }, expectedErr: nil, }, + "returns app details without respect to the app environment": { + tokenFlag: team2Token, + tokenAuth: fakeAuthsByTeamDomain[team2TeamDomain], + appFlag: deployedTeam2UninstalledAppID, + appStatus: api.GetAppStatusResult{ + Apps: []api.AppStatusResultAppInfo{{ + AppID: deployedTeam2UninstalledAppID, + Installed: deployedTeam2AppIsInstalled, + Hosted: true, + }}, + }, + appStatusErr: nil, + selectEnvironment: ShowLocalOnly, + selectStatus: ShowInstalledAndUninstalledApps, + expectedApp: SelectedApp{ + Auth: fakeAuthsByTeamDomain[team2TeamDomain], + App: deployedTeam2UninstalledApp, + }, + expectedErr: nil, + }, } for name, test := range tests { @@ -344,17 +365,21 @@ func TestPrompt_AppSelectPrompt_TokenAppFlag(t *testing.T) { clientsMock.Auth.On(AuthWithToken, mock.Anything, test.tokenFlag). Return(test.tokenAuth, nil) clientsMock.API.On(GetAppStatus, mock.Anything, mock.Anything, mock.Anything, mock.Anything). - Return(test.appStatus, test.statusErr) + Return(test.appStatus, test.appStatusErr) + clientsMock.API.On("ValidateSession", mock.Anything, mock.Anything).Return(api.AuthSession{ + TeamName: &test.tokenAuth.TeamDomain, + TeamID: &test.tokenAuth.TeamID, + }, nil) clientsMock.AddDefaultMocks() clients := shared.NewClientFactory(clientsMock.MockClientFactory()) clients.Config.TokenFlag = test.tokenFlag clients.Config.AppFlag = test.appFlag - selection, err := AppSelectPrompt(ctx, clients, test.selectStatus) + selection, err := AppSelectPrompt(ctx, clients, ShowAllEnvironments, test.selectStatus) - if test.statusErr != nil && assert.Error(t, err) { - require.Equal(t, test.statusErr, err) + if test.appStatusErr != nil && assert.Error(t, err) { + require.Equal(t, test.appStatusErr, err) } else if test.expectedErr != nil && assert.Error(t, err) { require.Equal(t, test.expectedErr, err) } else { @@ -619,7 +644,7 @@ func TestPrompt_AppSelectPrompt_GetApps(t *testing.T) { } } -func TestPrompt_AppSelectPrompt_FlatAppSelectPrompt(t *testing.T) { +func TestPrompt_AppSelectPrompt(t *testing.T) { tests := map[string]struct { mockAuths []types.SlackAuth mockAuthWithTeamIDError error @@ -958,6 +983,10 @@ func TestPrompt_AppSelectPrompt_FlatAppSelectPrompt(t *testing.T) { Auth: fakeAuthsByTeamDomain[team1TeamDomain], }, }, + "errors if app id flag is not valid": { + mockFlagApp: "123", + expectedError: slackerror.New(slackerror.ErrInvalidAppFlag), + }, "errors if app id flag has a team id flag that does not match": { mockAuths: fakeAuthsByTeamDomainSlice, mockAppsDeployed: []types.App{ @@ -1353,7 +1382,7 @@ func TestPrompt_AppSelectPrompt_FlatAppSelectPrompt(t *testing.T) { err := clients.AppClient().SaveLocal(ctx, app) require.NoError(t, err) } - selectedApp, err := flatAppSelectPrompt(ctx, clients, tt.appPromptConfigEnvironment, tt.appPromptConfigStatus) + selectedApp, err := AppSelectPrompt(ctx, clients, tt.appPromptConfigEnvironment, tt.appPromptConfigStatus) require.Equal(t, tt.expectedError, err) require.Equal(t, tt.expectedSelection, selectedApp) require.Contains(t, clientsMock.GetStdoutOutput(), tt.expectedStdout) @@ -1362,146 +1391,6 @@ func TestPrompt_AppSelectPrompt_FlatAppSelectPrompt(t *testing.T) { } } -// -// TeamAppSelectPrompt tests -// - -func TestPrompt_TeamAppSelectPrompt_TokenAppFlag(t *testing.T) { - tests := map[string]struct { - tokenFlag string - tokenAuth types.SlackAuth - appFlag string - appStatus api.GetAppStatusResult - statusErr error - saveLocal []types.App - selectEnv AppEnvironmentType - selectStatus AppInstallStatus - expectedApp SelectedApp - expectedErr error - }{ - "error if an error occurred while collecting app info": { - tokenFlag: team1Token, - tokenAuth: fakeAuthsByTeamDomain[team1TeamDomain], - appFlag: localTeam1UninstalledApp.AppID, - appStatus: api.GetAppStatusResult{}, - statusErr: slackerror.New(slackerror.ErrAppNotFound), - selectEnv: ShowHostedOnly, - selectStatus: ShowAllApps, - expectedApp: SelectedApp{}, - expectedErr: slackerror.New(slackerror.ErrAppNotFound), - }, - "continue if a saved local app is used for a deployed only prompt": { - tokenFlag: team1Token, - tokenAuth: fakeAuthsByTeamDomain[team1TeamDomain], - appFlag: localTeam1UninstalledApp.AppID, - appStatus: api.GetAppStatusResult{ - Apps: []api.AppStatusResultAppInfo{{ - AppID: localTeam1UninstalledAppID, - Installed: localTeam1AppIsInstalled, - Hosted: false, - }}, - }, - statusErr: nil, - saveLocal: []types.App{localTeam1UninstalledApp}, - selectEnv: ShowHostedOnly, - selectStatus: ShowAllApps, - expectedApp: SelectedApp{ - Auth: fakeAuthsByTeamDomain[team1TeamDomain], - App: localTeam1UninstalledApp, - }, - expectedErr: slackerror.New(slackerror.ErrLocalAppNotSupported), - }, - "error if a deployed app is used for a local only prompt": { - tokenFlag: team2Token, - tokenAuth: fakeAuthsByTeamDomain[team2TeamDomain], - appFlag: deployedTeam2UninstalledApp.AppID, - appStatus: api.GetAppStatusResult{ - Apps: []api.AppStatusResultAppInfo{{ - AppID: deployedTeam2UninstalledApp.AppID, - Installed: deployedTeam2AppIsInstalled, - Hosted: true, - }}, - }, - statusErr: nil, - selectEnv: ShowLocalOnly, - selectStatus: ShowAllApps, - expectedApp: SelectedApp{}, - expectedErr: slackerror.New(slackerror.ErrDeployedAppNotSupported), - }, - "error if an uninstalled app is used for an installed only prompt": { - tokenFlag: team2Token, - tokenAuth: fakeAuthsByTeamDomain[team2TeamDomain], - appFlag: deployedTeam2UninstalledApp.AppID, - appStatus: api.GetAppStatusResult{ - Apps: []api.AppStatusResultAppInfo{{ - AppID: deployedTeam2UninstalledApp.AppID, - Installed: deployedTeam2AppIsInstalled, - Hosted: true, - }}, - }, - statusErr: nil, - selectEnv: ShowHostedOnly, - selectStatus: ShowInstalledAppsOnly, - expectedApp: SelectedApp{}, - expectedErr: slackerror.New(slackerror.ErrInstallationRequired), - }, - "returns known information about the request app": { - tokenFlag: team1Token, - tokenAuth: fakeAuthsByTeamDomain[team1TeamDomain], - appFlag: deployedTeam1InstalledAppID, - appStatus: api.GetAppStatusResult{ - Apps: []api.AppStatusResultAppInfo{{ - AppID: deployedTeam1InstalledAppID, - Installed: deployedTeam1AppIsInstalled, - Hosted: true, - }}, - }, - statusErr: nil, - selectEnv: ShowHostedOnly, - selectStatus: ShowInstalledAppsOnly, - expectedApp: SelectedApp{ - Auth: fakeAuthsByTeamDomain[team1TeamDomain], - App: deployedTeam1InstalledApp, - }, - expectedErr: nil, - }, - } - - for name, test := range tests { - t.Run(name, func(t *testing.T) { - ctx := slackcontext.MockContext(t.Context()) - clientsMock := shared.NewClientsMock() - clientsMock.Auth.On(AuthWithToken, mock.Anything, test.tokenFlag). - Return(test.tokenAuth, nil) - clientsMock.API.On(GetAppStatus, mock.Anything, mock.Anything, mock.Anything, mock.Anything). - Return(test.appStatus, test.statusErr) - clientsMock.AddDefaultMocks() - - clients := shared.NewClientFactory(clientsMock.MockClientFactory()) - for _, app := range test.saveLocal { - err := clients.AppClient().SaveLocal(ctx, app) - require.NoError(t, err) - } - clients.Config.TokenFlag = test.tokenFlag - clients.Config.AppFlag = test.appFlag - - selection, err := TeamAppSelectPrompt(ctx, clients, test.selectEnv, test.selectStatus) - - if test.statusErr != nil && assert.Error(t, err) { - require.Equal(t, test.statusErr, err) - } else if test.expectedErr != nil && assert.Error(t, err) { - require.Equal(t, test.expectedErr, err) - } else { - require.NoError(t, err) - assert.Equal(t, test.expectedApp.Auth, selection.Auth) - expectedApp := test.expectedApp.App - expectedApp.UserID = test.expectedApp.Auth.UserID - assert.Equal(t, expectedApp, selection.App) - } - }) - } -} - func TestSortAlphaNumeric_Sorted(t *testing.T) { items := []string{"alphabetical", "bordering"} labels := []string{"_alphabetical_ T001", "_bordering_ T1"}