@@ -33,6 +33,7 @@ describe('org:open:agent', () => {
3333
3434 const mockBotId = '0Xx1234567890ABCD' ;
3535 const mockBotName = 'TestAgent' ;
36+ const mockVersionId = '0X9DD0000000032s0AA' ;
3637
3738 let sfCommandUxStubs : ReturnType < typeof stubSfCommandUx > ;
3839
@@ -107,27 +108,6 @@ describe('org:open:agent', () => {
107108 expect ( ( error as Error ) . message ) . to . match ( / e x a c t l y o n e | c a n n o t a l s o b e p r o v i d e d / i) ;
108109 }
109110 } ) ;
110-
111- it ( 'requires authoring-bundle when version is provided' , async ( ) => {
112- try {
113- await OrgOpenAgent . run ( [
114- '--json' ,
115- '--target-org' ,
116- testOrg . username ,
117- '--url-only' ,
118- '--api-name' ,
119- mockBotName ,
120- '--version' ,
121- '1' ,
122- ] ) ;
123- assert . fail ( 'Should have thrown an error' ) ;
124- } catch ( error ) {
125- expect ( error ) . to . exist ;
126- expect ( ( error as Error ) . message ) . to . include ( '--version' ) ;
127- expect ( ( error as Error ) . message ) . to . include ( '--authoring-bundle' ) ;
128- expect ( ( error as Error ) . message ) . to . match ( / A l l o f t h e f o l l o w i n g m u s t b e p r o v i d e d | d e p e n d s o n / i) ;
129- }
130- } ) ;
131111 } ) ;
132112
133113 describe ( 'url generation with api-name' , ( ) => {
@@ -168,6 +148,45 @@ describe('org:open:agent', () => {
168148 expect ( spies . get ( 'singleRecordQuery' ) . callCount ) . to . equal ( 1 ) ;
169149 expect ( spies . get ( 'singleRecordQuery' ) . firstCall . args [ 0 ] ) . to . include ( specialName ) ;
170150 } ) ;
151+
152+ it ( 'builds URL with api-name and version using BotVersion query' , async ( ) => {
153+ const version = '2' ;
154+ // Override the singleRecordQuery stub to return different results for BotDefinition and BotVersion
155+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
156+ const singleRecordQueryStub = spies . get ( 'singleRecordQuery' ) ;
157+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
158+ singleRecordQueryStub . onFirstCall ( ) . resolves ( { Id : mockBotId } ) ; // BotDefinition query
159+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
160+ singleRecordQueryStub . onSecondCall ( ) . resolves ( { Id : mockVersionId } ) ; // BotVersion query
161+
162+ const response = await OrgOpenAgent . run ( [
163+ '--json' ,
164+ '--target-org' ,
165+ testOrg . username ,
166+ '--url-only' ,
167+ '--api-name' ,
168+ mockBotName ,
169+ '--version' ,
170+ version ,
171+ ] ) ;
172+ assert ( response ) ;
173+ testJsonStructure ( response ) ;
174+
175+ // Verify both queries were made
176+ expect ( singleRecordQueryStub . callCount ) . to . equal ( 2 ) ;
177+
178+ // Verify BotDefinition query
179+ expect ( singleRecordQueryStub . firstCall . args [ 0 ] ) . to . include ( mockBotName ) ;
180+ expect ( singleRecordQueryStub . firstCall . args [ 0 ] ) . to . include ( 'BotDefinition' ) ;
181+
182+ // Verify BotVersion query
183+ expect ( singleRecordQueryStub . secondCall . args [ 0 ] ) . to . include ( 'BotVersion' ) ;
184+ expect ( singleRecordQueryStub . secondCall . args [ 0 ] ) . to . include ( mockBotId ) ;
185+ expect ( singleRecordQueryStub . secondCall . args [ 0 ] ) . to . include ( `VersionNumber=${ version } ` ) ;
186+
187+ const expectedPath = `AiCopilot/copilotStudio.app#/copilot/builder?copilotId=${ mockBotId } &versionId=${ mockVersionId } ` ;
188+ expect ( response . url ) . to . equal ( getExpectedUrlWithPath ( expectedPath ) ) ;
189+ } ) ;
171190 } ) ;
172191
173192 describe ( 'url generation with authoring-bundle' , ( ) => {
0 commit comments