Testing your agent
Testing Your Agent
Installation
npm install --save-dev @forestadmin/agent-testingQuick Start
import {
createAgentTestClient,
createForestServerSandbox,
} from '@forestadmin/agent-testing';
describe('My Agent', () => {
let sandbox, client;
beforeAll(async () => {
// Start mock server
sandbox = await createForestServerSandbox(3001);
// Connect test client
client = await createAgentTestClient({
serverUrl: 'http://localhost:3001',
agentUrl: 'http://localhost:3310',
agentSchemaPath: './.forestadmin-schema.json',
agentForestEnvSecret: process.env.FOREST_ENV_SECRET,
agentForestAuthSecret: process.env.FOREST_AUTH_SECRET,
});
});
afterAll(async () => {
await sandbox?.stop();
});
it('should list users', async () => {
const users = await client.collection('users').list();
expect(users.length).toBeGreaterThan(0);
});
it('should execute action', async () => {
const action = await client
.collection('orders')
.action('Apply discount', { recordId: 1 });
await action.getFieldNumber('discount').fill(10);
const result = await action.execute();
expect(result.success).toBe(true);
});
});Collections
List
Create
Update
Delete
Actions
Dynamic forms
Field properties
Computed Fields
Segments
Charts
Last updated