Skip to content

Commit

Permalink
More tests, including connect integration
Browse files Browse the repository at this point in the history
  • Loading branch information
angelini committed Jan 12, 2012
1 parent 650eeca commit 6af526d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/connectIntegration-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
var vows = require('vows');
var assert = require('assert');

var connect = require('connect');
var request = require('request');
var resty = require('../lib/resty');

var app = connect.createServer();
app.use(resty.middleware(__dirname + '/../example/resources'));
app.listen(3131);

vows.describe('Using connect').addBatch({
'testing Collection get request': {
'topic': function() {
request('http://127.0.0.1:3131/users', this.callback);
},

'should contain {all: "users"}': function(err, res, body) {
assert.isNull(err);
assert.equal(JSON.parse(body).all, 'users');
}
},

'testing Resource get request': {
'topic': function() {
request('http://127.0.0.1:3131/users/123', this.callback);
},

'should contain {uid: 123}': function(err, res, body) {
assert.isNull(err);
assert.equal(JSON.parse(body).uid, '123');
}
}
})['export'](module);

10 changes: 10 additions & 0 deletions tests/readResources-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ vows.describe('Read Resources').addBatch({
'_main.Resource get should be a function': function(resources) {
assert.equal(typeof resources.users._main.Resource.get, 'function');
}
},

'Read an invalid resource folder': {
topic: function() {
return readResources(__dirname + '/does/not/exist');
},

'should return an Error object': function(resources) {
assert.equal(resources.code, 'ENOENT');
}
}
})['export'](module);

0 comments on commit 6af526d

Please sign in to comment.