<commit_before>var injection = require('../services/injection.js');
var Q = require('q');

module.exports = function (test, fixtureName, testFn) {
    var allcountServer = require('../allcount-server.js');

    injection.resetInjection();
    injection.bindFactory('port', 9080);
    injection.bindFactory('dbUrl', 'mongodb://localhost:27017/' + fixtureName);
    injection.bindFactory('gitRepoUrl', 'test-fixtures/' + fixtureName);

    allcountServer.reconfigureAllcount();
    var server = allcountServer.inject('allcountServerStartup');
    server.startup(function (errors) {
        if (errors) {
            throw new Error(errors.join('\n'));
        }
        Q(testFn()).then(function () {
            return server.stop().then(function () {
                injection.resetInjection();
                test.done();
            });
        }).done();
    });
};<commit_msg>Cleanup DB before and after integration tests<commit_after>var injection = require('../services/injection.js');
var Q = require('q');
var mongoose = require('mongoose');

module.exports = function (test, fixtureName, testFn) {
    var dbUrl = 'mongodb://localhost:27017/' + fixtureName;

    var cleanUp = function () {
        return Q.nbind(mongoose.connect, mongoose)(dbUrl).then(function () {
            var db = mongoose.connection.db;
            return Q.nbind(db.dropDatabase, db)().then(function () {
                db.close();
            });
        });
    };

    cleanUp().then(function () {
        var allcountServer = require('../allcount-server.js');

        injection.resetInjection();
        injection.bindFactory('port', 9080);
        injection.bindFactory('dbUrl', dbUrl);
        injection.bindFactory('gitRepoUrl', 'test-fixtures/' + fixtureName);

        allcountServer.reconfigureAllcount();
        return allcountServer.inject('allcountServerStartup');
    }).then(function (server) {
        return Q.nbind(server.startup, server)().then(function (errors) {
            if (errors) {
                throw new Error(errors.join('\n'));
            }
            return Q(testFn()).then(function () {
                return server.stop().then(function () {
                    injection.resetInjection();
                });
            });
        }).then(cleanUp);
    }).done(function () {
        test.done();
    });
};
{'fraction_non_alphanumeric': 0.15818725951261223, 'fraction_numerical': 0.007695596408721676, 'mean_word_length': 2.4615384615384617, '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': '4859384', 'n_tokens_mistral': 659, 'n_tokens_neox': 638, 'n_words': 111}