<commit_before>'use strict';

process.env.NODE_ENV = 'test';

let supertest = require('supertest');

const options = {
    databaseUri: require('./database-config').getDatabaseUri(),
};

const migrator = require('../../../migrator');
const { createStores } = require('../../../lib/db');

process.env.DATABASE_URL = options.databaseUri

const createApp =  migrator(options.databaseUri).then(() => {
    const stores = createStores(options);
    const app = require('../../../app')({stores});
    return { stores, request: supertest(app) };
});

function createStrategies (stores) {
    return BPromise.map([
        {
            name: 'default',
            description: 'Default on or off Strategy.',
            parametersTemplate: {},
        },
        {
            name: 'usersWithEmail',
            description: 'Active for users defined  in the comma-separated emails-parameter.',
            parametersTemplate: {
                emails: 'String',
            },
        },
    ], strategy => stores.strategyStore._createStrategy(strategy));
}

function createFeatures (stores) {
    return BPromise.map([
        {
            name: 'featureX',
            description: 'the #1 feature',
            enabled: true,
            strategies: [{ name: 'default', parameters: {} }],
        },
        {
            name: 'featureY',
            description: 'soon to be the #1 feature',
            enabled: false,
            strategies: [{
                name: 'baz',
                parameters: {
                    foo: 'bar',
                },
            }],
        },
        {
            name: 'featureZ',
            description: 'terrible feature',
            enabled: true,
            strategies: [{
                name: 'baz',
                parameters: {
                    foo: 'rab',
                },
            }],
        },
        {
            name: 'featureArchivedX',
            description: 'the #1 feature',
            enabled: true,
            archived: true,
            strategies: [{ name: 'default', parameters: {} }],
        },
        {
            name: 'featureArchivedY',
            description: 'soon to be the #1 feature',
            enabled: false,
            archived: true,
            strategies: [{
                name: 'baz',
                parameters: {
                    foo: 'bar',
                },
            }],
        },
        {
            name: 'featureArchivedZ',
            description: 'terrible feature',
            enabled: true,
            archived: true,
            strategies: [{
                name: 'baz',
                parameters: {
                    foo: 'rab',
                },
            }],
        },
    ], feature => stores.featureToggleStore._createFeature(feature));
}

function destroyStrategies (stores) {
    return stores.db('strategies').del();
}

function destroyFeatures (stores) {
    return stores.db('features').del();
}

function resetDatabase (stores) {
    return BPromise.all([destroyStrategies(stores), destroyFeatures(stores)]);
}

function setupDatabase (stores) {
    return BPromise.all([createStrategies(stores), createFeatures(stores)]);
}<commit_msg>Fix failing test after bluebird removal<commit_after>'use strict';

process.env.NODE_ENV = 'test';

let supertest = require('supertest');

const options = {
    databaseUri: require('./database-config').getDatabaseUri(),
};

const migrator = require('../../../migrator');
const { createStores } = require('../../../lib/db');

process.env.DATABASE_URL = options.databaseUri

const createApp =  migrator(options.databaseUri).then(() => {
    const stores = createStores(options);
    const app = require('../../../app')({stores});
    return { stores, request: supertest(app) };
});

function createStrategies (stores) {
    return [
        {
            name: 'default',
            description: 'Default on or off Strategy.',
            parametersTemplate: {},
        },
        {
            name: 'usersWithEmail',
            description: 'Active for users defined  in the comma-separated emails-parameter.',
            parametersTemplate: {
                emails: 'String',
            },
        },
    ].map(strategy => stores.strategyStore._createStrategy(strategy));
}

function createFeatures (stores) {
    return [
        {
            name: 'featureX',
            description: 'the #1 feature',
            enabled: true,
            strategies: [{ name: 'default', parameters: {} }],
        },
        {
            name: 'featureY',
            description: 'soon to be the #1 feature',
            enabled: false,
            strategies: [{
                name: 'baz',
                parameters: {
                    foo: 'bar',
                },
            }],
        },
        {
            name: 'featureZ',
            description: 'terrible feature',
            enabled: true,
            strategies: [{
                name: 'baz',
                parameters: {
                    foo: 'rab',
                },
            }],
        },
        {
            name: 'featureArchivedX',
            description: 'the #1 feature',
            enabled: true,
            archived: true,
            strategies: [{ name: 'default', parameters: {} }],
        },
        {
            name: 'featureArchivedY',
            description: 'soon to be the #1 feature',
            enabled: false,
            archived: true,
            strategies: [{
                name: 'baz',
                parameters: {
                    foo: 'bar',
                },
            }],
        },
        {
            name: 'featureArchivedZ',
            description: 'terrible feature',
            enabled: true,
            archived: true,
            strategies: [{
                name: 'baz',
                parameters: {
                    foo: 'rab',
                },
            }],
        },
    ].map(feature => stores.featureToggleStore._createFeature(feature));
}

function destroyStrategies (stores) {
    return stores.db('strategies').del();
}

function destroyFeatures (stores) {
    return stores.db('features').del();
}

function resetDatabase (stores) {
    return Promise.all([destroyStrategies(stores), destroyFeatures(stores)]);
}

function setupDatabase (stores) {
    return Promise.all(createStrategies(stores).concat(createFeatures(stores)))
}
{'fraction_non_alphanumeric': 0.13380281690140844, 'fraction_numerical': 0.0012519561815336462, 'mean_word_length': 1.5646067415730338, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '7293209', 'n_tokens_mistral': 1667, 'n_tokens_neox': 1645, 'n_words': 364}