Skip to content

Commit f3767d6

Browse files
zimegClaude
andauthored
refactor(experiment): separate iostreams prompts from survey implementations (#404)
Co-authored-by: Claude <svc-devxp-claude@slack-corp.com>
1 parent f23e6d3 commit f3767d6

File tree

15 files changed

+710
-439
lines changed

15 files changed

+710
-439
lines changed

cmd/datastore/count_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ func TestCountCommand(t *testing.T) {
251251
}, nil)
252252
cm.IO.On("InputPrompt", mock.Anything, "Enter an expression", iostreams.InputPromptConfig{
253253
Required: false,
254-
}).Return("")
254+
}).Return("", nil)
255255
cm.API.On("AppsDatastoreCount", mock.Anything, mock.Anything, mock.Anything).
256256
Return(types.AppDatastoreCountResult{Datastore: "numbers", Count: 12}, nil)
257257
},
@@ -298,16 +298,16 @@ func TestCountCommand(t *testing.T) {
298298
}, nil)
299299
cm.IO.On("InputPrompt", mock.Anything, "Enter an expression", iostreams.InputPromptConfig{
300300
Required: false,
301-
}).Return("#n < :num AND #n <> :zero AND #prime = :bool")
301+
}).Return("#n < :num AND #n <> :zero AND #prime = :bool", nil)
302302
cm.IO.On("InputPrompt", mock.Anything, "Enter a value for ':num'", iostreams.InputPromptConfig{
303303
Required: true,
304-
}).Return("12")
304+
}).Return("12", nil)
305305
cm.IO.On("InputPrompt", mock.Anything, "Enter a value for ':zero'", iostreams.InputPromptConfig{
306306
Required: true,
307-
}).Return("0")
307+
}).Return("0", nil)
308308
cm.IO.On("InputPrompt", mock.Anything, "Enter a value for ':bool'", iostreams.InputPromptConfig{
309309
Required: true,
310-
}).Return("true")
310+
}).Return("true", nil)
311311
cm.API.On("AppsDatastoreCount", mock.Anything, mock.Anything, mock.Anything).
312312
Return(types.AppDatastoreCountResult{Datastore: "numbers", Count: 6}, nil)
313313
},

cmd/datastore/delete_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ func TestDeleteCommand(t *testing.T) {
186186
}, nil)
187187
clientsMock.IO.On("InputPrompt", mock.Anything, "Enter a task_id", iostreams.InputPromptConfig{
188188
Required: true,
189-
}).Return("1234")
189+
}).Return("1234", nil)
190190
},
191191
Teardown: func() {
192192
os.Args = os.Args[:len(os.Args)-1]

cmd/datastore/get_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ func TestGetCommand(t *testing.T) {
185185
}, nil)
186186
clientsMock.IO.On("InputPrompt", mock.Anything, "Enter a task_id", iostreams.InputPromptConfig{
187187
Required: true,
188-
}).Return("1234")
188+
}).Return("1234", nil)
189189
},
190190
Teardown: func() {
191191
os.Args = os.Args[:len(os.Args)-1]

cmd/datastore/put_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,13 @@ func TestPutCommand(t *testing.T) {
194194
}, nil)
195195
clientsMock.IO.On("InputPrompt", mock.Anything, "Enter a value for 'task_id':", iostreams.InputPromptConfig{
196196
Required: true,
197-
}).Return("1234")
197+
}).Return("1234", nil)
198198
clientsMock.IO.On("InputPrompt", mock.Anything, "Enter a value for 'task':", iostreams.InputPromptConfig{
199199
Required: false,
200-
}).Return("prompting for info")
200+
}).Return("prompting for info", nil)
201201
clientsMock.IO.On("InputPrompt", mock.Anything, "Enter a value for 'status':", iostreams.InputPromptConfig{
202202
Required: false,
203-
}).Return("promptful")
203+
}).Return("promptful", nil)
204204
},
205205
Teardown: func() {
206206
os.Args = os.Args[:len(os.Args)-1]

cmd/datastore/query_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func TestQueryCommand(t *testing.T) {
245245
}, nil)
246246
clientsMock.IO.On("InputPrompt", mock.Anything, "Enter an expression", iostreams.InputPromptConfig{
247247
Required: false,
248-
}).Return("")
248+
}).Return("", nil)
249249
},
250250
Teardown: func() {
251251
os.Args = os.Args[:len(os.Args)-1]
@@ -269,7 +269,7 @@ func TestQueryCommand(t *testing.T) {
269269
}, nil)
270270
clientsMock.IO.On("InputPrompt", mock.Anything, "Enter an expression", iostreams.InputPromptConfig{
271271
Required: false,
272-
}).Return("#task_id < :num AND #task_id <> :zero AND #notes = :progress")
272+
}).Return("#task_id < :num AND #task_id <> :zero AND #notes = :progress", nil)
273273
clientsMock.IO.On("SelectPrompt", mock.Anything, "Select an attribute for '#notes'", mock.Anything, iostreams.MatchPromptConfig(iostreams.SelectPromptConfig{
274274
Flag: clientsMock.Config.Flags.Lookup("attributes"),
275275
})).Return(iostreams.SelectPromptResponse{
@@ -286,13 +286,13 @@ func TestQueryCommand(t *testing.T) {
286286
}, nil)
287287
clientsMock.IO.On("InputPrompt", mock.Anything, "Enter a value for ':num'", iostreams.InputPromptConfig{
288288
Required: true,
289-
}).Return("3")
289+
}).Return("3", nil)
290290
clientsMock.IO.On("InputPrompt", mock.Anything, "Enter a value for ':zero'", iostreams.InputPromptConfig{
291291
Required: true,
292-
}).Return("0")
292+
}).Return("0", nil)
293293
clientsMock.IO.On("InputPrompt", mock.Anything, "Enter a value for ':progress'", iostreams.InputPromptConfig{
294294
Required: true,
295-
}).Return("wip")
295+
}).Return("wip", nil)
296296
},
297297
Teardown: func() {
298298
os.Args = os.Args[:len(os.Args)-1]

cmd/datastore/update_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ func TestUpdateCommand(t *testing.T) {
195195
}, nil)
196196
clientsMock.IO.On("InputPrompt", mock.Anything, "Enter a value for 'task_id':", iostreams.InputPromptConfig{
197197
Required: true,
198-
}).Return("8888")
199-
clientsMock.IO.On("MultiSelectPrompt", mock.Anything, "Select fields to update", mock.Anything).Return([]string{})
198+
}).Return("8888", nil)
199+
clientsMock.IO.On("MultiSelectPrompt", mock.Anything, "Select fields to update", mock.Anything).Return([]string{}, nil)
200200
},
201201
Teardown: func() {
202202
os.Args = os.Args[:len(os.Args)-1]
@@ -223,14 +223,14 @@ func TestUpdateCommand(t *testing.T) {
223223
}, nil)
224224
clientsMock.IO.On("InputPrompt", mock.Anything, "Enter a value for 'task_id':", iostreams.InputPromptConfig{
225225
Required: true,
226-
}).Return("0000")
227-
clientsMock.IO.On("MultiSelectPrompt", mock.Anything, "Select fields to update", mock.Anything).Return([]string{"status", "task"})
226+
}).Return("0000", nil)
227+
clientsMock.IO.On("MultiSelectPrompt", mock.Anything, "Select fields to update", mock.Anything).Return([]string{"status", "task"}, nil)
228228
clientsMock.IO.On("InputPrompt", mock.Anything, "Enter a value for 'status':", iostreams.InputPromptConfig{
229229
Required: false,
230-
}).Return("")
230+
}).Return("", nil)
231231
clientsMock.IO.On("InputPrompt", mock.Anything, "Enter a value for 'task':", iostreams.InputPromptConfig{
232232
Required: false,
233-
}).Return("")
233+
}).Return("", nil)
234234
},
235235
Teardown: func() {
236236
os.Args = os.Args[:len(os.Args)-1]
@@ -259,11 +259,11 @@ func TestUpdateCommand(t *testing.T) {
259259
}, nil)
260260
clientsMock.IO.On("InputPrompt", mock.Anything, "Enter a value for 'task_id':", iostreams.InputPromptConfig{
261261
Required: true,
262-
}).Return("1234")
263-
clientsMock.IO.On("MultiSelectPrompt", mock.Anything, "Select fields to update", mock.Anything).Return([]string{"status"})
262+
}).Return("1234", nil)
263+
clientsMock.IO.On("MultiSelectPrompt", mock.Anything, "Select fields to update", mock.Anything).Return([]string{"status"}, nil)
264264
clientsMock.IO.On("InputPrompt", mock.Anything, "Enter a value for 'status':", iostreams.InputPromptConfig{
265265
Required: false,
266-
}).Return("getting closer")
266+
}).Return("getting closer", nil)
267267
},
268268
Teardown: func() {
269269
os.Args = os.Args[:len(os.Args)-1]
@@ -291,14 +291,14 @@ func TestUpdateCommand(t *testing.T) {
291291
}, nil)
292292
clientsMock.IO.On("InputPrompt", mock.Anything, "Enter a value for 'task_id':", iostreams.InputPromptConfig{
293293
Required: true,
294-
}).Return("9999")
295-
clientsMock.IO.On("MultiSelectPrompt", mock.Anything, "Select fields to update", mock.Anything).Return([]string{"task", "status"})
294+
}).Return("9999", nil)
295+
clientsMock.IO.On("MultiSelectPrompt", mock.Anything, "Select fields to update", mock.Anything).Return([]string{"task", "status"}, nil)
296296
clientsMock.IO.On("InputPrompt", mock.Anything, "Enter a value for 'task':", iostreams.InputPromptConfig{
297297
Required: false,
298-
}).Return("relax")
298+
}).Return("relax", nil)
299299
clientsMock.IO.On("InputPrompt", mock.Anything, "Enter a value for 'status':", iostreams.InputPromptConfig{
300300
Required: false,
301-
}).Return("always")
301+
}).Return("always", nil)
302302
},
303303
Teardown: func() {
304304
os.Args = os.Args[:len(os.Args)-1]

cmd/externalauth/remove_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ func TestExternalAuthRemoveCommand(t *testing.T) {
182182
}}, nil)
183183
clientsMock.API.On("AppsAuthExternalDelete", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil)
184184
clientsMock.AddDefaultMocks()
185-
clientsMock.IO.On("ConfirmPrompt", mock.Anything, "Are you sure you want to remove all tokens for this app relevant to the specified provider from your current team/org?", mock.Anything).Return(true)
185+
clientsMock.IO.On("ConfirmPrompt", mock.Anything, "Are you sure you want to remove all tokens for this app relevant to the specified provider from your current team/org?", mock.Anything).Return(true, nil)
186186
err := clients.AppClient().SaveDeployed(ctx, fakeApp)
187187
require.NoError(t, err, "Cant write apps.json")
188188
},
@@ -209,7 +209,7 @@ func TestExternalAuthRemoveCommand(t *testing.T) {
209209
clientsMock.AddDefaultMocks()
210210
err := clients.AppClient().SaveDeployed(ctx, fakeApp)
211211
require.NoError(t, err, "Cant write apps.json")
212-
clientsMock.IO.On("ConfirmPrompt", mock.Anything, "Are you sure you want to remove all tokens for this app from your current team/org?", mock.Anything).Return(true)
212+
clientsMock.IO.On("ConfirmPrompt", mock.Anything, "Are you sure you want to remove all tokens for this app from your current team/org?", mock.Anything).Return(true, nil)
213213
},
214214
ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) {
215215
clientsMock.API.AssertCalled(t, "AppsAuthExternalDelete", mock.Anything, mock.Anything, fakeAppID, "", "")
@@ -235,7 +235,7 @@ func TestExternalAuthRemoveCommand(t *testing.T) {
235235
err := clients.AppClient().SaveDeployed(ctx, fakeApp)
236236
require.NoError(t, err, "Cant write apps.json")
237237

238-
clientsMock.IO.On("ConfirmPrompt", mock.Anything, "Are you sure you want to remove all tokens for this app relevant to the specified provider from your current team/org?", mock.Anything).Return(true)
238+
clientsMock.IO.On("ConfirmPrompt", mock.Anything, "Are you sure you want to remove all tokens for this app relevant to the specified provider from your current team/org?", mock.Anything).Return(true, nil)
239239
},
240240
ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) {
241241
clientsMock.API.AssertCalled(t, "AppsAuthExternalDelete", mock.Anything, mock.Anything, fakeAppID, "provider_a", "")
@@ -252,7 +252,7 @@ func TestExternalAuthRemoveCommand(t *testing.T) {
252252
clientsMock.AddDefaultMocks()
253253
err := clients.AppClient().SaveDeployed(ctx, fakeApp)
254254
require.NoError(t, err, "Cant write apps.json")
255-
clientsMock.IO.On("ConfirmPrompt", mock.Anything, "Are you sure you want to remove all tokens for this app from your current team/org?", mock.Anything).Return(true)
255+
clientsMock.IO.On("ConfirmPrompt", mock.Anything, "Are you sure you want to remove all tokens for this app from your current team/org?", mock.Anything).Return(true, nil)
256256
},
257257
ExpectedAsserts: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock) {
258258
clientsMock.API.AssertCalled(t, "AppsAuthExternalDelete", mock.Anything, mock.Anything, fakeAppID, "", "")

cmd/feedback/feedback_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func TestFeedbackCommand(t *testing.T) {
6363
scm.On("SetSurveyConfig", mock.Anything, mock.Anything, mock.Anything).Return(nil)
6464
clientsMock.Config.SystemConfig = scm
6565

66-
clientsMock.IO.On("ConfirmPrompt", mock.Anything, "Open in browser?", mock.Anything).Return(true)
66+
clientsMock.IO.On("ConfirmPrompt", mock.Anything, "Open in browser?", mock.Anything).Return(true, nil)
6767
clientsMock.Browser.On("OpenURL", "https://survey.com?project_id=projectID&system_id=systemID&utm_medium=cli&utm_source=cli").Return(nil)
6868

6969
clients := shared.NewClientFactory(clientsMock.MockClientFactory())
@@ -133,7 +133,7 @@ func TestFeedbackCommand(t *testing.T) {
133133
Index: 2,
134134
}, nil)
135135

136-
clientsMock.IO.On("ConfirmPrompt", mock.Anything, "Open in browser?", mock.Anything).Return(true)
136+
clientsMock.IO.On("ConfirmPrompt", mock.Anything, "Open in browser?", mock.Anything).Return(true, nil)
137137
clientsMock.Browser.On("OpenURL", "https://survey.com?project_id=projectID&system_id=systemID&utm_medium=cli&utm_source=cli").Return(nil)
138138

139139
clients := shared.NewClientFactory(clientsMock.MockClientFactory())
@@ -223,19 +223,19 @@ func TestShowSurveyMessages(t *testing.T) {
223223

224224
// B
225225
pcm.On("GetSurveyConfig", mock.Anything, "B").Return(config.SurveyConfig{}, slackerror.New(slackerror.ErrSurveyConfigNotFound)).Once()
226-
clientsMock.IO.On("ConfirmPrompt", mock.Anything, "Would you like to take a minute to tell us about B?", mock.Anything).Return(true)
226+
clientsMock.IO.On("ConfirmPrompt", mock.Anything, "Would you like to take a minute to tell us about B?", mock.Anything).Return(true, nil)
227227
scm.On("GetSystemID", mock.Anything).Return("systemID", nil).Once()
228228
pcm.On("GetProjectID", mock.Anything).Return("projectID", nil).Once()
229-
clientsMock.IO.On("ConfirmPrompt", mock.Anything, "Open in browser?", mock.Anything).Return(true).Once()
229+
clientsMock.IO.On("ConfirmPrompt", mock.Anything, "Open in browser?", mock.Anything).Return(true, nil).Once()
230230
clientsMock.Browser.On("OpenURL", "https://B.com?project_id=projectID&system_id=systemID&utm_medium=cli&utm_source=cli").Return(nil).Once()
231231
pcm.On("SetSurveyConfig", mock.Anything, "B", mock.Anything).Return(nil).Once()
232232

233233
// C
234234
scm.On("GetSurveyConfig", mock.Anything, "C").Return(config.SurveyConfig{AskedAt: oneMonthAgoTimestamp}, nil).Once()
235-
clientsMock.IO.On("ConfirmPrompt", mock.Anything, "Would you like to take a minute to tell us about C?", mock.Anything).Return(true)
235+
clientsMock.IO.On("ConfirmPrompt", mock.Anything, "Would you like to take a minute to tell us about C?", mock.Anything).Return(true, nil)
236236
scm.On("GetSystemID", mock.Anything).Return("systemID", nil).Once()
237237
pcm.On("GetProjectID", mock.Anything).Return("projectID", nil).Once()
238-
clientsMock.IO.On("ConfirmPrompt", mock.Anything, "Open in browser?", mock.Anything).Return(true).Once()
238+
clientsMock.IO.On("ConfirmPrompt", mock.Anything, "Open in browser?", mock.Anything).Return(true, nil).Once()
239239
clientsMock.Browser.On("OpenURL", "https://C.com?project_id=projectID&system_id=systemID&utm_medium=cli&utm_source=cli").Return(nil).Once()
240240
scm.On("SetSurveyConfig", mock.Anything, "C", mock.Anything).Return(nil).Once()
241241

@@ -315,5 +315,5 @@ func setupFeedbackCommandMocks(t *testing.T, ctx context.Context, cm *shared.Cli
315315
pcm.On("GetProjectID", mock.Anything).Return("projectID", nil)
316316
cm.Config.ProjectConfig = pcm
317317

318-
cm.IO.On("ConfirmPrompt", mock.Anything, "Open in browser?", mock.Anything).Return(false)
318+
cm.IO.On("ConfirmPrompt", mock.Anything, "Open in browser?", mock.Anything).Return(false, nil)
319319
}

cmd/triggers/access_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ func TestTriggersAccessCommand(t *testing.T) {
271271
clientsMock.API.On("UserInfo", mock.Anything, mock.Anything, "collaborator_ID").
272272
Return(&types.UserInfo{}, nil).Once()
273273
// confirm to add app collaborators
274-
clientsMock.IO.On("ConfirmPrompt", mock.Anything, "Include app collaborators?", mock.Anything).Return(true)
274+
clientsMock.IO.On("ConfirmPrompt", mock.Anything, "Include app collaborators?", mock.Anything).Return(true, nil)
275275
// set access type to named_entities
276276
clientsMock.API.On("TriggerPermissionsSet", mock.Anything, mock.Anything, fakeTriggerID, "collaborator_ID", types.PermissionNamedEntities, "users").Maybe().
277277
Return([]string{}, nil)

internal/iostreams/charm.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,6 @@ func buildSelectForm(msg string, options []string, cfg SelectPromptConfig, selec
8585
Options(opts...).
8686
Value(selected)
8787

88-
if cfg.PageSize > 0 {
89-
field.Height(cfg.PageSize + 2)
90-
}
91-
9288
return huh.NewForm(huh.NewGroup(field)).WithTheme(style.ThemeSlack())
9389
}
9490

0 commit comments

Comments
 (0)