'use strict';

var http = require('http');

var assert = require('assertive');

var fetch = require('../lib/fetch');

describe('fetch', function() {
  var server;

  before('start echo server', function(done) {
    server = http.createServer(function(req, res) {
      res.writeHead(200, {
        'Content-Type': 'application/json',
      });
      res.end(JSON.stringify({
        method: req.method,
        url: req.url,
        headers: req.headers,
      }));
    });
    server.on('error', done);
    server.listen(3000, function() { done(); });
  });

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

  it('can fetch stuff', function() {
    var headers = { 'x-Fancy': 'stuff' };
    headers['X-Fancy'] = 'other stuff';
    return fetch('http://localhost:3000/foo', { headers: headers })
      .json()
      .then(function(echo) {
        assert.equal('GET', echo.method);
        assert.equal('/foo', echo.url);
        assert.equal('overriding headers works thanks to key ordering',
          'other stuff', echo.headers['x-fancy']);
      });
  });
});

@@ -252,24 +252,159 @@
 req, res) %7B%0A
+      var chunks = %5B%5D;%0A      req.on('data', function(chunk) %7B%0A        chunks.push(chunk);%0A      %7D);%0A      req.on('end', function() %7B%0A  
       res.wr
@@ -418,16 +418,18 @@
 (200, %7B%0A
+  
         
@@ -466,28 +466,32 @@
 son',%0A      
+  
 %7D);%0A
+  
       res.en
@@ -509,16 +509,18 @@
 ngify(%7B%0A
+  
         
@@ -547,16 +547,18 @@
         
+  
 url: req
@@ -563,16 +563,18 @@
 eq.url,%0A
+  
         
@@ -601,18 +601,79 @@
 ,%0A      
+    body: Buffer.concat(chunks).toString()%0A        %7D));%0A      
 %7D
-)
 );%0A    %7D
@@ -1150,16 +1150,53 @@
 o.url);%0A
+        assert.equal('', echo.body);%0A
         

Add test for empty body