Skip to content

Commit

Permalink
Completed connect intégration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
angelini committed Jan 12, 2012
1 parent 6af526d commit f603573
Showing 1 changed file with 80 additions and 3 deletions.
83 changes: 80 additions & 3 deletions tests/connectIntegration-test.js
@@ -1,3 +1,6 @@
var PORT = 3131;
var BASE_URL = 'http://127.0.0.1:' + PORT;

var vows = require('vows'); var vows = require('vows');
var assert = require('assert'); var assert = require('assert');


Expand All @@ -6,13 +9,15 @@ var request = require('request');
var resty = require('../lib/resty'); var resty = require('../lib/resty');


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


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


'should contain {all: "users"}': function(err, res, body) { 'should contain {all: "users"}': function(err, res, body) {
Expand All @@ -23,13 +28,85 @@ vows.describe('Using connect').addBatch({


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


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

'testing nested Resource get request': {
'topic': function() {
request(BASE_URL + '/users/123/contacts/456', this.callback);
},

'should contain a uid and cid': function(err, res, body) {
body = JSON.parse(body);

assert.isNull(err);
assert.equal(body.uid, '123');
assert.equal(body.cid, '456');
}
},

'testing querystring support': {
'topic': function() {
request(BASE_URL + '/users/123?hello=world', this.callback);
},

'should have accessed the querystring': function(err, res, body) {
assert.isNull(err);
assert.equal(JSON.parse(body).query.hello, 'world');
}
},

'testing POST and body support': {
'topic': function() {
request({
uri: BASE_URL + '/users/123/contacts/456',
method: 'POST',
body: JSON.stringify({ test: 'data' }),
headers: {
'Content-Type': 'application/json'
}
}, this.callback);
},

'should have accessed the body': function(err, res, body) {
assert.isNull(err);
assert.equal(JSON.parse(body).body.test, 'data');
}
},

'invalid resource request': {
'topic': function() {
request(BASE_URL + '/does/not/exist', this.callback);
},

'should return Resource Not Found': function(err, res, body) {
assert.isNull(err);
assert.equal(JSON.parse(body).error, 'Resource Not Found');
}
},

'invalid method request': {
'topic': function() {
request({
uri: BASE_URL + '/users/123',
method: 'POST',
body: JSON.stringify({ test: 'data' }),
headers: {
'Content-Type': 'application/json'
}
}, this.callback);
},

'should return Method Not Found': function(err, res, body) {
assert.isNull(err);
assert.equal(JSON.parse(body).error, 'Method Not Found');
}
} }
})['export'](module); })['export'](module);


0 comments on commit f603573

Please sign in to comment.