Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Completed connect intégration tests

  • Loading branch information...
commit f603573910e46c4af1f400433d02a59a6ffba120 1 parent 6af526d
@angelini authored
Showing with 80 additions and 3 deletions.
  1. +80 −3 tests/connectIntegration-test.js
View
83 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);
Please sign in to comment.
Something went wrong with that request. Please try again.