Skip to content

Commit 400a1e6

Browse files
committed
fix: add tests for activate and deactivate
1 parent fbad38c commit 400a1e6

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

test/nuts/agent.nut.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ describe('plugin-agent NUTs', () => {
121121
console.dir(deployResult2.response, { depth: 10 });
122122
}
123123
expect(deployResult2.response.success, 'expected Agent Test deploy to succeed').to.equal(true);
124+
125+
// wait for the agent to be provisioned
126+
console.log('\nwaiting 2 minutes for agent provisioning...');
127+
await sleep(120_000);
124128
});
125129

126130
describe('agent test list', () => {
@@ -223,6 +227,42 @@ describe('plugin-agent NUTs', () => {
223227
});
224228
});
225229

230+
describe('agent activate/deactivate', () => {
231+
const botApiName = 'Local_Info_Agent';
232+
const botStatusQuery = `SELECT Status FROM BotVersion WHERE BotDefinitionId IN (SELECT Id FROM BotDefinition WHERE DeveloperName = '${botApiName}') LIMIT 1`;
233+
234+
it('should activate the agent', async () => {
235+
// Verify the BotVersion status has 'Inactive' initial state
236+
const botVersionInitalState = await connection.singleRecordQuery<{ Status: string }>(botStatusQuery);
237+
expect(botVersionInitalState.Status).to.equal('Inactive');
238+
239+
try {
240+
execCmd(`agent activate --api-name ${botApiName} --target-org ${username} --json`, { ensureExitCode: 0 });
241+
} catch (err) {
242+
const errMsg = err instanceof Error ? err.message : 'unknown';
243+
console.log(`Error activating agent due to ${errMsg}. \nWaiting 2 minutes and trying again...`);
244+
await sleep(120_000);
245+
execCmd(`agent activate --api-name ${botApiName} --target-org ${username} --json`, { ensureExitCode: 0 });
246+
}
247+
248+
// Verify the BotVersion status is now 'Active'
249+
const botVersionResult = await connection.singleRecordQuery<{ Status: string }>(botStatusQuery);
250+
expect(botVersionResult.Status).to.equal('Active');
251+
});
252+
253+
it('should deactivate the agent', async () => {
254+
// Verify the BotVersion status has 'Active' initial state
255+
const botVersionInitalState = await connection.singleRecordQuery<{ Status: string }>(botStatusQuery);
256+
expect(botVersionInitalState.Status).to.equal('Active');
257+
258+
execCmd(`agent deactivate --api-name ${botApiName} --target-org ${username} --json`, { ensureExitCode: 0 });
259+
260+
// Verify the BotVersion status is now 'Inactive'
261+
const botVersionResult = await connection.singleRecordQuery<{ Status: string }>(botStatusQuery);
262+
expect(botVersionResult.Status).to.equal('Inactive');
263+
});
264+
});
265+
226266
describe('agent create', () => {
227267
const specFileName = genUniqueString('agentSpec_%s.yaml');
228268

0 commit comments

Comments
 (0)