
var Client = require('../index').Client;
var Transport = require('./mock/Transport');
var OutgoingFrameStream = require('./mock/OutgoingFrameStream');
var assert = require('assert');

describe('Client.connect', function() {

  var client, transport, framesOut, framesIn;

  beforeEach(function() {

    transport = new Transport();
    framesOut = new OutgoingFrameStream();

    client = new Client(transport, {
      outgoingFrameStream: framesOut
    });
  });

  it('should send a CONNECT frame and include accept-version header', function(done) {

    client.connect();

    assert(framesOut._frames[0]);

    var frame = framesOut._frames[0];

    assert.equal(frame.command, 'CONNECT');
    assert('accept-version' in frame.headers);

    assert.equal(frame._finished, true);
    assert.equal(frame._body.length, 0);
    
    done();
  });

  it('should parse the heart-beat header and call setHeartbeat', function(done) {

    client.connect({
      'heart-beat': '1,2'
    });

    var heartbeat = client.getHeartbeat();

    assert.equal(heartbeat[0], 1);
    assert.equal(heartbeat[1], 2);

    assert.equal(framesOut._frames[0].headers['heart-beat'], '1,2');

    done();
  });
});


var Client = require('../index').Client;
var Transport = require('./mock/Transport');
var OutgoingFrameStream = require('./mock/OutgoingFrameStream');
var assert = require('assert');

describe('Client.connect', function() {

  var client, transport, framesOut, framesIn;

  beforeEach(function() {

    transport = new Transport();
    framesOut = new OutgoingFrameStream();

    client = new Client(transport, {
      outgoingFrameStream: framesOut
    });
  });

  it('should send a CONNECT frame and include accept-version header', function(done) {

    client.connect();

    assert(framesOut._frames[0]);

    var frame = framesOut._frames[0];

    assert.equal(frame.command, 'CONNECT');
    assert('accept-version' in frame.headers);

    assert.equal(frame._finished, true);
    assert.equal(frame._body.length, 0);
    
    done();
  });

});

--- 
+++ 
@@ -35,4 +35,19 @@
     done();
   });
 
+  it('should parse the heart-beat header and call setHeartbeat', function(done) {
+
+    client.connect({
+      'heart-beat': '1,2'
+    });
+
+    var heartbeat = client.getHeartbeat();
+
+    assert.equal(heartbeat[0], 1);
+    assert.equal(heartbeat[1], 2);
+
+    assert.equal(framesOut._frames[0].headers['heart-beat'], '1,2');
+
+    done();
+  });
 });
Test for heart-beat header handling
