Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/mocha-3.1.2/test/http-meta.spec.js')
-rw-r--r--tests/lib/mocha-3.1.2/test/http-meta.spec.js65
1 files changed, 65 insertions, 0 deletions
diff --git a/tests/lib/mocha-3.1.2/test/http-meta.spec.js b/tests/lib/mocha-3.1.2/test/http-meta.spec.js
new file mode 100644
index 0000000000..c92dbd2307
--- /dev/null
+++ b/tests/lib/mocha-3.1.2/test/http-meta.spec.js
@@ -0,0 +1,65 @@
+'use strict';
+
+var http = require('http');
+
+var PORT = 8889;
+
+var server = http.createServer(function (req, res) {
+ var accept = req.headers.accept || '';
+ var json = ~accept.indexOf('json');
+
+ switch (req.url) {
+ case '/':
+ res.end('hello');
+ break;
+ case '/users':
+ if (json) {
+ res.end('["tobi","loki","jane"]');
+ } else {
+ res.end('tobi, loki, jane');
+ }
+ break;
+ }
+});
+
+function get (url, body, header) {
+ return function (done) {
+ http.get({
+ path: url,
+ port: PORT,
+ headers: header || {}
+ }, function (res) {
+ var buf = '';
+ res.should.have.property('statusCode', 200);
+ res.setEncoding('utf8');
+ res.on('data', function (chunk) { buf += chunk; });
+ res.on('end', function () {
+ buf.should.equal(body);
+ done();
+ });
+ });
+ };
+}
+
+describe('http requests', function () {
+ before(function (done) {
+ server.listen(PORT, done);
+ });
+
+ after(function () {
+ server.close();
+ });
+
+ describe('GET /', function () {
+ it('should respond with hello',
+ get('/', 'hello'));
+ });
+
+ describe('GET /users', function () {
+ it('should respond with users',
+ get('/users', 'tobi, loki, jane'));
+
+ it('should respond with users',
+ get('/users', '["tobi","loki","jane"]', { Accept: 'application/json' }));
+ });
+});