var assert = require('chai').assert;
var HttpServer = require('../../lib/http-server');
var sinon = require('sinon');
var Promise = require('bluebird');

describe('Http Server alone', function() {
  it('is created properly and starts', function(done) {
    var serviceLocator = require('../../lib/service-locator.js');

    var logger = {
      debug: function() {
      }
    };

    var loggerSpy = sinon.spy(logger, 'debug');
    serviceLocator.register('logger', function() {
      return logger;
    });

    var port = 8811;
    var apiKey = 'fooKey';

    var httpServer = new HttpServer(port, apiKey);

    assert.instanceOf(httpServer, HttpServer);
    assert.strictEqual(httpServer.port, port);
    assert.strictEqual(httpServer.apiKey, apiKey);

    httpServer.start().then(function() {
      assert.isTrue(loggerSpy.calledOnce);
      done();
    });
  });

  it('fails without apiKey', function() {
    assert.throw(function() {
      new HttpServer(8811);
    }, /apiKey is not defined/);
  });

});

@@ -145,16 +145,127 @@
 ebird');
+%0Avar serviceLocator = require('../../lib/service-locator.js');%0Avar requestPromise = require('request-promise');
 %0A%0Adescri
@@ -283,14 +283,8 @@
 rver
- alone
 ', f
@@ -301,127 +301,327 @@
 %7B%0A  
-it('is created properly and starts', function(done) %7B%0A    var serviceLocator = require('../../lib/service-locator.js');
+var port = 8811;%0A  var apiKey = 'fooKey';%0A%0A  function getOptions(path, apiKey, data) %7B%0A    return %7B%0A      method: 'POST',%0A      uri: 'http://localhost:' + '8811' + '/' + path,%0A      params: data,%0A      headers: %7B'Server-Key': apiKey%7D,%0A      json: true%0A    %7D;%0A  %7D%0A%0A  it('is created properly and starts', function(done) %7B
 %0A%0A  
@@ -812,57 +812,8 @@
 );%0A%0A
-    var port = 8811;%0A    var apiKey = 'fooKey';%0A%0A
     
@@ -1098,15 +1098,400 @@
     
-  done(
+%7D).then(function() %7B%0A      var requests = %5B%5D;%0A%0A      requests%5B'authFail'%5D = requestPromise(getOptions('stopStream', 'wrongKey', %7B%7D)).catch(function(err) %7B%0A        assert.instanceOf(err, Error);%0A        assert.strictEqual(err%5B'statusCode'%5D, 403);%0A      %7D);%0A%0A      Promise.all(requests).finally(function() %7B%0A        done();%0A      %7D);%0A    %7D).catch(function() %7B%0A      assert.fail(actual, expected
 );%0A 
@@ -1643,13 +1643,12 @@
 ;%0A  %7D);%0A
-%0A
 %7D);%0A

add test for auth failures