Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a database and sails.request() with unit tests #494

Open
not-an-aardvark opened this issue Dec 26, 2015 · 0 comments
Open

Use a database and sails.request() with unit tests #494

not-an-aardvark opened this issue Dec 26, 2015 · 0 comments

Comments

@not-an-aardvark
Copy link
Contributor

Apparently having a test database is supported by Travis. If we use that along with sails.request(), we'll be able to fully test requests to the server rather than just testing service methods, which should make our unit tests much more effective.

I couldn't find any good documentation on the sails.request() function (it was briefly mentioned in this migration guide), but I messed around and came up with an example unit test.

describe('API calls', function () {
  this.timeout(10000);
  before(function beforeRunningAnyTests (done){
    // Load the app (no need to lift to a port)
    require('sails').load({log: {level: 'warn'}, hooks: {grunt: false}}, function whenAppIsReady(err){
      return done(err);
    });
  });

  it('Gets a user profile correctly', function (done) {
    sails.request({method: 'get', url: '/user/get/not_an_aardvark'}, function (err, clientRes, body) {
      assert.equal(clientRes.statusCode, 200);
      assert.equal(body.name, 'not_an_aardvark');
      assert.ok(body.isMod);
      assert.notOk(body.redToken); // don't send a user's redToken to the client
      // etc
      done(err);
    });
  });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants