Unit Tests

Gravity comes with a full suite of unit tests included in the toolbelt. You can run these to ensure your application functions as it should before releasing it.

// to start the tests, run:
gravity test

The testing suite uses mocha and chai, you can find boilerplate tests in the /test folder.

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.

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(true);
process.env.token = 'Bearer ' + res.body.token;
// cleanup
delete config.account.paid.token;
done();
});
}).timeout(config.timeout);
});

To add your own tests, simply create a new test script and import it to the run.js file (executed by the toolbelt). Use the example above as a template to get you started.

You can also use npm test