Skip to content

Commit 677602d

Browse files
test: assign perms to SO user
1 parent f074fb9 commit 677602d

3 files changed

Lines changed: 107 additions & 5 deletions

File tree

test/nuts/agent.generate.authoring-bundle.nut.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { existsSync, readFileSync } from 'node:fs';
1919
import { expect } from 'chai';
2020
import { genUniqueString, TestSession } from '@salesforce/cli-plugins-testkit';
2121
import { execCmd } from '@salesforce/cli-plugins-testkit';
22+
import { Org, User } from '@salesforce/core';
2223
import type { AgentGenerateAuthoringBundleResult } from '../../src/commands/agent/generate/authoring-bundle.js';
2324

2425
let session: TestSession;
@@ -37,6 +38,16 @@ describe('agent generate authoring-bundle NUTs', () => {
3738
},
3839
],
3940
});
41+
42+
// Assign required permission sets to the scratch org admin user
43+
const username = session.orgs.get('default')!.username as string;
44+
const defaultOrg = await Org.create({ aliasOrUsername: username });
45+
const connection = defaultOrg.getConnection();
46+
const queryResult = await connection.singleRecordQuery<{ Id: string }>(
47+
`SELECT Id FROM User WHERE Username='${username}'`
48+
);
49+
const user = await User.create({ org: defaultOrg });
50+
await user.assignPermissionSets(queryResult.Id, ['EinsteinGPTPromptTemplateManager', 'ExecutePromptTemplates']);
4051
});
4152

4253
after(async () => {

test/nuts/agent.publish.nut.ts

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
* limitations under the License.
1515
*/
1616
import { join } from 'node:path';
17+
import { existsSync, renameSync } from 'node:fs';
1718
import { expect } from 'chai';
1819
import { TestSession } from '@salesforce/cli-plugins-testkit';
1920
import { execCmd } from '@salesforce/cli-plugins-testkit';
21+
import { Org, User } from '@salesforce/core';
2022
import type { AgentPublishAuthoringBundleResult } from '../../src/commands/agent/publish/authoring-bundle.js';
2123

2224
describe('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
});

test/nuts/agent.validate.nut.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
* limitations under the License.
1515
*/
1616
import { join } from 'node:path';
17+
import { existsSync, renameSync } from 'node:fs';
1718
import { expect } from 'chai';
1819
import { TestSession } from '@salesforce/cli-plugins-testkit';
1920
import { execCmd } from '@salesforce/cli-plugins-testkit';
21+
import { Org, User } from '@salesforce/core';
2022
import type { AgentValidateAuthoringBundleResult } from '../../src/commands/agent/validate/authoring-bundle.js';
2123

2224
describe('agent validate authoring-bundle NUTs', () => {
@@ -35,6 +37,61 @@ describe('agent validate 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 .xml files to .bundle-meta.xml for the validate 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+
}
73+
74+
const invalidXmlPath = join(
75+
session.project.dir,
76+
'force-app',
77+
'main',
78+
'default',
79+
'aiAuthoringBundles',
80+
'invalid',
81+
'invalid.xml'
82+
);
83+
const invalidBundleMetaPath = join(
84+
session.project.dir,
85+
'force-app',
86+
'main',
87+
'default',
88+
'aiAuthoringBundles',
89+
'invalid',
90+
'invalid.bundle-meta.xml'
91+
);
92+
if (existsSync(invalidXmlPath) && !existsSync(invalidBundleMetaPath)) {
93+
renameSync(invalidXmlPath, invalidBundleMetaPath);
94+
}
3895
});
3996

4097
after(async () => {

0 commit comments

Comments
 (0)