'use strict';

var chalk = require('chalk');
var chai = require('chai');
var sinonChai = require('sinon-chai');
var optDate = require('./optDate');
var sinon = require('sinon');

var expect = chai.expect;
chai.use(sinonChai);

var consoleStub = void 0;

describe('optDate', function () {
  beforeEach(function () {
    consoleStub = sinon.stub(console, 'log');
  });
  afterEach(function () {
    console.log.restore();
  });
  it('Should add 2 days', function (done) {
    var date = '2017-05-01';
    var sDate = '(Mon) 2017-05-01';
    var sNewDate = '(Wed) 2017-05-03';
    optDate(2, {
      date: date
    });
    setTimeout(function () {
      expect(consoleStub).to.have.been.calledWith('\nInformed date: ' + chalk.yellow(sDate));
      expect(consoleStub).to.have.been.calledWith('Calculated Date: ' + chalk.yellow(sNewDate));
      done();
    }, 300);
  });
  it('Should add 4 months', function (done) {
    var date = '2017-05-01';
    var sDate = '(Mon) 2017-05-01';
    var sNewDate = '(Fri) 2017-09-01';
    optDate(4, {
      date: date,
      period: 'M'
    });
    setTimeout(function () {
      expect(consoleStub).to.have.been.calledWith('\nInformed date: ' + chalk.yellow(sDate));
      expect(consoleStub).to.have.been.calledWith('Calculated Date: ' + chalk.yellow(sNewDate));
      done();
    }, 300);
  });
  it('Should subtract 35 days', function (done) {
    var date = '2017-05-01';
    var sDate = '(Mon) 2017-05-01';
    var sNewDate = '(Mon) 2017-03-27';
    optDate(35, {
      date: date,
      subtract: true
    });
    setTimeout(function () {
      expect(consoleStub).to.have.been.calledWith('\nInformed date: ' + chalk.yellow(sDate));
      expect(consoleStub).to.have.been.calledWith('Calculated Date: ' + chalk.yellow(sNewDate));
      done();
    }, 300);
  });
});