<commit_before>var CountdownManager = require('../code/lib/countdownManager');
var moment = require('moment');
var Moment = moment().constructor;
var sinon = require('sinon');

describe('Countdown Manager', function() {

  var timer = null;
  var countdownManager = null;
  var callbackSpy = null;

  before(function() {
    timer = sinon.useFakeTimers();
  });

  beforeEach(function() {
    countdownManager = new CountdownManager('2016-07-27');
    callbackSpy = sinon.spy();
  });

  after(function() {
    timer.restore();
  });

  describe('start', function () {

    beforeEach(function () {
      countdownManager.start(callbackSpy);
      timer.tick(CountdownManager.countdownInterval);
    });

    it('sets interval countdown', function () {
      assert.ok(callbackSpy.called);
    });

  });

  describe('stop', function () {

    beforeEach(function () {
      countdownManager.stop(callbackSpy);
      timer.tick(CountdownManager.countdownInterval);
    });

    it('clears interval countdown', function() {
      assert.equal(callbackSpy.called, false);
    });

    it('returns an instance of moment', function() {
      assert.ok(countdownManager.stop() instanceof Moment);
    });

  });

  describe('intervalCounter', function () {
    beforeEach(function () {

    });
  });

  describe('countdownDate', function () {

  });

  describe('time', function () {

  });

  // it('.start sets interval countdown', function() {
  //   this.CountdownManager.start(this.callback);
  //   this.timer.tick(CountdownManager.countdownInterval);
  //   assert.equal(this.callback.called, true);
  // });

  // it('.stop clears interval countdown and returns moment', function() {
  //   this.CountdownManager.start(this.callback);
  //   var stopMoment = this.CountdownManager.stop();
  //   this.timer.tick(CountdownManager.countdownInterval);
  //   assert.ok(stopMoment instanceof Moment);
  //   assert.equal(this.callback.called, false);
  // });

});<commit_msg>updated tests, to cover all functions<commit_after>var CountdownManager = require('../code/lib/countdownManager');
var countdown = require('../code/lib/countdown');
var moment = require('moment');
var Moment = moment().constructor;
var sinon = require('sinon');

describe('Countdown Manager', function() {

  var timer = null;
  var date = null;
  var countdownManager = null;
  var callbackSpy = null;

  before(function() {
    timer = sinon.useFakeTimers();
  });

  beforeEach(function() {
    date = {
      startDate: '2016-07-27'
    };
    countdownManager = new CountdownManager(date);
    callbackSpy = sinon.spy();
  });

  after(function() {
    timer.restore();
  });

  describe('start', function () {

    beforeEach(function () {
      countdownManager.start(callbackSpy);
      timer.tick(CountdownManager.countdownInterval);
    });

    it('sets interval countdown', function () {
      assert.ok(callbackSpy.called);
    });

  });

  describe('stop', function () {

    beforeEach(function () {
      countdownManager.stop(callbackSpy);
      timer.tick(CountdownManager.countdownInterval);
    });

    it('clears interval countdown', function() {
      assert.equal(callbackSpy.called, false);
    });

    it('returns an instance of moment', function() {
      assert.ok(countdownManager.stop() instanceof Moment);
    });

  });

  describe('intervalCounter', function () {

    var intervalFunction = null;
    var timeStub = null;

    beforeEach(function () {
      timeStub = sinon.stub(countdownManager, 'time').returns('test');
      intervalFunction = countdownManager.intervalCounter(callbackSpy);
      intervalFunction();
    });

    it('returns a callback', function() {
      assert.ok(callbackSpy.called);
    });

    it('the callback passes through the value of the time function', function() {
      assert.ok(callbackSpy.calledWith('test'));
    });

  });

  describe('countdownDate', function () {

    describe('when a callback is provided', function () {

      beforeEach(function () {
        countdownManager.countdownDate(callbackSpy);
      });

      it('calls back with startDate', function() {
        assert.ok(callbackSpy.calledWith(date.startDate));
      });

    });

    describe('when no callback is provided', function () {

      var result = null;

      beforeEach(function () {
        result = countdownManager.countdownDate();
      });

      it('returns startDate', function() {
        assert.equal(result, date.startDate);
      });

    });

  });

  describe('time', function () {

      var countdownUntilStub = null;
      var countdownDateValue = null;
      var currentMoment = null;

      beforeEach(function() {
        countdownUntilStub = sinon.stub(countdown, 'until');
        sinon.stub(countdownManager, 'countdownDate').returns(countdownDateValue);

        currentMoment = 'test';
        countdownManager.time(currentMoment);
      });

      it('calls countdown until with countdownDate & currentMoment', function () {
        assert.ok(countdownUntilStub.calledWith(countdownDateValue, currentMoment));
      });
  });

});
{'fraction_non_alphanumeric': 0.14984289080911234, 'fraction_numerical': 0.003142183817753339, 'mean_word_length': 3.287037037037037, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6270036', 'n_tokens_mistral': 1511, 'n_tokens_neox': 1447, 'n_words': 272}