summaryrefslogtreecommitdiffstats
path: root/common/src/main/webapp/usageguide/appserver/node_modules/node-restful/test/model.hooks.js
blob: 9207cbc5179c17d4084da755c782b019a5649a23 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
var config = require('./fixtures/config'),
    request = require('supertest'),
    sinon = require('sinon');

describe('Model', function() {
  var app, movie, user;
  before(function() {
    app = config.app;
    movie = config.movie;
    user = config.user;
  });
  describe('before hook', function() {
    it('should call the before hook on a GET', function() {
      movie.routes.get.before.length.should.equal(1);
      movie.routes.get.after.length.should.equal(1);
    });
    it('should call the before hook on a POST', function() {
      movie.routes.post.before.length.should.equal(1);
      movie.routes.post.after.length.should.equal(1);
    });
    it('should call the before hook on a PUT', function() {
      movie.routes.put.before.length.should.equal(1);
      movie.routes.put.after.length.should.equal(1);
    });
    it('should call after all hook on user defined all route', function(done) {
      request(app)
        .get('/api/movies/recommend')
        .end(function(err, res) {
          res.body.recommend.should.equal('called');
          res.body.after.should.equal('called');
          done();
        });
    });
    it('should call before all hook on user defined get route', function(done) {
      request(app)
        .get('/api/movies/' + config.movies[2]._id + '/athirdroute')
        .end(function(err, res) {
          res.body.athirdroute.should.equal('called');
          res.body.after.should.equal('called');
          done();
        });
    });
    it('should use the properties set in a before route for filtering', function(done) {
      request(app)
        .get('/users')
        .end(function(err, res) {
          res.body.should.have.length(1);
          done(err);
        });
    });
  });
});