Comparing version 0.0.3 to 0.0.4
@@ -88,1 +88,26 @@ "use strict"; | ||
exports.delay = function (req, res) { | ||
var delay = parseInt(req.url.split('/').pop(), 10), | ||
seconds = (delay * 1000); | ||
setTimeout(function () { | ||
res.writeHead(200, headers); | ||
res.end('waited for ' + delay + ' seconds'); | ||
}, seconds); | ||
}; | ||
exports.json = function (req, res) { | ||
var p = parse(req.url), | ||
json = (p.query ? JSON.stringify(qs.parse(p.query)) : '{ "echo": true }'); | ||
if (req.body) { | ||
json = JSON.stringify(req.body); | ||
} | ||
res.writeHead(200, { | ||
'Content-type': 'application/json' | ||
}); | ||
res.end(json); | ||
}; |
@@ -5,3 +5,3 @@ { | ||
"author": "Dav Glass <davglass@gmail.com>", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"dependencies": { | ||
@@ -8,0 +8,0 @@ }, |
@@ -29,2 +29,4 @@ EchoEcho | ||
* `status` - Special status route `echo/status/403` returns a `403`, all `http.STATUS_CODES` supported | ||
* `delay` - Special delay route `echo/delay/2` returns a 200 delayed by 2 seconds. | ||
* `json` - Send query parameters or POST parameters and get them back as JSON | ||
@@ -31,0 +33,0 @@ Using in Your Server |
var vows = require('vows'), | ||
assert = require('assert'), | ||
http = require('http'), | ||
parse = require('url').parse, | ||
qs = require('querystring'); | ||
echoecho = require('../lib/echo'); | ||
@@ -241,2 +243,78 @@ | ||
} | ||
}, | ||
"and get default json": { | ||
topic: function() { | ||
fetch({ | ||
method: 'GET', | ||
path: '/foo/bar/baz/echo/json' | ||
}, this.callback); | ||
}, | ||
"with query body": function(topic) { | ||
assert.equal(topic.code, 200); | ||
assert.equal(topic.body, '{ "echo": true }'); | ||
} | ||
}, | ||
"and post default json": { | ||
topic: function() { | ||
fetch({ | ||
method: 'POST', | ||
path: '/foo/bar/baz/echo/json' | ||
}, this.callback); | ||
}, | ||
"with query body": function(topic) { | ||
assert.equal(topic.code, 200); | ||
assert.equal(topic.body, '{ "echo": true }'); | ||
} | ||
}, | ||
"and get custom json": { | ||
topic: function() { | ||
var self = this, | ||
url = '/foo/bar/baz/echo/json?foo=bar&baz=world'; | ||
fetch({ | ||
method: 'GET', | ||
path: url | ||
}, function(err, data) { | ||
var q = parse(url); | ||
data.expected = JSON.stringify(qs.parse(q.query)); | ||
self.callback(err, data); | ||
}); | ||
}, | ||
"with query body": function(topic) { | ||
assert.equal(topic.code, 200); | ||
assert.equal(topic.headers['content-type'], 'application/json'); | ||
assert.equal(topic.body, topic.expected); | ||
} | ||
}, | ||
"and post custom json": { | ||
topic: function() { | ||
var self = this, | ||
url = '/foo/bar/baz/echo/json?foo=bar&baz=world&do=not'; | ||
fetch({ | ||
method: 'POST', | ||
path: url | ||
}, function(err, data) { | ||
var q = parse(url); | ||
data.expected = JSON.stringify(qs.parse(q.query)); | ||
self.callback(err, data); | ||
}); | ||
}, | ||
"with query body": function(topic) { | ||
assert.equal(topic.code, 200); | ||
assert.equal(topic.headers['content-type'], 'application/json'); | ||
assert.equal(topic.body, topic.expected); | ||
} | ||
}, | ||
"and delay 3 seconds": { | ||
topic: function() { | ||
fetch({ | ||
method: 'GET', | ||
path: '/foo/bar/baz/echo/delay/3' | ||
}, this.callback); | ||
}, | ||
"with query body": function(topic) { | ||
assert.equal(topic.code, 200); | ||
assert.equal(topic.body, 'waited for 3 seconds'); | ||
} | ||
} | ||
@@ -243,0 +321,0 @@ } |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18776
461
92
18