2014-12-03 15:22:03 +01:00
|
|
|
process.env.NODE_ENV = 'test';
|
|
|
|
|
2014-12-09 14:44:25 +01:00
|
|
|
var Promise = require('bluebird');
|
|
|
|
var request = require('supertest');
|
|
|
|
var app = require('../app');
|
|
|
|
var knex = require('../lib/dbPool');
|
|
|
|
var featureDb = require('../lib/featureDb');
|
|
|
|
var strategyDb = require('../lib/strategyDb');
|
2014-12-05 17:20:17 +01:00
|
|
|
|
|
|
|
Promise.promisifyAll(request);
|
|
|
|
request = request(app);
|
2014-11-25 14:41:11 +01:00
|
|
|
|
2014-12-05 17:20:17 +01:00
|
|
|
function createStrategies() {
|
|
|
|
return Promise.map([
|
|
|
|
{
|
|
|
|
name: "default",
|
|
|
|
description: "Default on or off Strategy."
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "usersWithEmail",
|
|
|
|
description: "Active for users defined in the comma-separated emails-parameter.",
|
|
|
|
parametersTemplate: {
|
|
|
|
emails: "String"
|
|
|
|
}
|
|
|
|
}
|
2014-12-09 14:44:25 +01:00
|
|
|
], function (strategy) { return strategyDb._createStrategy(strategy); });
|
2014-12-05 17:20:17 +01:00
|
|
|
}
|
2014-11-25 14:41:11 +01:00
|
|
|
|
2014-12-05 17:20:17 +01:00
|
|
|
function createFeatures() {
|
|
|
|
return Promise.map([
|
|
|
|
{
|
|
|
|
"name": "featureX",
|
|
|
|
"description": "the #1 feature",
|
|
|
|
"enabled": true,
|
|
|
|
"strategy": "default"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "featureY",
|
|
|
|
"description": "soon to be the #1 feature",
|
|
|
|
"enabled": false,
|
|
|
|
"strategy": "baz",
|
|
|
|
"parameters": {
|
|
|
|
"foo": "bar"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "featureZ",
|
|
|
|
"description": "terrible feature",
|
|
|
|
"enabled": true,
|
|
|
|
"strategy": "baz",
|
|
|
|
"parameters": {
|
|
|
|
"foo": "rab"
|
|
|
|
}
|
|
|
|
}
|
2014-12-09 14:44:25 +01:00
|
|
|
], function (feature) { return featureDb._createFeature(feature); });
|
2014-12-05 17:20:17 +01:00
|
|
|
}
|
2014-11-25 14:41:11 +01:00
|
|
|
|
2014-12-05 17:20:17 +01:00
|
|
|
function destroyStrategies() {
|
|
|
|
return knex('strategies').del();
|
|
|
|
}
|
2014-11-25 14:41:11 +01:00
|
|
|
|
2014-12-05 17:20:17 +01:00
|
|
|
function destroyFeatures() {
|
|
|
|
return knex('features').del();
|
2014-11-25 14:41:11 +01:00
|
|
|
}
|
|
|
|
|
2014-12-05 17:20:17 +01:00
|
|
|
function resetDatabase() {
|
2014-12-12 14:11:09 +01:00
|
|
|
return Promise.all([destroyStrategies(), destroyFeatures()]);
|
2014-12-05 17:20:17 +01:00
|
|
|
}
|
2014-11-25 14:41:11 +01:00
|
|
|
|
2014-12-05 17:20:17 +01:00
|
|
|
function setupDatabase() {
|
|
|
|
return Promise.all([createStrategies(), createFeatures()]);
|
2014-11-25 14:41:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
2014-12-05 17:20:17 +01:00
|
|
|
request: request,
|
|
|
|
db: {
|
|
|
|
reset: resetDatabase,
|
|
|
|
setup: setupDatabase,
|
|
|
|
resetAndSetup: function () { return resetDatabase().then(setupDatabase); }
|
|
|
|
}
|
2014-11-25 14:41:11 +01:00
|
|
|
};
|