<commit_before>'use strict';

var auth = require('./auth.json');
var sinon = require('sinon');
var expect = require('chai').expect;
var should = require('chai').should();
var request = require('request');

describe('SAP module', function () {
  var sap;

  function initModule(auth) {
    sap = require('../index')(auth);
  }

  beforeEach(function () {
    sap = undefined;
    initModule(auth);
  });

  describe('initialization', function () {
    var error;

    beforeEach(function () {
      error = sinon.stub(console, 'error');
    });

    afterEach(function () {
      error.restore();
    });

    it('sets auth options', sinon.test(function () {
      should.exist(sap.client_id);
      should.exist(sap.client_secret);
      should.exist(sap.refresh_token);
    }));

    describe('when no options are passed', function () {
      it('logs an error to the console', function () {
        sap = undefined;
        initModule();

        sinon.assert.calledOnce(error);
      });
    });

    describe('when insufficient options are passed', function () {
      it('logs an error to the console', function () {
        sap = undefined;
        initModule({ client_id: 'foo', client_secret: 'bar' });

        sinon.assert.calledOnce(error);
      });
    });
  });

  describe('getAccessToken', function() {
    var postRequest;

    beforeEach(function () {
      postRequest = sinon.stub(request, 'post');
    });

    afterEach(function () {
      postRequest.restore();
    });

    it('sends a POST request', function() {
      sap.getAccessToken();

      sinon.assert.calledOnce(postRequest);
    });
  });
});<commit_msg>Refactor unit test to use `sinon.test` for automatic cleanup<commit_after>'use strict';

var auth = require('./auth.json');
var sinon = require('sinon');
var expect = require('chai').expect;
var should = require('chai').should();
var request = require('request');

describe('SAP module', function () {
  var sap;

  function initModule(auth) {
    sap = require('../index')(auth);
  }

  beforeEach(function () {
    sap = undefined;
    initModule(auth);
  });

  describe('initialization', function () {
    var error;

    beforeEach(function () {
      error = sinon.stub(console, 'error');
    });

    afterEach(function () {
      error.restore();
    });

    it('sets auth options', function () {
      should.exist(sap.client_id);
      should.exist(sap.client_secret);
      should.exist(sap.refresh_token);
    });

    describe('when no options are passed', function () {
      it('logs an error to the console', function () {
        sap = undefined;
        initModule();

        sinon.assert.calledOnce(error);
      });
    });

    describe('when insufficient options are passed', function () {
      it('logs an error to the console', function () {
        sap = undefined;
        initModule({ client_id: 'foo', client_secret: 'bar' });

        sinon.assert.calledOnce(error);
      });
    });
  });

  describe('getAccessToken', function() {
    it('sends a POST request', sinon.test(function() {
      var postRequest = this.stub(request, 'post');
      sap.getAccessToken();

      sinon.assert.calledOnce(postRequest);
    }));
  });
});
{'fraction_non_alphanumeric': 0.1641697877652934, 'fraction_numerical': 0.0, 'mean_word_length': 2.8990267639902676, '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': '1254960', 'n_tokens_mistral': 955, 'n_tokens_neox': 943, 'n_words': 208}