<commit_before>const packagesDownloadStats = require('./../../index');
const expect = require('chai').expect;

describe('Callbacks', function() {
  describe('fetchAllStats', function() {
    it('Invalid single package name', function(done) {
      packagesDownloadStats.fetchAllStats(null, function(err, stats) {
        expect(err).to.be.an('error');
        expect(stats).to.be.an('undefined');
        done();
      });
    });

    it('Correct but not existing package', function(done) {
      packagesDownloadStats.fetchAllStats('thispackagedoesntexist', function(err, stats) {
        expect(err).to.be.an('error');
        expect(stats).to.be.an('undefined');
        done();
      });
    });

    it('Invalid package name in array', function(done) {
      packagesDownloadStats.fetchAllStats([undefined, 'request', 'express'], function(err, stats) {
        expect(err).to.be.an('error');
        expect(stats).to.be.an('undefined');
        done();
      });
    });

    it('Single existing package', function(done) {
      packagesDownloadStats.fetchAllStats('express', function(err, stats) {
        if (err) return done(err);
        expect(stats).to.have.property('monthly');
        expect(stats).to.have.property('weekly');
        expect(stats).to.have.property('daily');
        done();
      });
    });

    it('Array of size 1 with existing package', function(done) {
      packagesDownloadStats.fetchAllStats(['express'], function(err, stats) {
        if (err) return done(err);
        expect(stats).to.have.property('express');

        expect(stats.express).to.have.property('monthly');
        expect(stats.express).to.have.property('weekly');
        expect(stats.express).to.have.property('daily');
        done();
      });
    });

    it('Array of existing packages', function(done) {
      const packages = ['express', 'request', 'async'];
      packagesDownloadStats.fetchAllStats(packages, function(err, stats) {
        if (err) return done(err);
        packages.forEach(s => {
          expect(stats).to.have.property(s);
          expect(stats[s]).to.have.property('monthly');
          expect(stats[s]).to.have.property('weekly');
          expect(stats[s]).to.have.property('daily');
        });
        done();
      });
    });
  });

  describe('fetchMonthlyStats', function() {
    it('Single existing package', function(done) {
      packagesDownloadStats.fetchMonthlyStats('express', function(err, stats) {
        if (err) return done(err);
        expect(stats).to.be.above(-1);
        done();
        });
      });

    it('Array of size 1 of existing package', function(done) {
      packagesDownloadStats.fetchMonthlyStats(['express'], function(err, stats) {
        expect(stats).to.have.property('express');
        done(err);
      });
    });

    it('Array of existing packages', function(done) {
      packagesDownloadStats.fetchMonthlyStats(['express', 'request', 'async'], function(err, stats) {
        expect(stats).to.have.property('express');
        expect(stats).to.have.property('request');
        expect(stats).to.have.property('async');
        done(err);
      });
    });
  });

});<commit_msg>add some tests<commit_after>const packagesDownloadStats = require('./../../index');
const expect = require('chai').expect;

describe('Callbacks', function() {
  describe('fetchAllStats', function() {
    it('Empty array', function(done) {
      packagesDownloadStats.fetchAllStats([], function(err, stats) {
        expect(err).to.be.an('error');
        expect(stats).to.be.an('undefined');
        done();
      });
    });

    it('Invalid single package name', function(done) {
      packagesDownloadStats.fetchAllStats(null, function(err, stats) {
        expect(err).to.be.an('error');
        expect(stats).to.be.an('undefined');
        done();
      });
    });

    it('Correct but not existing package', function(done) {
      packagesDownloadStats.fetchAllStats('thispackagedoesntexist', function(err, stats) {
        expect(err).to.be.an('error');
        expect(stats).to.be.an('undefined');
        done();
      });
    });

    it('Invalid package name in array', function(done) {
      packagesDownloadStats.fetchAllStats([undefined, 'request', 'express'], function(err, stats) {
        expect(err).to.be.an('error');
        expect(stats).to.be.an('undefined');
        done();
      });
    });

    it('Single existing package', function(done) {
      packagesDownloadStats.fetchAllStats('express', function(err, stats) {
        if (err) return done(err);
        expect(stats).to.have.property('monthly');
        expect(stats).to.have.property('weekly');
        expect(stats).to.have.property('daily');
        done();
      });
    });

    it('Array of size 1 with existing package', function(done) {
      packagesDownloadStats.fetchAllStats(['express'], function(err, stats) {
        if (err) return done(err);
        expect(stats).to.have.property('express');

        expect(stats.express).to.have.property('monthly');
        expect(stats.express).to.have.property('weekly');
        expect(stats.express).to.have.property('daily');
        done();
      });
    });

    it('Array of existing packages', function(done) {
      const packages = ['express', 'request', 'async'];
      packagesDownloadStats.fetchAllStats(packages, function(err, stats) {
        if (err) return done(err);
        packages.forEach(s => {
          expect(stats).to.have.property(s);
          expect(stats[s]).to.have.property('monthly');
          expect(stats[s]).to.have.property('weekly');
          expect(stats[s]).to.have.property('daily');
        });
        done();
      });
    });
  });

  const methods = ['fetchMonthlyStats', 'fetchWeeklyStats', 'fetchDailyStats'];
  methods.forEach(methodName => {
    describe(methodName, function() {
      it('Empty array', function(done) {
        packagesDownloadStats[methodName]([], function(err, stats) {
          expect(err).to.be.an('error');
          expect(stats).to.be.an('undefined');
          done();
        });
      });

      it('Invalid single package name', function(done) {
        packagesDownloadStats[methodName](null, function(err, stats) {
          expect(err).to.be.an('error');
          expect(stats).to.be.an('undefined');
          done();
        });
      });

      it('Correct but not existing package', function(done) {
        packagesDownloadStats[methodName]('thispackagedoesntexist', function(err, stats) {
          expect(err).to.be.an('error');
          expect(stats).to.be.an('undefined');
          done();
        });
      });

      it('Invalid package name in array', function(done) {
        packagesDownloadStats[methodName]([undefined, 'request', 'express'], function(err, stats) {
          expect(err).to.be.an('error');
          expect(stats).to.be.an('undefined');
          done();
        });
      });

      it('Single existing package', function(done) {
        packagesDownloadStats[methodName]('express', function(err, stats) {
          if (err) return done(err);
          expect(stats).to.be.above(-1);
          done();
        });
      });

      it('Array of existing packages', function(done) {
        const packages = ['express', 'request', 'async'];
        packagesDownloadStats[methodName](packages, function(err, stats) {
          if (err) return done(err);
          packages.forEach(s => {
            expect(stats).to.have.property(s);
            expect(stats[s]).to.be.above(-1);
          });
          done();
        });
      });

      it('Array of size 1 of existing package', function(done) {
        packagesDownloadStats[methodName](['express'], function(err, stats) {
          expect(stats).to.have.property('express');
          expect(stats.express).to.be.above(-1);
          done(err);
        });
      });

    });
  });
});
{'fraction_non_alphanumeric': 0.17617897546714123, 'fraction_numerical': 0.0010169060633024025, 'mean_word_length': 2.75381679389313, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 25, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3809215', 'n_tokens_mistral': 2239, 'n_tokens_neox': 2195, 'n_words': 365}