Skip to content

Commit

Permalink
Cleanup tests for middleware and replaced express dev dependency with…
Browse files Browse the repository at this point in the history
… connect
  • Loading branch information
tedeh committed Jun 10, 2012
1 parent e669cac commit c1a7aed
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 80 deletions.
25 changes: 15 additions & 10 deletions lib/server/middleware.js
Expand Up @@ -16,17 +16,22 @@ var JaysonMiddleware = module.exports = function(server, options) {
server.call(req.body, function(error, success) {
var response = error || success;

var body = '';
// stringifies JSON
try { body = JSON.stringify(response, options.replacer); } catch(err) { return next(err); }

var headers = {
"content-length": Buffer.byteLength(body, options.encoding),
"content-type": "application/json"
};
res.writeHead(200, headers);
res.write(body);
res.end();
try { var body = JSON.stringify(response, options.replacer); } catch(err) { return next(err); }

// empty response?
if(body) {
var headers = {
"content-length": Buffer.byteLength(body, options.encoding),
"content-type": "application/json"
};
res.writeHead(200, headers);
res.write(body);
res.end();
} else {
res.writeHead(204);
res.end();
}
});

// ends the request with an error code
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -23,7 +23,7 @@
"devDependencies": {
"should": "*",
"mocha": "*",
"express": "*",
"connect": "*",
"uglify-js": "*"
}
}
File renamed without changes.
37 changes: 37 additions & 0 deletions test/middleware.server-client.test.js
@@ -0,0 +1,37 @@
var should = require('should');
var support = require('./support/client-server');
var jayson = require(__dirname + '/..');
var connect = require('connect');

describe('jayson middleware', function() {

var server;
var stack = connect.createServer();
stack.use(connect.json({reviver: support.options.reviver}));
stack.use(jayson.server(support.methods, support.options).middleware());

var client = jayson.client.http({
reviver: support.options.reviver,
replacer: support.options.replacer,
host: 'localhost',
port: 3000
});

before(function(done) { server = stack.listen(3000, done); });

it('should be able to receive a success-method from a client', support.clientRequest(client));

it('should be able to receive an error-method from a client', support.clientError(client));

it('should support reviving and replacing', support.clientReviveReplace(client));

it('should be able to handle a notification', support.clientNotification(client));

it('should be able to handle a batch request', support.clientBatch(client));

after(function(done) {
server.once('close', done);
server.close();
})

});
69 changes: 0 additions & 69 deletions test/middleware.test.js

This file was deleted.

0 comments on commit c1a7aed

Please sign in to comment.