Skip to content

Commit

Permalink
chore: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Nov 13, 2024
1 parent 50b1615 commit 8ef2616
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 17 deletions.
1 change: 0 additions & 1 deletion src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export class Agent implements SfAgent {

let agentSpec: AgentJobSpec;
const response = await this.maybeMock.request<AgentJobSpecCreateResponse>('GET', this.buildAgentJobSpecUrl(config));

if (response.isSuccess && response.jobSpecs) {
agentSpec = response.jobSpecs;
} else {
Expand Down
29 changes: 14 additions & 15 deletions src/maybe-mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,21 +128,20 @@ export class MaybeMock {
if (this.mockDir) {
this.logger.debug(`Mocking ${method} request to ${url} using ${this.mockDir}`);
const responses = await readResponses<T>(this.mockDir, url, this.logger);
if (!this.scopes.has(url)) {
const scope = nock(this.connection.baseUrl());
this.scopes.set(url, scope);
switch (method) {
case 'GET':
for (const response of responses) {
scope.get(url).reply(200, response);
}
break;
case 'POST':
for (const response of responses) {
scope.post(url, body).reply(200, response);
}
break;
}
const baseUrl = this.connection.baseUrl();
const scope = this.scopes.get(baseUrl) ?? nock(baseUrl);
this.scopes.set(baseUrl, scope);
switch (method) {
case 'GET':
for (const response of responses) {
scope.get(url).reply(200, response);
}
break;
case 'POST':
for (const response of responses) {
scope.post(url, body).reply(200, response);
}
break;
}
}

Expand Down
31 changes: 30 additions & 1 deletion test/agentJobSpecCreate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,51 @@ import { expect } from 'chai';
import { MockTestOrgData, TestContext } from '@salesforce/core/testSetup';
import { SfProject } from '@salesforce/core';
import { Agent } from '../src/agent';
import { AgentJobSpecCreateConfig } from '../src/types';

describe('agent job spec create test', () => {
const $$ = new TestContext();
const testOrg = new MockTestOrgData();
$$.inProject(true);

process.env.SF_MOCK_DIR = 'test/mocks';

it('runs agent run test', async () => {
const connection = await testOrg.getConnection();
connection.instanceUrl = 'https://mydomain.salesforce.com';
const sfProject = SfProject.getInstance();
$$.SANDBOXES.CONNECTION.restore();
const agent = new Agent(connection, sfProject);
const output = await agent.createSpec({
name: 'MyFirstAgent',
type: 'customer_facing',
role: 'answer questions about vacation_rentals',
companyName: 'Coral Cloud Enterprises',
companyDescription: 'Provide vacation rentals and activities',
});

// TODO: make this assertion more meaningful
expect(output).to.be.ok;
});

it('creates an agent', async () => {
const connection = await testOrg.getConnection();
connection.instanceUrl = 'https://mydomain.salesforce.com';
const sfProject = SfProject.getInstance();
$$.SANDBOXES.CONNECTION.restore();
const agent = new Agent(connection, sfProject);
const output = agent.createSpec({
const opts: AgentJobSpecCreateConfig = {
name: 'MyFirstAgent',
type: 'customer_facing',
role: 'answer questions about vacation rentals',
companyName: 'Coral Cloud Enterprises',
companyDescription: 'Provide vacation rentals and activities',
};
const jobSpecs = await agent.createSpec(opts);
expect(jobSpecs).to.be.ok;
const output = agent.create({
...opts,
jobSpecs,
});
expect(output).to.be.ok;
});
Expand Down
90 changes: 90 additions & 0 deletions test/mocks/connect_agent-job-spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{
"isSuccess": true,
"type": "customer_facing",
"role": "replace me",
"companyName": "replace me",
"companyDescription": "replace me",
"companyWebsite": "replace me",
"jobSpecs": [
{
"jobTitle": "Guest_Experience_Enhancement",
"jobDescription": "Develop and implement entertainment programs to enhance guest experience."
},
{
"jobTitle": "Event_Planning_and_Execution",
"jobDescription": "Plan, organize, and execute resort events and activities."
},
{
"jobTitle": "Vendor_Management",
"jobDescription": "Coordinate with external vendors for event supplies and services."
},
{
"jobTitle": "Staff_Training_and_Development",
"jobDescription": "Train and develop staff to deliver exceptional entertainment services."
},
{
"jobTitle": "Budget_Management",
"jobDescription": "Manage budgets for entertainment activities and events."
},
{
"jobTitle": "Guest_Feedback_Analysis",
"jobDescription": "Collect and analyze guest feedback to improve entertainment offerings."
},
{
"jobTitle": "Marketing_Collaboration",
"jobDescription": "Work with marketing to promote events and entertainment activities."
},
{
"jobTitle": "Technology_Integration",
"jobDescription": "Utilize technology to enhance guest engagement and streamline operations."
},
{
"jobTitle": "Safety_and_Compliance",
"jobDescription": "Ensure all entertainment activities comply with safety regulations."
},
{
"jobTitle": "Performance_Monitoring",
"jobDescription": "Monitor and evaluate the performance of entertainment programs."
},
{
"jobTitle": "Community_Partnerships",
"jobDescription": "Build partnerships with local artists and performers."
},
{
"jobTitle": "Inventory_Management",
"jobDescription": "Manage inventory of entertainment equipment and supplies."
},
{
"jobTitle": "Custom_Experience_Creation",
"jobDescription": "Design personalized entertainment experiences for VIP guests."
},
{
"jobTitle": "Data_Reporting",
"jobDescription": "Generate reports on entertainment program performance and guest satisfaction."
},
{
"jobTitle": "Crisis_Management",
"jobDescription": "Develop plans to handle emergencies during entertainment events."
},
{
"jobTitle": "Digital_Engagement",
"jobDescription": "Enhance online presence and engagement through social media."
},
{
"jobTitle": "Salesforce_Integration",
"jobDescription": "Utilize Salesforce to track guest preferences and tailor entertainment."
},
{
"jobTitle": "Trend_Analysis",
"jobDescription": "Stay updated on industry trends to keep entertainment offerings fresh."
},
{
"jobTitle": "Cross_Department_Coordination",
"jobDescription": "Collaborate with other departments to ensure seamless guest experience."
},
{
"jobTitle": "Resource_Optimization",
"jobDescription": "Optimize the use of resources to maximize guest satisfaction."
}
]
}

0 comments on commit 8ef2616

Please sign in to comment.