Testing your agent

circle-check

Testing Your Agent

Test your Forest Admin customizations locally without connecting to Forest Admin servers.

Installation

npm install --save-dev @forestadmin/agent-testing

Quick Start

The testing library provides two main functions:

  • createForestServerSandbox(port) - Starts a local mock server that simulates Forest Admin servers.

  • createAgentTestClient(options) - Creates a test client to interact with your agent.

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

Test CRUD operations and hooks.

List

Test that filters return the correct records.

Create

Test that a record is correctly created.

Update

Test that a record is correctly updated.

Delete

Test that a record is correctly deleted.

Actions

Test smart actions and form behavior.

Dynamic forms

Test fields that appear based on other field values.

Field properties

Test field validation rules.

Computed Fields

Test custom computed fields.

Segments

Test custom segments.

Charts

Test dashboard charts.

Last updated