Skip to content

Commit c186ffc

Browse files
authored
refactor: join the app selector and team selector logic (#159)
1 parent 0229807 commit c186ffc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+196
-360
lines changed

cmd/app/add.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import (
3636
var runAddCommandFunc = RunAddCommand
3737
var appInstallProdAppFunc = apps.Add
3838
var appInstallDevAppFunc = apps.InstallLocalApp
39-
var teamAppSelectPromptFunc = prompts.TeamAppSelectPrompt
39+
var appSelectPromptFunc = prompts.AppSelectPrompt
4040

4141
// Flags
4242

@@ -111,7 +111,7 @@ func preRunAddCommand(ctx context.Context, clients *shared.ClientFactory) error
111111
// RunAddCommand executes the workspace install command, prints output, and returns any errors.
112112
func RunAddCommand(ctx context.Context, clients *shared.ClientFactory, selection *prompts.SelectedApp, orgGrantWorkspaceID string) (context.Context, types.InstallState, types.App, error) {
113113
if selection == nil {
114-
selected, err := teamAppSelectPromptFunc(ctx, clients, prompts.ShowHostedOnly, prompts.ShowAllApps)
114+
selected, err := appSelectPromptFunc(ctx, clients, prompts.ShowHostedOnly, prompts.ShowAllApps)
115115
if err != nil {
116116
return ctx, "", types.App{}, err
117117
}

cmd/app/add_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ func TestAppAddCommand(t *testing.T) {
140140

141141
// Mock TeamSelector prompt to return "team1"
142142
appSelectMock := prompts.NewAppSelectMock()
143-
teamAppSelectPromptFunc = appSelectMock.TeamAppSelectPrompt
144-
appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{Auth: mockAuthTeam1}, nil)
143+
appSelectPromptFunc = appSelectMock.AppSelectPrompt
144+
appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowHostedOnly, prompts.ShowAllApps).Return(prompts.SelectedApp{Auth: mockAuthTeam1}, nil)
145145

146146
// Mock valid session for team1
147147
cm.API.On("ValidateSession", mock.Anything, mock.Anything).Return(api.AuthSession{
@@ -212,8 +212,8 @@ func TestAppAddCommand(t *testing.T) {
212212

213213
// Mock TeamSelector prompt to return "team1"
214214
appSelectMock := prompts.NewAppSelectMock()
215-
teamAppSelectPromptFunc = appSelectMock.TeamAppSelectPrompt
216-
appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{App: mockAppTeam1, Auth: mockAuthTeam1}, nil)
215+
appSelectPromptFunc = appSelectMock.AppSelectPrompt
216+
appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowHostedOnly, prompts.ShowAllApps).Return(prompts.SelectedApp{App: mockAppTeam1, Auth: mockAuthTeam1}, nil)
217217

218218
// Mock valid session for team1
219219
cm.API.On("ValidateSession", mock.Anything, mock.Anything).Return(api.AuthSession{
@@ -292,8 +292,8 @@ func TestAppAddCommand(t *testing.T) {
292292
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
293293
prepareAddMocks(t, cf, cm)
294294
appSelectMock := prompts.NewAppSelectMock()
295-
teamAppSelectPromptFunc = appSelectMock.TeamAppSelectPrompt
296-
appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{App: mockAppTeam1}, nil)
295+
appSelectPromptFunc = appSelectMock.AppSelectPrompt
296+
appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowHostedOnly, prompts.ShowAllApps).Return(prompts.SelectedApp{App: mockAppTeam1}, nil)
297297
},
298298
},
299299
"adds a new deployed app to an org with a workspace grant": {
@@ -303,8 +303,8 @@ func TestAppAddCommand(t *testing.T) {
303303
prepareAddMocks(t, cf, cm)
304304
// Select workspace
305305
appSelectMock := prompts.NewAppSelectMock()
306-
teamAppSelectPromptFunc = appSelectMock.TeamAppSelectPrompt
307-
appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{App: types.NewApp(), Auth: mockOrgAuth}, nil)
306+
appSelectPromptFunc = appSelectMock.AppSelectPrompt
307+
appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowHostedOnly, prompts.ShowAllApps).Return(prompts.SelectedApp{App: types.NewApp(), Auth: mockOrgAuth}, nil)
308308
// Mock calls
309309
cm.API.On("ValidateSession", mock.Anything, mock.Anything).Return(api.AuthSession{
310310
UserID: &mockOrgAuth.UserID,
@@ -363,8 +363,8 @@ func TestAppAddCommand(t *testing.T) {
363363
prepareAddMocks(t, cf, cm)
364364
// Select workspace
365365
appSelectMock := prompts.NewAppSelectMock()
366-
teamAppSelectPromptFunc = appSelectMock.TeamAppSelectPrompt
367-
appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{App: types.NewApp(), Auth: mockOrgAuth}, nil)
366+
appSelectPromptFunc = appSelectMock.AppSelectPrompt
367+
appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowHostedOnly, prompts.ShowAllApps).Return(prompts.SelectedApp{App: types.NewApp(), Auth: mockOrgAuth}, nil)
368368
// Mock calls
369369
cm.API.On("ValidateSession", mock.Anything, mock.Anything).Return(api.AuthSession{
370370
UserID: &mockOrgAuth.UserID,
@@ -419,8 +419,8 @@ func TestAppAddCommand(t *testing.T) {
419419
prepareAddMocks(t, cf, cm)
420420
// Select workspace
421421
appSelectMock := prompts.NewAppSelectMock()
422-
teamAppSelectPromptFunc = appSelectMock.TeamAppSelectPrompt
423-
appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{App: types.NewApp(), Auth: mockOrgAuth}, nil)
422+
appSelectPromptFunc = appSelectMock.AppSelectPrompt
423+
appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowHostedOnly, prompts.ShowAllApps).Return(prompts.SelectedApp{App: types.NewApp(), Auth: mockOrgAuth}, nil)
424424
// Mock calls
425425
cm.API.On("ValidateSession", mock.Anything, mock.Anything).Return(api.AuthSession{
426426
UserID: &mockOrgAuth.UserID,

cmd/app/delete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func RunDeleteCommand(ctx context.Context, clients *shared.ClientFactory, cmd *c
7171
}
7272

7373
// Get the app auth selection from the flag or prompt
74-
selection, err := deleteAppSelectPromptFunc(ctx, clients, prompts.ShowInstalledAndUninstalledApps)
74+
selection, err := deleteAppSelectPromptFunc(ctx, clients, prompts.ShowAllEnvironments, prompts.ShowInstalledAndUninstalledApps)
7575
if err != nil {
7676
if slackerror.ToSlackError(err).Code == slackerror.ErrInstallationRequired {
7777
return types.App{}, nil

cmd/app/delete_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func TestAppsDeleteCommand(t *testing.T) {
5555
// Mock App Selection
5656
appSelectMock := prompts.NewAppSelectMock()
5757
deleteAppSelectPromptFunc = appSelectMock.AppSelectPrompt
58-
appSelectMock.On("AppSelectPrompt").Return(prompts.SelectedApp{
58+
appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowAllEnvironments, prompts.ShowInstalledAndUninstalledApps).Return(prompts.SelectedApp{
5959
Auth: types.SlackAuth{TeamDomain: fakeDeployedApp.TeamDomain},
6060
App: fakeDeployedApp,
6161
}, nil)
@@ -89,7 +89,7 @@ func TestAppsDeleteCommand(t *testing.T) {
8989
// Mock App Selection
9090
appSelectMock := prompts.NewAppSelectMock()
9191
deleteAppSelectPromptFunc = appSelectMock.AppSelectPrompt
92-
appSelectMock.On("AppSelectPrompt").Return(prompts.SelectedApp{
92+
appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowAllEnvironments, prompts.ShowInstalledAndUninstalledApps).Return(prompts.SelectedApp{
9393
Auth: types.SlackAuth{TeamDomain: fakeLocalApp.TeamDomain},
9494
App: fakeLocalApp,
9595
}, nil)
@@ -122,7 +122,7 @@ func TestAppsDeleteCommand(t *testing.T) {
122122
// Mock App Selection
123123
appSelectMock := prompts.NewAppSelectMock()
124124
deleteAppSelectPromptFunc = appSelectMock.AppSelectPrompt
125-
appSelectMock.On("AppSelectPrompt").Return(prompts.SelectedApp{
125+
appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowAllEnvironments, prompts.ShowInstalledAndUninstalledApps).Return(prompts.SelectedApp{
126126
Auth: types.SlackAuth{TeamDomain: fakeDeployedApp.TeamDomain},
127127
App: fakeDeployedApp,
128128
}, nil)
@@ -149,7 +149,7 @@ func TestAppsDeleteCommand(t *testing.T) {
149149
cm.API.On("ValidateSession", mock.Anything, mock.Anything).Return(api.AuthSession{}, nil)
150150
appSelectMock := prompts.NewAppSelectMock()
151151
deleteAppSelectPromptFunc = appSelectMock.AppSelectPrompt
152-
appSelectMock.On("AppSelectPrompt").Return(prompts.SelectedApp{App: fakeDeployedApp}, nil)
152+
appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowAllEnvironments, prompts.ShowInstalledAndUninstalledApps).Return(prompts.SelectedApp{App: fakeDeployedApp}, nil)
153153
},
154154
},
155155
}, func(cf *shared.ClientFactory) *cobra.Command {

cmd/app/settings.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func appSettingsCommandRunE(clients *shared.ClientFactory, cmd *cobra.Command, a
9696
ctx := cmd.Context()
9797
clients.IO.PrintTrace(ctx, slacktrace.AppSettingsStart)
9898

99-
app, err := settingsAppSelectPromptFunc(ctx, clients, prompts.ShowInstalledAndUninstalledApps)
99+
app, err := settingsAppSelectPromptFunc(ctx, clients, prompts.ShowAllEnvironments, prompts.ShowInstalledAndUninstalledApps)
100100
if err != nil {
101101
return err
102102
}

cmd/app/settings_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ func Test_App_SettingsCommand(t *testing.T) {
9696
appSelectMock := prompts.NewAppSelectMock()
9797
appSelectMock.On(
9898
"AppSelectPrompt",
99+
mock.Anything,
100+
mock.Anything,
101+
prompts.ShowAllEnvironments,
102+
prompts.ShowInstalledAndUninstalledApps,
99103
).Return(
100104
prompts.SelectedApp{App: types.App{AppID: "A0101010101"}},
101105
nil,
@@ -124,6 +128,10 @@ func Test_App_SettingsCommand(t *testing.T) {
124128
appSelectMock := prompts.NewAppSelectMock()
125129
appSelectMock.On(
126130
"AppSelectPrompt",
131+
mock.Anything,
132+
mock.Anything,
133+
prompts.ShowAllEnvironments,
134+
prompts.ShowInstalledAndUninstalledApps,
127135
).Return(
128136
prompts.SelectedApp{},
129137
slackerror.New(slackerror.ErrInstallationRequired),
@@ -147,6 +155,10 @@ func Test_App_SettingsCommand(t *testing.T) {
147155
appSelectMock := prompts.NewAppSelectMock()
148156
appSelectMock.On(
149157
"AppSelectPrompt",
158+
mock.Anything,
159+
mock.Anything,
160+
prompts.ShowAllEnvironments,
161+
prompts.ShowInstalledAndUninstalledApps,
150162
).Return(
151163
prompts.SelectedApp{App: types.App{AppID: "A0123456789"}},
152164
nil,
@@ -176,6 +188,10 @@ func Test_App_SettingsCommand(t *testing.T) {
176188
appSelectMock := prompts.NewAppSelectMock()
177189
appSelectMock.On(
178190
"AppSelectPrompt",
191+
mock.Anything,
192+
mock.Anything,
193+
prompts.ShowAllEnvironments,
194+
prompts.ShowInstalledAndUninstalledApps,
179195
).Return(
180196
prompts.SelectedApp{
181197
App: types.App{AppID: "A0123456789"},

cmd/app/uninstall.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func RunUninstallCommand(ctx context.Context, clients *shared.ClientFactory, cmd
6666
}
6767

6868
// Get the workspace from the flag or prompt
69-
selection, err := uninstallAppSelectPromptFunc(ctx, clients, prompts.ShowInstalledAppsOnly)
69+
selection, err := uninstallAppSelectPromptFunc(ctx, clients, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly)
7070
if err != nil {
7171
if slackerror.ToSlackError(err).Code == slackerror.ErrInstallationRequired {
7272
return types.App{}, nil

cmd/app/uninstall_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func TestAppsUninstall(t *testing.T) {
8484
prepareCommonUninstallMocks(ctx, cf, cm)
8585
appSelectMock := prompts.NewAppSelectMock()
8686
uninstallAppSelectPromptFunc = appSelectMock.AppSelectPrompt
87-
appSelectMock.On("AppSelectPrompt").Return(prompts.SelectedApp{App: fakeApp}, nil)
87+
appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly).Return(prompts.SelectedApp{App: fakeApp}, nil)
8888
},
8989
},
9090
}, func(clients *shared.ClientFactory) *cobra.Command {
@@ -99,7 +99,7 @@ func prepareCommonUninstallMocks(ctx context.Context, clients *shared.ClientFact
9999
// Mock App Selection
100100
appSelectMock := prompts.NewAppSelectMock()
101101
uninstallAppSelectPromptFunc = appSelectMock.AppSelectPrompt
102-
appSelectMock.On("AppSelectPrompt").Return(selectedProdApp, nil)
102+
appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowAllEnvironments, prompts.ShowInstalledAppsOnly).Return(selectedProdApp, nil)
103103

104104
// Mock API calls
105105
clientsMock.Auth.On("ResolveAPIHost", mock.Anything, mock.Anything, mock.Anything).

cmd/collaborators/add.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func runAddCommandFunc(ctx context.Context, clients *shared.ClientFactory, cmd *
7474
defer span.Finish()
7575

7676
// Get the app auth selection from the flag or prompt
77-
selection, err := teamAppSelectPromptFunc(ctx, clients, prompts.ShowHostedOnly, prompts.ShowInstalledAndUninstalledApps)
77+
selection, err := appSelectPromptFunc(ctx, clients, prompts.ShowHostedOnly, prompts.ShowInstalledAndUninstalledApps)
7878
if err != nil {
7979
return err
8080
}

cmd/collaborators/add_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ func TestAddCommand(t *testing.T) {
3535
cm.AddDefaultMocks()
3636
// Mock App Selection
3737
appSelectMock := prompts.NewAppSelectMock()
38-
teamAppSelectPromptFunc = appSelectMock.TeamAppSelectPrompt
39-
appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{App: types.App{AppID: "A123"}, Auth: types.SlackAuth{}}, nil)
38+
appSelectPromptFunc = appSelectMock.AppSelectPrompt
39+
appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowHostedOnly, prompts.ShowInstalledAndUninstalledApps).Return(prompts.SelectedApp{App: types.App{AppID: "A123"}, Auth: types.SlackAuth{}}, nil)
4040
// Set experiment flag
4141
cm.Config.ExperimentsFlag = append(cm.Config.ExperimentsFlag, "read-only-collaborators")
4242
cm.Config.LoadExperiments(ctx, cm.IO.PrintDebug)
@@ -59,8 +59,8 @@ func TestAddCommand(t *testing.T) {
5959
cm.AddDefaultMocks()
6060
// Mock App Selection
6161
appSelectMock := prompts.NewAppSelectMock()
62-
teamAppSelectPromptFunc = appSelectMock.TeamAppSelectPrompt
63-
appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{App: types.App{AppID: "A123"}, Auth: types.SlackAuth{}}, nil)
62+
appSelectPromptFunc = appSelectMock.AppSelectPrompt
63+
appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowHostedOnly, prompts.ShowInstalledAndUninstalledApps).Return(prompts.SelectedApp{App: types.App{AppID: "A123"}, Auth: types.SlackAuth{}}, nil)
6464
// Set experiment flag
6565
cm.Config.ExperimentsFlag = append(cm.Config.ExperimentsFlag, "read-only-collaborators")
6666
cm.Config.LoadExperiments(ctx, cm.IO.PrintDebug)
@@ -84,8 +84,8 @@ func TestAddCommand(t *testing.T) {
8484
cm.AddDefaultMocks()
8585
// Mock App Selection
8686
appSelectMock := prompts.NewAppSelectMock()
87-
teamAppSelectPromptFunc = appSelectMock.TeamAppSelectPrompt
88-
appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{App: types.App{AppID: "A123"}, Auth: types.SlackAuth{}}, nil)
87+
appSelectPromptFunc = appSelectMock.AppSelectPrompt
88+
appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowHostedOnly, prompts.ShowInstalledAndUninstalledApps).Return(prompts.SelectedApp{App: types.App{AppID: "A123"}, Auth: types.SlackAuth{}}, nil)
8989
// Mock API call
9090
cm.API.On("AddCollaborator", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
9191
Return(nil)

0 commit comments

Comments
 (0)