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.

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);
})

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

Last updated