<commit_before>/* eslint-disable no-unused-expressions */
/* global describe, it, before, after, beforeEach, afterEach */

const axios = require('axios');
const moxios = require('moxios'); // axios requests mocking

const sinon = require('sinon');
const chai = require('chai');
const sinonChai = require('sinon-chai');
const expect = chai.expect;
chai.use(sinonChai);

const rocketLaunch = require('../lib/modules/rocketLaunch');
const helpers = require('../lib/helpers');

const nextResponse = require('./mockData.js');

describe('Rocket launch', function () {
  let sandbox;

  beforeEach(function () {
    moxios.install();

    moxios.stubRequest('https://launchlibrary.net/1.2/launch/next/1', {
      status: 200,
      responseText: nextResponse.nextSingleResponse
    });

    moxios.stubRequest('https://launchlibrary.net/1.2/launch/next/5', {
      status: 200,
      responseText: nextResponse.nextMultiResponse
    });

    sandbox = sinon.sandbox.create();
    sandbox.stub(helpers, 'printMessage');
    sandbox.stub(helpers, 'printError');
  });

  afterEach(function () {
    moxios.uninstall();

    sandbox.restore();
  });

  describe('nextLaunch', function () {
    it('should call printMessage once', function (done) {
      rocketLaunch.nextLaunch({});

      moxios.wait(function () {
        expect(helpers.printMessage).to.be.calledOnce;
        done();
      });
    });

    it('should call printMessage once in details mode', function (done) {
      rocketLaunch.nextLaunch({
        details: true
      });

      moxios.wait(function () {
        expect(helpers.printMessage).to.be.calledOnce;
        done();
      });
    });

    it('should call printMessage twice with time conversion error', function (done) {
      sandbox.stub(helpers, 'convertTimezone').yields('Unrecognised time zone.');

      rocketLaunch.nextLaunch({
        timezone: 'wrongTimezone'
      });

      moxios.wait(function () {
        expect(helpers.printMessage).to.be.calledTwice;
        done();
      });
    });

    it('should call printMessage once for each launch', function (done) {
      let launchCount = 5;
      rocketLaunch.nextLaunch({
        limit: launchCount
      });

      moxios.wait(function () {
        expect(helpers.printMessage).to.be.callCount(launchCount);
        done();
      });
    });

    it('should call printError once on request failure', function (done) {
      moxios.stubRequest('https://launchlibrary.net/1.2/launch/next/10', {
        status: 403,
        responseText: {
          'status': 'fail',
          'msg': 'Error message'
        }
      });

      let launchCount = 10;
      rocketLaunch.nextLaunch({
        limit: launchCount
      });

      moxios.wait(function () {
        expect(helpers.printError).to.be.calledOnce;
        done();
      });
    });
  });
});
<commit_msg>Update time conversion error test<commit_after>/* eslint-disable no-unused-expressions */
/* global describe, it, before, after, beforeEach, afterEach */

const axios = require('axios');
const moxios = require('moxios'); // axios requests mocking

const sinon = require('sinon');
const chai = require('chai');
const sinonChai = require('sinon-chai');
const expect = chai.expect;
chai.use(sinonChai);

const rocketLaunch = require('../lib/modules/rocketLaunch');
const helpers = require('../lib/helpers');

const nextResponse = require('./mockData.js');

describe('Rocket launch', function () {
  let sandbox;

  beforeEach(function () {
    moxios.install();

    moxios.stubRequest('https://launchlibrary.net/1.2/launch/next/1', {
      status: 200,
      responseText: nextResponse.nextSingleResponse
    });

    moxios.stubRequest('https://launchlibrary.net/1.2/launch/next/5', {
      status: 200,
      responseText: nextResponse.nextMultiResponse
    });

    sandbox = sinon.sandbox.create();
    sandbox.stub(helpers, 'printMessage');
    sandbox.stub(helpers, 'printError');
  });

  afterEach(function () {
    moxios.uninstall();

    sandbox.restore();
  });

  describe('nextLaunch', function () {
    it('should call printMessage once', function (done) {
      rocketLaunch.nextLaunch({});

      moxios.wait(function () {
        expect(helpers.printMessage).to.be.calledOnce;
        done();
      });
    });

    it('should call printMessage once in details mode', function (done) {
      rocketLaunch.nextLaunch({
        details: true
      });

      moxios.wait(function () {
        expect(helpers.printMessage).to.be.calledOnce;
        done();
      });
    });

    it('should call printMessage once and printError with time conversion error once', function (done) {
      sandbox.stub(helpers, 'convertTimezone').yields('Unrecognised time zone.');

      rocketLaunch.nextLaunch({
        timezone: 'wrongTimezone'
      });

      moxios.wait(function () {
        expect(helpers.printError).to.be.calledOncee;
        expect(helpers.printMessage).to.be.calledOnce;
        done();
      });
    });

    it('should call printMessage once for each launch', function (done) {
      let launchCount = 5;
      rocketLaunch.nextLaunch({
        limit: launchCount
      });

      moxios.wait(function () {
        expect(helpers.printMessage).to.be.callCount(launchCount);
        done();
      });
    });

    it('should call printError once on request failure', function (done) {
      moxios.stubRequest('https://launchlibrary.net/1.2/launch/next/10', {
        status: 403,
        responseText: {
          'status': 'fail',
          'msg': 'Error message'
        }
      });

      let launchCount = 10;
      rocketLaunch.nextLaunch({
        limit: launchCount
      });

      moxios.wait(function () {
        expect(helpers.printError).to.be.calledOnce;
        done();
      });
    });
  });
});

{'fraction_non_alphanumeric': 0.14949879018320084, 'fraction_numerical': 0.0076045627376425855, 'mean_word_length': 2.7651268705270007, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 6, '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': '3484152', 'n_tokens_mistral': 1789, 'n_tokens_neox': 1737, 'n_words': 326}