diff --git a/test/messenger.js b/test/messenger.js index d14a7efc..e4fc45a8 100644 --- a/test/messenger.js +++ b/test/messenger.js @@ -1,42 +1,100 @@ "use strict"; +var http = require("http"); var vows = require("vows"); var assert = require("assert"); var pact = require("pact"); -var yeti = require("../lib/yeti"); +var Hub = require("../lib/hub"); vows.describe("Yeti Hub HTTP errors").addBatch({ "Hub setup and connection" : { - topic : pact.httpify(yeti.createHub()), + topic : function () { + var vow = this, + hub = new Hub(); + hub.listen(function () { + vow.callback(null, hub); + }); + }, + teardown: function (hub) { + hub.close(); + }, "when a non-GET or HEAD request is used" : { - topic : pact.request({ - url : "http://localhost:9000", - method : "PUT" - }), - "should return a 405 error" : pact.code(405), + topic : function (hub) { + var vow = this; + var req = http.request({ + host : hub.server.address().address, + port : hub.server.address().port, + method : "PUT" + }); + req.on("response", function (res) { + res.setEncoding("utf8"); + res.on("data", function (chunk) { + vow.callback(null, { + body : chunk, + status : res.statusCode, + headers : res.headers + }); + }); + }); + req.end(); + }, + "should return a 405 error" : function (topic) { + assert.equal(topic.status, 405); + }, "should return the proper error message" : function (topic) { assert.equal(topic.body, "Method Not Allowed\n" + "GET or HEAD method required."); } }, "when the desired route is not found" : { - topic : pact.request({ - url : "http://localhost:9000/foobar" - }), - "should return a 404 error" : pact.code(404), + topic : function (hub) { + var vow = this; + var req = http.request({ + host : hub.server.address().address, + port : hub.server.address().port, + path : "/foobar", + method : "GET" + }); + req.on("response", function (res) { + res.setEncoding("utf8"); + res.on("data", function (chunk) { + vow.callback(null, { + body : chunk, + status : res.statusCode, + headers : res.headers + }); + }); + }); + req.end(); + }, + "should return a 404 error" : function (topic) { + assert.equal(topic.status, 404); + }, "should return the proper error message" : function (topic) { - assert.equal(topic.body, "Not Found\n" + + assert.equal(topic.body, "Not Found\n" + "Unable to find what you're looking for."); } }, "when a HEAD request is not found" : { - topic : pact.request({ - url : "http://localhost:9000/foobar", - method : "HEAD" - }), - "should end with no message" : function (topic) { - assert.equal(topic.body, ""); + topic : function (hub) { + var vow = this; + var req = http.request({ + host : hub.server.address().address, + port : hub.server.address().port, + path : "/foobar", + method : "HEAD" + }); + req.on("response", function (res) { + vow.callback(null, { + status : res.statusCode, + headers : res.headers + }); + }); + req.end(); + }, + "should return a 404 error" : function (topic) { + assert.equal(topic.status, 404); } } }