<commit_before>'use strict';

var assert  = require('assert'),
    log     = require('winston'),
    db      = require('larvitdb'),
    userLib = require('../larvituser.js'),
    fs      = require('fs');

// Set up winston
log.remove(log.transports.Console);

before(function(done) {
	var confFile;

	function runDbSetup(confFile) {
		log.verbose('DB config: ' + JSON.stringify(require(confFile)));

		db.setup(require(confFile), function(err) {
			assert( ! err, 'err should be negative');

			done();
		});
	}

	if (process.argv[3] === undefined)
		confFile = __dirname + '/../../../config/db_test.json';
	else
		confFile = process.argv[3].split('=')[1];

	log.verbose('DB config file: "' + confFile + '"');

	fs.stat(confFile, function(err) {
		var altConfFile = __dirname + '/../config/' + confFile;

		if (err) {
			log.info('Failed to find config file "' + confFile + '", retrying with "' + altConfFile + '"');

			fs.stat(altConfFile, function(err) {
				if (err)
					assert( ! err, 'fs.stat failed: ' + err.message);

				if ( ! err)
					runDbSetup(altConfFile);
			});
		} else {
			runDbSetup(confFile);
		}
	});

});

describe('Tools', function() {
	it('should change buffer to uuid string', function(done) {
		var uuidStr = 'de305d54-75b4-431b-adb2-eb6b9e546014',
		    uuidBuf = new Buffer(uuidStr.replace(/-/g, ''), 'hex'),
		    testStr = userLib.bufferToUuid(uuidBuf);

		assert(testStr === uuidStr, 'testStr should be "' + uuidStr + '" but is "' + testStr + '"');

		done();
	});
});

describe('User', function() {
	var createdUuid;

	before(function(done) {
		// Check for empty db
		db.query('SHOW TABLES', function(err, rows) {
			if (err) {
				log.error(err);
				process.exit(1);
			}

			if (rows.length) {
				log.error('Database is not empty. To make a test, you must supply an empty database!');
				process.exit(1);
			}

			userLib.checkDbStructure(function(err) {
				assert( ! err, 'err should be negative');<commit_msg>Removed test that should not be here anymore<commit_after>'use strict';

var assert  = require('assert'),
    log     = require('winston'),
    db      = require('larvitdb'),
    userLib = require('../larvituser.js'),
    fs      = require('fs');

// Set up winston
log.remove(log.transports.Console);

before(function(done) {
	var confFile;

	function runDbSetup(confFile) {
		log.verbose('DB config: ' + JSON.stringify(require(confFile)));

		db.setup(require(confFile), function(err) {
			assert( ! err, 'err should be negative');

			done();
		});
	}

	if (process.argv[3] === undefined)
		confFile = __dirname + '/../../../config/db_test.json';
	else
		confFile = process.argv[3].split('=')[1];

	log.verbose('DB config file: "' + confFile + '"');

	fs.stat(confFile, function(err) {
		var altConfFile = __dirname + '/../config/' + confFile;

		if (err) {
			log.info('Failed to find config file "' + confFile + '", retrying with "' + altConfFile + '"');

			fs.stat(altConfFile, function(err) {
				if (err)
					assert( ! err, 'fs.stat failed: ' + err.message);

				if ( ! err)
					runDbSetup(altConfFile);
			});
		} else {
			runDbSetup(confFile);
		}
	});

});

describe('User', function() {
	var createdUuid;

	before(function(done) {
		// Check for empty db
		db.query('SHOW TABLES', function(err, rows) {
			if (err) {
				log.error(err);
				process.exit(1);
			}

			if (rows.length) {
				log.error('Database is not empty. To make a test, you must supply an empty database!');
				process.exit(1);
			}

			userLib.checkDbStructure(function(err) {
				assert( ! err, 'err should be negative');
{'fraction_non_alphanumeric': 0.18097643097643099, 'fraction_numerical': 0.008417508417508417, 'mean_word_length': 3.269461077844311, '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': '708129', 'n_tokens_mistral': 1392, 'n_tokens_neox': 1218, 'n_words': 274}