# Run automated tests

This example will help you implement and run automated tests with Forest Admin.\
\
A typical use case, would be to run automated test on:

* your different smart actions
* your CRUD routes

to avoid testing them manually.

{% tabs %}
{% tab title="Testing CRUD routes" %}

```javascript
const axios = require('axios');
const jwt = require('jsonwebtoken');

const FOREST_AUTH_SECRET = //The content of the FOREST_AUTH_SECRET from your app
// All the informations below are base64 encoded in your JWT token.
const user = {
  id: //the id of the user to connect with,
  email: //the email of the user to connect with,
  firstName: //the first name of the user to connect with,
  lastName: //the last name of the user to connect with,
  team: //the team name (case sensitive) to connect to,
  renderingId: //the rendering ID to connect to,
  role: //the id of the role of the user
}

function getUserToken() {
  return jwt.sign(user, FOREST_AUTH_SECRET, {
    expiresIn: '30 minutes',
  });
}

async function getAddress() {  
  const forestToken = getUserToken();  
  
  const config = {
    method: 'get',
    url: 'http://localhost:3310/forest/addresses/5ff4738a2798354aa24794e7', //example url to get data
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${forestToken}`,
    },
  };  
  
  try {
    return await axios(config); //this performs the call
  } catch(e) {
    console.log(e);
  }
}

/**
 * Here is an example about how to retrieve your data
 */
getAddress().then((address) => {
  console.log(address.data.data.attributes);
})

```

{% endtab %}

{% tab title="Testing smart actions" %}

```javascript
const axios = require('axios');
const jwt = require('jsonwebtoken');

const FOREST_AUTH_SECRET = //The content of the FOREST_AUTH_SECRET from your app
const user = {
  id: //the id of the user to connect with,
  email: //the email of the user to connect with,
  firstName: //the first name of the user to connect with,
  lastName: //the last name of the user to connect with,
  team: //the team name (case sensitive) to connect to,
  renderingId: //the rendering ID to connect to,
}

function getUserToken() {
  return jwt.sign(user, FOREST_AUTH_SECRET, {
    expiresIn: '30 minutes',
  });
}

function testAction() {
  const forestToken = getUserToken();
    
  const config = {
    method: 'post',
    url: 'http://localhost:3310/forest/actions/smart-action-name', // the url to call your smart action
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${forestToken}`,
    },
    data: {
      data: {
        attributes: {
          collection_name: '', // the collection name to apply the action to
          ids: [], // the ids to apply the smart action to, in an array of string
          values: { }, // your form values if you have any with the format fieldName: value
        },
      },
    }
  };
  
  return axios(config); //this performs the call
}

/**
 * Here is an example about how to retrieve your data
 */
testAction().then((response) => {
  console.log(response);
}).catch((error) => {
  console.log(error);
});

```

{% endtab %}
{% endtabs %}

Request URL: <https://api.forestadmin.com/forest/actions/refresh-cache>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.forestadmin.com/woodshop/how-tos/run-automated-tests.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
