From f603573910e46c4af1f400433d02a59a6ffba120 Mon Sep 17 00:00:00 2001 From: Alex Angelini Date: Thu, 12 Jan 2012 14:34:38 -0500 Subject: [PATCH] =?UTF-8?q?Completed=20connect=20int=C3=A9gration=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/connectIntegration-test.js | 83 ++++++++++++++++++++++++++++++-- 1 file changed, 80 insertions(+), 3 deletions(-) diff --git a/tests/connectIntegration-test.js b/tests/connectIntegration-test.js index c69eeaa..e51163f 100644 --- a/tests/connectIntegration-test.js +++ b/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 assert = require('assert'); @@ -6,13 +9,15 @@ var request = require('request'); var resty = require('../lib/resty'); var app = connect.createServer(); +app.use(connect.query()); +app.use(connect.bodyParser()); app.use(resty.middleware(__dirname + '/../example/resources')); -app.listen(3131); +app.listen(PORT); vows.describe('Using connect').addBatch({ 'testing Collection get request': { '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) { @@ -23,13 +28,85 @@ vows.describe('Using connect').addBatch({ 'testing Resource get request': { '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) { assert.isNull(err); 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);