1414 * limitations under the License.
1515 */
1616import { join } from 'node:path' ;
17+ import { existsSync , renameSync } from 'node:fs' ;
1718import { expect } from 'chai' ;
1819import { TestSession } from '@salesforce/cli-plugins-testkit' ;
1920import { execCmd } from '@salesforce/cli-plugins-testkit' ;
21+ import { Org , User } from '@salesforce/core' ;
2022import type { AgentPublishAuthoringBundleResult } from '../../src/commands/agent/publish/authoring-bundle.js' ;
2123
2224describe ( 'agent publish authoring-bundle NUTs' , ( ) => {
@@ -35,6 +37,39 @@ describe('agent publish authoring-bundle NUTs', () => {
3537 } ,
3638 ] ,
3739 } ) ;
40+
41+ // Assign required permission sets to the scratch org admin user
42+ const username = session . orgs . get ( 'default' ) ! . username as string ;
43+ const defaultOrg = await Org . create ( { aliasOrUsername : username } ) ;
44+ const connection = defaultOrg . getConnection ( ) ;
45+ const queryResult = await connection . singleRecordQuery < { Id : string } > (
46+ `SELECT Id FROM User WHERE Username='${ username } '`
47+ ) ;
48+ const user = await User . create ( { org : defaultOrg } ) ;
49+ await user . assignPermissionSets ( queryResult . Id , [ 'EinsteinGPTPromptTemplateManager' , 'ExecutePromptTemplates' ] ) ;
50+
51+ // Rename valid.xml to valid.bundle-meta.xml for the publish test
52+ const validXmlPath = join (
53+ session . project . dir ,
54+ 'force-app' ,
55+ 'main' ,
56+ 'default' ,
57+ 'aiAuthoringBundles' ,
58+ 'valid' ,
59+ 'valid.xml'
60+ ) ;
61+ const validBundleMetaPath = join (
62+ session . project . dir ,
63+ 'force-app' ,
64+ 'main' ,
65+ 'default' ,
66+ 'aiAuthoringBundles' ,
67+ 'valid' ,
68+ 'valid.bundle-meta.xml'
69+ ) ;
70+ if ( existsSync ( validXmlPath ) && ! existsSync ( validBundleMetaPath ) ) {
71+ renameSync ( validXmlPath , validBundleMetaPath ) ;
72+ }
3873 } ) ;
3974
4075 after ( async ( ) => {
@@ -43,7 +78,7 @@ describe('agent publish authoring-bundle NUTs', () => {
4378
4479 it ( 'should publish a valid authoring bundle' , ( ) => {
4580 const username = session . orgs . get ( 'default' ) ! . username as string ;
46- const bundleApiName = 'Local_Info_Agent ' ;
81+ const bundleApiName = 'valid ' ;
4782
4883 const result = execCmd < AgentPublishAuthoringBundleResult > (
4984 `agent publish authoring-bundle --api-name ${ bundleApiName } --target-org ${ username } --json` ,
@@ -58,15 +93,14 @@ describe('agent publish authoring-bundle NUTs', () => {
5893
5994 it ( 'should fail for invalid bundle path' , ( ) => {
6095 const username = session . orgs . get ( 'default' ) ! . username as string ;
61- const bundlePath = join ( session . project . dir , 'invalid' , 'path' ) ;
62- const agentName = 'Test Agent' ;
96+ const bundleApiName = 'nonexistent' ;
6397
6498 const result = execCmd < AgentPublishAuthoringBundleResult > (
65- `agent publish authoring-bundle --api-name ${ bundlePath } --agent-name " ${ agentName } " --target-org ${ username } --json` ,
99+ `agent publish authoring-bundle --api-name ${ bundleApiName } --target-org ${ username } --json` ,
66100 { ensureExitCode : 1 }
67101 ) . jsonOutput ;
68102
69103 expect ( result ! . exitCode ) . to . equal ( 1 ) ;
70- expect ( JSON . stringify ( result ) ) . to . include ( 'Invalid bundle path ' ) ;
104+ expect ( JSON . stringify ( result ) ) . to . include ( 'Couldn\'t find a ". bundle-meta.xml" file ' ) ;
71105 } ) ;
72106} ) ;
0 commit comments