summaryrefslogtreecommitdiff
path: root/node_modules/mongoose/support/expresso/test/serial/http.test.js
blob: 7783eb5d42a84790f8fe2ff6e406a7edbc270673 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
 * Module dependencies.
 */

var assert = require('assert')
  , http = require('http');

var server = http.createServer(function(req, res){
    if (req.method === 'GET') {
        if (req.url === '/delay') {
            setTimeout(function(){
                res.writeHead(200, {});
                res.end('delayed');
            }, 200);
        } else {
            var body = JSON.stringify({ name: 'tj' });
            res.writeHead(200, {
                'Content-Type': 'application/json; charset=utf8',
                'Content-Length': body.length
            });
            res.end(body);
        }
    } else {
        var body = '';
        req.setEncoding('utf8');
        req.addListener('data', function(chunk){ body += chunk });
        req.addListener('end', function(){
            res.writeHead(200, {});
            res.end(req.url + ' ' + body);
        });
    }
});

module.exports = {
    'test assert.response()': function(done){
        assert.response(server, {
            url: '/',
            method: 'GET'
        },{
            body: '{"name":"tj"}',
            status: 200,
            headers: {
                'Content-Type': 'application/json; charset=utf8'
            }
        }, done);
    }
};