/*
  Tests for shopping cart.
  Invoke npm run test
*/
var cart = require('./cart.node.js'),
  should = require('should'),
  AsciiTable = require('ascii-table');

function emit(msg) {
  var message = msg.toString();
  if(message.indexOf(',') != -1) {
      var a_message = message.split(',');
      var table = new AsciiTable();
      table.setHeading('Item', 'Price', 'Qty');
      for(var i = 0; i < a_message.length; i++) {
          var col = a_message[i].split('|');
          table.addRow(col[0], col[1], col[2]);
      }
      message = table.toString();
  }
  else message = '\t' + message;
  console.log(message);
}

describe('Configure cart:', function() {
  it('Configure as \'Cart\' with no force cookies, bootstrap + striped and alerts', function() {
      cart.configure(null, false, '$', true, true, true);
  });
});

describe('Render the cart:', function() {
  it('Should be called \'Cart\' and have 0 items in it.', function() {
      emit(cart.renderCart());
      cart.renderCart().should.equal('Cart => 0');
  });
});

describe('Add items to cart:', function() {
  it('Add 2x Super Soda @ $ 0.85 to cart', function() {
      for(var i = 0; i < 2; i++) cart.addItem(1);
  });
  it('Add 1x Dakota Cola @ $ 0.70 to cart', function() {
      cart.addItem(2);
  });
  it('Add 7x Soda Water (250ml) @ $ 1.50 to cart', function() {
      for(var i = 0; i < 7; i++) cart.addItem(3);
  });
});

describe('Check items in cart', function() {
  it('There should now be 10 items in the cart', function() {
      emit(cart.renderItems());
      cart.getNumberItems().should.equal(10);
  });
});

describe('Add more items to cart:', function() {
  it('Add 1x Super Soda to cart (via changeQty)', function() {
      cart.changeQty(0, true);
  });
});

describe('Recheck items in cart', function() {
  it('There should now be 11 items in the cart', function() {
      cart.getNumberItems().should.equal(11);
      emit(cart.renderItems());
  });
});

describe('Remove items from cart:', function() {

});

@@ -177,16 +177,104 @@
 (msg) %7B%0A
+  var table = new AsciiTable();%0A  table.setHeading('Item', 'Price', 'Qty', '', '', '');%0A
   var me
@@ -384,82 +384,156 @@
     
-var table = new AsciiTable();%0A      table.setHeading('Item', 'Price
+for(var i = 0; i %3C a_message.length; i++) %7B%0A          var col = a_message%5Bi%5D.split('%7C');%0A          table.addRow(col%5B0%5D, col%5B1%5D, col%5B2%5D, 'X', '+
 ', '
-Qty
+-
 ');%0A
@@ -542,58 +542,88 @@
     
-for(var i = 0; i %3C a_message.length; i++) %7B%0A      
+%7D%0A      message = table.toString();%0A  %7D%0A  else if(message.indexOf('%7C') != -1) %7B%0A
     
@@ -628,36 +628,31 @@
   var col = 
-a_
 message
-%5Bi%5D
 .split('%7C');
@@ -644,38 +644,32 @@
 age.split('%7C');%0A
-      
     table.addRow
@@ -691,29 +691,34 @@
 , col%5B2%5D
-);%0A      %7D%0A  
+, 'X', '+', '-');%0A
     mess
@@ -878,61 +878,38 @@
 t%5C' 
-with no force cookies, bootstrap + striped and alerts
+using cookie and $ as currency
 ', f
@@ -951,36 +951,17 @@
 ll, 
-fals
+tru
 e, '$'
-, true, true, true
 );%0A 
@@ -2140,13 +2140,540 @@
 ion() %7B%0A
+  it('Remove 3x Super Soda from cart; should have 8 items now', function() %7B%0A    for(var i = 0; i %3C 3; i++) cart.changeQty(0, false);%0A    cart.getNumberItems().should.equal(8);%0A    emit(cart.renderItems());%0A  %7D);%0A%0A  it('Remove any Soda Waters from cart; should have 1 item now', function() %7B%0A    cart.removeItem(1);%0A    cart.getNumberItems().should.equal(1);%0A    emit(cart.renderItems());%0A  %7D);%0A%0A  it('Empty the cart; should have 0 items now', function() %7B%0A    cart.empty(true);%0A    cart.getNumberItems().should.equal(0);%0A  %7D);
 %0A%7D);%0A

Update tests.