// Init reqs
/* jslint node: true */
/* global describe: false */
/* global it: false */
'use strict';

var spawn   = require('child_process').spawn,
    request = require('request'),
    expect  = require('chai').expect;

// Tests

// Test for options
describe('options', function() {

  var child      = spawn('node', ['app/memcing.js', '-load-file', 'test/cmds-lf.txt', '-listen-http', ':12082', '-verbose'], {stdio: 'inherit', env: process.env}),
      restUrl    = 'http://127.0.0.1:12082',
      urlEntries = restUrl + '/entries';

  // listen-http
  describe('-listen-http', function() {
    it('should listen HTTP requests', function(done) {
      request(restUrl, function (err, res, body) {
        if(!err) {
          expect(res.statusCode).to.equal(200);
          expect(body).to.equal('');
          done();
        } else {
          done(err);
        }
      });
    });
  });

  // load-file
  describe('-load-file', function() {
    it('should load commands from the given file', function(done) {
      request(urlEntries, function (err, res, body) {
        if(!err) {
          var resData = JSON.parse(body);
          expect(res.statusCode).to.equal(200);
          expect(resData).to.be.a('array');
          expect(resData).to.have.length(3);
          expect(resData[0]).to.be.a('object');
          expect(resData[0]).to.have.property('key');
          expect(resData[0]).to.have.property('val');
          expect(resData[0]).to.have.property('ts').to.be.above(0);
          expect(resData[0]).to.have.property('expTS');
          done();
        } else {
          done(err);
        }
        child.kill();
      });
    });
  });
});
@@ -1165,32 +1165,33 @@
 .to.equal(200);%0A
+%0A
           expect
@@ -1263,16 +1263,17 @@
 gth(3);%0A
+%0A
         
@@ -1292,28 +1292,49 @@
 Data
-%5B0%5D
 ).to.
-be.a('object
+have.deep.property('%5B0%5D.key', 'hello
 ');%0A
@@ -1384,14 +1384,29 @@
 ty('
-key');
+ts').to.be.above(0);%0A
 %0A   
@@ -1418,35 +1418,32 @@
   expect(resData
-%5B0%5D
 ).to.have.proper
@@ -1428,32 +1428,37 @@
 esData).to.have.
+deep.
 property('val');
@@ -1455,11 +1455,26 @@
 ty('
-val
+%5B1%5D.key', 'counter
 ');%0A
@@ -1490,33 +1490,33 @@
  expect(resData%5B
-0
+1
 %5D).to.have.prope
@@ -1512,34 +1512,35 @@
 .have.property('
-ts
+val
 ').to.be.above(0
@@ -1532,23 +1532,91 @@
 ).to.be.
-above(0
+equal(1);%0A%0A          expect(resData).to.have.deep.property('%5B2%5D.key', 'bye'
 );%0A     
@@ -1627,33 +1627,33 @@
  expect(resData%5B
-0
+2
 %5D).to.have.prope
@@ -1664,17 +1664,52 @@
 'expTS')
-;
+.to.be.above(new Date().getTime());%0A
 %0A       

Improve testing for -load-file