# Testing

Gravity comes with a full suite of integration tests included to ensure your application functions as it should before releasing it.&#x20;

{% hint style="warning" %}
Please set the **SUPPORT\_EMAIL** variable in your [environment](/gravity-server/environment-variables.md) before running tests as this email is used for testing.
{% endhint %}

```javascript
// to start the tests, run:
gravity test

// or
npm test
```

The testing suite uses [mocha](https://mochajs.org) and [chai](https://www.chaijs.com), boilerplate tests are in the `/test` folder.&#x20;

## How Tests Work

A test calls the API endpoint and passes a data object. The response is then tested to ensure the correct status is returned and the returned data matches a specific format.

```javascript
describe('POST /account', () => {
  it ('should create a new paid account', done => {

    config.account.paid.token = { id: 'tok_visa' };

    chai.request(server)
    .post('/api/account')
    .send(config.account.paid)
    .end((err, res) => {

      res.should.have.status(200);
      res.body.token.should.be.a('string');
      res.body.plan.should.eq(config.account.paid.plan);
      res.body.subscription.should.eq('active');
      process.env.token = 'Bearer ' + res.body.token;

      // cleanup
      delete config.account.paid.token;
      done();

    });
  }).timeout(config.timeout);
});
```

To add your tests, create a new test script and import it to the `run.js` file; use the example above as a template.

{% hint style="info" %}
Tests are designed to work with `email_verification` enabled. If you modify the config, some tests may fail and need to be adjusted for your own requirements.
{% endhint %}


---

# 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.usegravity.app/gravity-server/testing.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.
