@@ -143,7 +143,6 @@ describe('project delete source', () => {
143143 let resolveProjectConfigStub : sinon . SinonStub ;
144144 let rmStub : sinon . SinonStub ;
145145 let compSetFromSourceStub : sinon . SinonStub ;
146- let confirmStub : sinon . SinonStub ;
147146 let handlePromptStub : sinon . SinonStub ;
148147
149148 class TestDelete extends Source {
@@ -159,7 +158,7 @@ describe('project delete source', () => {
159158 params : string [ ] ,
160159 options ?: {
161160 sourceApiVersion ?: string ;
162- confirm ?: boolean ;
161+ inquirerMock ?: { checkbox : sinon . SinonStub } ;
163162 }
164163 ) => {
165164 const cmd = new TestDelete ( params , oclifConfigStub ) ;
@@ -184,8 +183,14 @@ describe('project delete source', () => {
184183 onCancel : ( ) => { } ,
185184 onError : ( ) => { } ,
186185 } ) ;
187- confirmStub = stubMethod ( $$ . SANDBOX , cmd , 'confirm' ) . returns ( options ?. confirm ?? true ) ;
188186 handlePromptStub = stubMethod ( $$ . SANDBOX , cmd , 'handlePrompt' ) . returns ( confirm ) ;
187+ if ( options ?. inquirerMock ) {
188+ // @ts -expect-error stubbing private member of the command
189+ cmd . inquirer = options . inquirerMock ;
190+ } else {
191+ // @ts -expect-error stubbing private member of the command
192+ cmd . inquirer = { checkbox : $$ . SANDBOX . stub ( ) . resolves ( [ ] ) } ;
193+ }
189194 rmStub = stubMethod ( $$ . SANDBOX , fs . promises , 'rm' ) . resolves ( ) ;
190195 stubMethod ( $$ . SANDBOX , DeployCache , 'update' ) . resolves ( ) ;
191196
@@ -269,10 +274,13 @@ describe('project delete source', () => {
269274
270275 it ( 'should pass along metadata and org for pseudo-type matching with plugins' , async ( ) => {
271276 const agentCompSet = new ComponentSet ( ) ;
277+ const pluginNames = [ agentComponents [ 2 ] . name , agentComponents [ 3 ] . name ] ;
272278 agentComponents . map ( ( comp ) => agentCompSet . add ( comp ) ) ;
273279 compSetFromSourceStub = compSetFromSourceStub . returns ( agentCompSet ) ;
280+ const inquirerCheckboxStub = $$ . SANDBOX . stub ( ) . resolves ( pluginNames ) ;
281+ const inquirerMock = { checkbox : inquirerCheckboxStub } ;
274282 const metadata = [ 'Agent:My_Agent' ] ;
275- await runDeleteCmd ( [ '--metadata' , metadata [ 0 ] , '--json' ] ) ;
283+ await runDeleteCmd ( [ '--metadata' , metadata [ 0 ] , '--json' ] , { inquirerMock } ) ;
276284 ensureCreateComponentSetArgs ( {
277285 metadata : {
278286 metadataEntries : metadata ,
@@ -285,12 +293,12 @@ describe('project delete source', () => {
285293 } ) ;
286294 ensureHookArgs ( ) ;
287295 expect ( compSetFromSourceStub . calledOnce ) . to . be . true ;
288- expect ( confirmStub . calledOnce ) . to . be . true ;
289- expect ( confirmStub . firstCall . firstArg )
290- . has . deep . property ( 'message' )
291- . that . includes ( 'Do you want to delete ALL related topics?' )
292- . and . includes ( agentComponents [ 2 ] . xml )
293- . and . includes ( agentComponents [ 3 ] . xml ) ;
296+ expect ( inquirerCheckboxStub . calledOnce ) . to . be . true ;
297+ expect ( inquirerCheckboxStub . firstCall . firstArg ) . has . property ( 'message' , 'Select related topics to delete' ) ;
298+ expect ( inquirerCheckboxStub . firstCall . firstArg ) . has . deep . property ( 'choices' , [
299+ { name : 'Test_Plugin1' , value : 'Test_Plugin1' } ,
300+ { name : 'Test_Plugin2' , value : 'Test_Plugin2' } ,
301+ ] ) ;
294302 expect ( handlePromptStub . calledOnce ) . to . be . true ;
295303 expect ( lifecycleEmitStub . firstCall . args [ 1 ] ) . to . deep . equal ( agentComponents ) ;
296304 } ) ;
@@ -299,8 +307,10 @@ describe('project delete source', () => {
299307 const agentCompSet = new ComponentSet ( ) ;
300308 agentComponents . map ( ( comp ) => agentCompSet . add ( comp ) ) ;
301309 compSetFromSourceStub = compSetFromSourceStub . returns ( agentCompSet ) ;
310+ const inquirerCheckboxStub = $$ . SANDBOX . stub ( ) . resolves ( [ ] ) ;
311+ const inquirerMock = { checkbox : inquirerCheckboxStub } ;
302312 const metadata = [ 'Agent:My_Agent' ] ;
303- await runDeleteCmd ( [ '--metadata' , metadata [ 0 ] , '--json' ] , { confirm : false } ) ;
313+ await runDeleteCmd ( [ '--metadata' , metadata [ 0 ] , '--json' ] , { inquirerMock } ) ;
304314 ensureCreateComponentSetArgs ( {
305315 metadata : {
306316 metadataEntries : metadata ,
@@ -313,12 +323,11 @@ describe('project delete source', () => {
313323 } ) ;
314324 ensureHookArgs ( ) ;
315325 expect ( compSetFromSourceStub . calledOnce ) . to . be . true ;
316- expect ( confirmStub . calledOnce ) . to . be . true ;
317- expect ( confirmStub . firstCall . firstArg )
318- . has . deep . property ( 'message' )
319- . that . includes ( 'Do you want to delete ALL related topics?' )
320- . and . includes ( agentComponents [ 2 ] . xml )
321- . and . includes ( agentComponents [ 3 ] . xml ) ;
326+ expect ( inquirerCheckboxStub . calledOnce ) . to . be . true ;
327+ expect ( inquirerCheckboxStub . firstCall . firstArg ) . has . deep . property ( 'choices' , [
328+ { name : 'Test_Plugin1' , value : 'Test_Plugin1' } ,
329+ { name : 'Test_Plugin2' , value : 'Test_Plugin2' } ,
330+ ] ) ;
322331 expect ( handlePromptStub . calledOnce ) . to . be . true ;
323332 expect ( lifecycleEmitStub . firstCall . args [ 1 ] ) . to . deep . equal ( [ agentComponents [ 0 ] , agentComponents [ 1 ] ] ) ;
324333 } ) ;
0 commit comments