<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//suppress stdout when running unit tests
process.env.NODE_ENV = 'test';

var chai = require('chai');
var fs = require('fs');
var MaxmindDbDownloader = require('../lib/maxmind-db-downloader');
var path = require('path');
var Promise = require('bluebird');
var rimraf = require('rimraf');
var sinon = require('sinon');
var assert = chai.assert;

describe('maxmind-db-downloader', function () {
  'use strict';
  var maxmindDbDownloader;
  var targetDirPath;
  var downloadPromiseFunctions;

  beforeEach(function () {
    maxmindDbDownloader = new MaxmindDbDownloader();
  });

  afterEach(function () {
    downloadPromiseFunctions = null;
    // cleanup, remove the created directory
    var expectedTargetDirPath = path.join(__dirname, '..', 'test-db');
    if (targetDirPath === expectedTargetDirPath && fs.statSync(targetDirPath).isDirectory()) {
      rimraf.sync(targetDirPath);
    }
    targetDirPath = '';
  });

  describe('createTargetDir', function () {
    it('creates the specified directory', function () {
      targetDirPath = maxmindDbDownloader.createTargetDir('test-db');
      assert.equal(targetDirPath, path.join(__dirname, '..', 'test-db'), 'Directory path is correct');
      assert.isTrue(fs.statSync(targetDirPath).isDirectory(), 'Directory was created');
    });
  });

  describe('setupDownloadList', function () {
    it('sets up the download list from sources.json', function () {<commit_msg>added tests for existing directory<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//suppress stdout when running unit tests
process.env.NODE_ENV = 'test';

var chai = require('chai');
var fs = require('fs');
var MaxmindDbDownloader = require('../lib/maxmind-db-downloader');
var path = require('path');
var Promise = require('bluebird');
var rimraf = require('rimraf');
var sinon = require('sinon');
var assert = chai.assert;

describe('maxmind-db-downloader', function () {
  'use strict';
  var maxmindDbDownloader;
  var targetDirPath;
  var downloadPromiseFunctions;
  var expectedTargetDirPath = path.join(__dirname, '..', 'test-db');

  beforeEach(function () {
    maxmindDbDownloader = new MaxmindDbDownloader();
  });

  afterEach(function () {
    downloadPromiseFunctions = null;
    // cleanup, remove the created directory
    if (fs.statSync(expectedTargetDirPath).isDirectory()) {
      rimraf.sync(expectedTargetDirPath);
    }
    targetDirPath = '';
  });

  describe('createTargetDir', function () {
    it('creates the specified directory', function () {
      targetDirPath = maxmindDbDownloader.createTargetDir('test-db');
      assert.equal(targetDirPath, expectedTargetDirPath, 'Directory path is correct');
      assert.isTrue(fs.statSync(targetDirPath).isDirectory(), 'Directory was created');
    });

    it('does nothing when directory already exists', function () {
      // when mkdirp is called on existing directory, it
      // does nothing, and returns null
      maxmindDbDownloader.createTargetDir('test-db');
      var duplicateTargetDirPath = maxmindDbDownloader.createTargetDir('test-db');
      assert.isNull(duplicateTargetDirPath, 'Nothing was created');
      assert.isTrue(fs.statSync(expectedTargetDirPath).isDirectory(), 'Directory still exists');
    });
  });

  describe('setupDownloadList', function () {
    it('sets up the download list from sources.json', function () {
{'fraction_non_alphanumeric': 0.1337971635001338, 'fraction_numerical': 0.0021407546160021407, 'mean_word_length': 4.264788732394366, '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': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '791812', 'n_tokens_mistral': 1075, 'n_tokens_neox': 1055, 'n_words': 291}