@@ -12,6 +12,7 @@ import {
12
12
ComponentSet ,
13
13
ComponentSetBuilder ,
14
14
ComponentSetOptions ,
15
+ RegistryAccess ,
15
16
SourceComponent ,
16
17
} from '@salesforce/source-deploy-retrieve' ;
17
18
import { Lifecycle , SfProject } from '@salesforce/core' ;
@@ -40,6 +41,30 @@ export const exampleSourceComponent: ComponentProperties = {
40
41
content : '/dreamhouse-lwc/force-app/main/default/classes/GeocodingService.cls' ,
41
42
} ;
42
43
44
+ const registry = new RegistryAccess ( ) ;
45
+ const agentComponents : SourceComponent [ ] = [
46
+ new SourceComponent ( {
47
+ name : 'My_Agent' ,
48
+ type : registry . getTypeByName ( 'Bot' ) ,
49
+ xml : '/dreamhouse-lwc/force-app/main/default/bots/My_Agent.bot-meta.xml' ,
50
+ } ) ,
51
+ new SourceComponent ( {
52
+ name : 'Test_Planner' ,
53
+ type : registry . getTypeByName ( 'GenAiPlanner' ) ,
54
+ xml : '/dreamhouse-lwc/force-app/main/default/genAiPlanners/Test_Planner.genAiPlanner-meta.xml' ,
55
+ } ) ,
56
+ new SourceComponent ( {
57
+ name : 'Test_Plugin1' ,
58
+ type : registry . getTypeByName ( 'GenAiPlugin' ) ,
59
+ xml : '/dreamhouse-lwc/force-app/main/default/genAiPlugins/Test_Plugin1.genAiPlugin-meta.xml' ,
60
+ } ) ,
61
+ new SourceComponent ( {
62
+ name : 'Test_Plugin2' ,
63
+ type : registry . getTypeByName ( 'GenAiPlugin' ) ,
64
+ xml : '/dreamhouse-lwc/force-app/main/default/genAiPlugins/Test_Plugin2.genAiPlugin-meta.xml' ,
65
+ } ) ,
66
+ ] ;
67
+
43
68
export const exampleDeleteResponse = {
44
69
// required but ignored by the delete UT
45
70
getFileResponses : ( ) : void => { } ,
@@ -118,6 +143,7 @@ describe('project delete source', () => {
118
143
let resolveProjectConfigStub : sinon . SinonStub ;
119
144
let rmStub : sinon . SinonStub ;
120
145
let compSetFromSourceStub : sinon . SinonStub ;
146
+ let handlePromptStub : sinon . SinonStub ;
121
147
122
148
class TestDelete extends Source {
123
149
public async runIt ( ) {
@@ -128,7 +154,13 @@ describe('project delete source', () => {
128
154
}
129
155
}
130
156
131
- const runDeleteCmd = async ( params : string [ ] , options ?: { sourceApiVersion ?: string } ) => {
157
+ const runDeleteCmd = async (
158
+ params : string [ ] ,
159
+ options ?: {
160
+ sourceApiVersion ?: string ;
161
+ inquirerMock ?: { checkbox : sinon . SinonStub } ;
162
+ }
163
+ ) => {
132
164
const cmd = new TestDelete ( params , oclifConfigStub ) ;
133
165
cmd . project = SfProject . getInstance ( ) ;
134
166
$$ . SANDBOX . stub ( cmd . project , 'getDefaultPackage' ) . returns ( { name : '' , path : '' , fullPath : defaultPackagePath } ) ;
@@ -151,7 +183,14 @@ describe('project delete source', () => {
151
183
onCancel : ( ) => { } ,
152
184
onError : ( ) => { } ,
153
185
} ) ;
154
- stubMethod ( $$ . SANDBOX , cmd , 'handlePrompt' ) . returns ( confirm ) ;
186
+ 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
+ }
155
194
rmStub = stubMethod ( $$ . SANDBOX , fs . promises , 'rm' ) . resolves ( ) ;
156
195
stubMethod ( $$ . SANDBOX , DeployCache , 'update' ) . resolves ( ) ;
157
196
@@ -233,9 +272,45 @@ describe('project delete source', () => {
233
272
ensureHookArgs ( ) ;
234
273
} ) ;
235
274
236
- it ( 'should pass along metadata and org for pseudo-type matching' , async ( ) => {
275
+ it ( 'should pass along metadata and org for pseudo-type matching with plugins' , async ( ) => {
276
+ const agentCompSet = new ComponentSet ( ) ;
277
+ const pluginNames = [ agentComponents [ 2 ] . name , agentComponents [ 3 ] . name ] ;
278
+ agentComponents . map ( ( comp ) => agentCompSet . add ( comp ) ) ;
279
+ compSetFromSourceStub = compSetFromSourceStub . returns ( agentCompSet ) ;
280
+ const inquirerCheckboxStub = $$ . SANDBOX . stub ( ) . resolves ( pluginNames ) ;
281
+ const inquirerMock = { checkbox : inquirerCheckboxStub } ;
282
+ const metadata = [ 'Agent:My_Agent' ] ;
283
+ await runDeleteCmd ( [ '--metadata' , metadata [ 0 ] , '--json' ] , { inquirerMock } ) ;
284
+ ensureCreateComponentSetArgs ( {
285
+ metadata : {
286
+ metadataEntries : metadata ,
287
+ directoryPaths : [ defaultPackagePath ] ,
288
+ } ,
289
+ org : {
290
+ username : testOrg . username ,
291
+ exclude : [ ] ,
292
+ } ,
293
+ } ) ;
294
+ ensureHookArgs ( ) ;
295
+ expect ( compSetFromSourceStub . calledOnce ) . to . be . true ;
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
+ ] ) ;
302
+ expect ( handlePromptStub . calledOnce ) . to . be . true ;
303
+ expect ( lifecycleEmitStub . firstCall . args [ 1 ] ) . to . deep . equal ( agentComponents ) ;
304
+ } ) ;
305
+
306
+ it ( 'should pass along metadata and org for pseudo-type matching without plugins' , async ( ) => {
307
+ const agentCompSet = new ComponentSet ( ) ;
308
+ agentComponents . map ( ( comp ) => agentCompSet . add ( comp ) ) ;
309
+ compSetFromSourceStub = compSetFromSourceStub . returns ( agentCompSet ) ;
310
+ const inquirerCheckboxStub = $$ . SANDBOX . stub ( ) . resolves ( [ ] ) ;
311
+ const inquirerMock = { checkbox : inquirerCheckboxStub } ;
237
312
const metadata = [ 'Agent:My_Agent' ] ;
238
- await runDeleteCmd ( [ '--metadata' , metadata [ 0 ] , '--json' ] ) ;
313
+ await runDeleteCmd ( [ '--metadata' , metadata [ 0 ] , '--json' ] , { inquirerMock } ) ;
239
314
ensureCreateComponentSetArgs ( {
240
315
metadata : {
241
316
metadataEntries : metadata ,
@@ -248,6 +323,13 @@ describe('project delete source', () => {
248
323
} ) ;
249
324
ensureHookArgs ( ) ;
250
325
expect ( compSetFromSourceStub . calledOnce ) . to . be . true ;
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
+ ] ) ;
331
+ expect ( handlePromptStub . calledOnce ) . to . be . true ;
332
+ expect ( lifecycleEmitStub . firstCall . args [ 1 ] ) . to . deep . equal ( [ agentComponents [ 0 ] , agentComponents [ 1 ] ] ) ;
251
333
} ) ;
252
334
253
335
it ( 'should pass along apiversion' , async ( ) => {
0 commit comments