# Supertest backend, permission error while initialization

**URL:** <https://community.forestadmin.com/t/supertest-backend-permission-error-while-initialization/4235>\
**Category:** Help me!\
**Created:** [February 19, 2022, 6:48pm UTC](https://community.forestadmin.com/t/supertest-backend-permission-error-while-initialization/4235 "2022-02-19T18:48:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Justin\_Martin](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/justin_martin/32/1028_2.png) [@Justin\_Martin](https://community.forestadmin.com/u/Justin_Martin)\
**Post date:** [February 19, 2022, 6:48pm UTC](https://community.forestadmin.com/t/supertest-backend-permission-error-while-initialization/4235/1 "2022-02-19T18:48:09Z")

</div>

Hello,

I’m trying to test one of my backend route using `jest` and `supertest` but an error occured and i don’t know why.

Error: ` [forest] 🌳🌳🌳 Permissions error: Cannot retrieve the data from the Forest server. Can you check that you properly copied the Forest envSecret in the Liana initializer?`

I already check in `process.env` if all are ok and the value of `FOREST_ENV_SECRET` is good. Also when i start my server in dev mode (`yarn start` instead of `yarn test`) all works well while my FOREST\_ENV\_SECRET is the same

router.test.js :

```javascript
const models = require('../../../models');
const { last } = require('lodash');
const request = require('supertest');

const app = require('../../../app.js');
const { initFactories, clearDatabase } = require('../../../test-utils/helper');
const { getUserToken } = require('../../../test-utils/auth');

const {
  fields: {
    DISTANCE_OPTIONS,
    DISTANCE_OPTION_INPUT_FIELD,
    DISTANCE_XX_INPUT_FIELD,
    DISTANCE_YY_INPUT_FIELD,
  },
} = require('../../utils/filter-care-giver/ui');

describe('Router > Announce', () => {
  let factories;

  beforeAll(() => {
    factories = initFactories(models);
  });

  afterEach(async () => {
    await clearDatabase(models);
  });

  it('POST /forest/announce/actions/filter-care-giver', async () => {
    const { id } = await factories.institution.createOne({});

    const form = {
      [DISTANCE_OPTION_INPUT_FIELD]: last(DISTANCE_OPTIONS).field,
      [DISTANCE_XX_INPUT_FIELD]: 7,
      [DISTANCE_YY_INPUT_FIELD]: 1024,
    };

    const body = { body: { data: { attributes: { ids: [id], values: form } } } };
    await request(app)
      .post('/forest/announce/actions/filter-care-giver')
      .set('Authorization', `Bearer ${getUserToken()}`)
      .send(body)
      .expect(200);
  });
});

```

---

<div class="post-metadata">

**Author:** ![Justin\_Martin](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/justin_martin/32/1028_2.png) [@Justin\_Martin](https://community.forestadmin.com/u/Justin_Martin)\
**Post date:** [February 19, 2022, 10:22pm UTC](https://community.forestadmin.com/t/supertest-backend-permission-error-while-initialization/4235/2 "2022-02-19T22:22:51Z")

</div>

Ok I found an other solution based on `start-server-and-test`. I use `.env` files to setup my test environment.

I add theses scripts in my `package.json` :

```javascript
    "start:test": "node -r dotenv/config ./server.js dotenv_config_path=.env.test",
    "test": "start-server-and-test 'yarn start:test' http://localhost:3310 'yarn test:run'",
    "test:run": "jest --watch"

```

And so i don’t have to import my `app.js` in test file
