<commit_before>var async = require('async');
var config = Object.assign({}, require('../config.json'));
config.TESTING = true;
var outputFile = require('../bin/output-file');
var opt = {
  cfg: config,
  table: 'MOCK_DATA'
};
var destinations = require('../bin/list-dest')(config);
var colParser = require('../bin/col-parser');
var columns;
var Timer = require('../bin/timer');
var fs = require('fs');
opt.log = require('../bin/log-test')(Object.assign({}, config, opt));
opt.timer = new Timer();
opt.source = 'DB_TEST';
config.logto = 'test';
var response = require('../bin/response')(Object.assign({}, config, opt));

describe('Run all destinations with MOCK_DATA', function() {
  it('Overrides opfile without error', function(done) {
    outputFile(opt, function(err, op) {
      opt.opfile = op;
      //force to use MOCK_DATA as output-ed data
      opt.opfile.filename = __dirname.replace(/\\/g, '/') + '/assets/MOCK_DATA.txt';
      opt.opfile.twoLines(function(err, data) {
        if (err) return done(err);
        var test2Lines = [
          'id_IND\tfirst_name\tlast_name\temail\tgender\tip_address\ttesting_GPA\ttesting_DATE\ttesting_TIMESTAMP\ttesting_DEC',
          '1\tEmily\tFisher\tefisher0@google.de\tFemale\t172.16.58.3\t89.64\t2015-11-15\t2016-01-29\t89.62'
        ];
        if (data[0] !== test2Lines[0] || data[1] !== test2Lines[1]) return done(new Error('Data returned by opfile.twoLines() did not match MOCK_DATA.\n' + data.toString() + test2Lines.toString()));
        done();
      });
    });
  });
  it('Parsed columns without error', function(done) {
    colParser(opt.opfile, function(err, parsedCols) {
      if (err) return done(err);
      columns = parsedCols;
      var cols = ['id', 'first_name', 'last_name', 'email', 'gender', 'ip_address', 'testing_GPA', 'testing_DATE', 'testing_TIMESTAMP', 'testing_DEC'];
      response.source.respond('ok', 1000, cols);
      done();
    });
  });
  it('Runs every destination', function() {
    async.each(destinations, function(dest) {
      describe('Checking ' + dest, function() {
        this.timeout(30000);
        var destination = fs.existsSync('./bin/dest/' + dest + '.js') ? require('../bin/dest/' + dest) : require(config.dirs.destinations + dest);
        it('Ran destination ' + dest, function(done) {
          destination(opt, columns, function(err, rows, columns) {
            if (err) return done(new Error(err));
            response.destination.respond('ok', rows, columns);
            var res = response.check();
            if (res === null) return done();<commit_msg>test needs to tell us which destination so we pick right creds<commit_after>var async = require('async');
var config = Object.assign({}, require('../config.json'));
config.TESTING = true;
var outputFile = require('../bin/output-file');
var opt = {
  cfg: config,
  table: 'MOCK_DATA'
};
var destinations = require('../bin/list-dest')(config);
var colParser = require('../bin/col-parser');
var columns;
var Timer = require('../bin/timer');
var fs = require('fs');
opt.log = require('../bin/log-test')(Object.assign({}, config, opt));
opt.timer = new Timer();
opt.source = 'DB_TEST';
config.logto = 'test';
var response = require('../bin/response')(Object.assign({}, config, opt));

describe('Run all destinations with MOCK_DATA', function() {
  it('Overrides opfile without error', function(done) {
    outputFile(opt, function(err, op) {
      opt.opfile = op;
      //force to use MOCK_DATA as output-ed data
      opt.opfile.filename = __dirname.replace(/\\/g, '/') + '/assets/MOCK_DATA.txt';
      opt.opfile.twoLines(function(err, data) {
        if (err) return done(err);
        var test2Lines = [
          'id_IND\tfirst_name\tlast_name\temail\tgender\tip_address\ttesting_GPA\ttesting_DATE\ttesting_TIMESTAMP\ttesting_DEC',
          '1\tEmily\tFisher\<EMAIL>\tFemale\t172.16.58.3\t89.64\t2015-11-15\t2016-01-29\t89.62'
        ];
        if (data[0] !== test2Lines[0] || data[1] !== test2Lines[1]) return done(new Error('Data returned by opfile.twoLines() did not match MOCK_DATA.\n' + data.toString() + test2Lines.toString()));
        done();
      });
    });
  });
  it('Parsed columns without error', function(done) {
    colParser(opt.opfile, function(err, parsedCols) {
      if (err) return done(err);
      columns = parsedCols;
      var cols = ['id', 'first_name', 'last_name', 'email', 'gender', 'ip_address', 'testing_GPA', 'testing_DATE', 'testing_TIMESTAMP', 'testing_DEC'];
      response.source.respond('ok', 1000, cols);
      done();
    });
  });
  it('Runs every destination', function() {
    async.each(destinations, function(dest) {
      describe('Checking ' + dest, function() {
        this.timeout(30000);
        var destination = fs.existsSync('./bin/dest/' + dest + '.js') ? require('../bin/dest/' + dest) : require(config.dirs.destinations + dest);
        it('Ran destination ' + dest, function(done) {
          opt.destination = dest;
          destination(opt, columns, function(err, rows, columns) {
            if (err) return done(new Error(err));
            response.destination.respond('ok', rows, columns);
            var res = response.check();
            if (res === null) return done();
{'fraction_non_alphanumeric': 0.1791530944625407, 'fraction_numerical': 0.019352366353707608, 'mean_word_length': 3.3463780183180685, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 3, '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': '1030464', 'n_tokens_mistral': 1748, 'n_tokens_neox': 1674, 'n_words': 364}