mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-28 00:06:53 +01:00
e52c1d16fe
* Add Travis postgresql setup. * Replace "db mocks" with a before hook that creates the same data through the HTTP API. * Reset DB and re-create all fixtures for each test. We'll need something better here. * CAVEAT: no concept of a dev vs test database. Running tests will clear data from the currently configured database.
91 lines
2.2 KiB
JavaScript
91 lines
2.2 KiB
JavaScript
process.env.NODE_ENV = 'test';
|
|
|
|
var Promise = require('bluebird');
|
|
var request = require('supertest');
|
|
var app = require('../app');
|
|
var knex = require('../lib/dbPool');
|
|
|
|
Promise.promisifyAll(request);
|
|
request = request(app);
|
|
|
|
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"
|
|
}
|
|
}
|
|
], function (strategy) {
|
|
return request
|
|
.post('/strategies').send(strategy)
|
|
.set('Content-Type', 'application/json')
|
|
.expect(201)
|
|
.endAsync();
|
|
});
|
|
}
|
|
|
|
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"
|
|
}
|
|
}
|
|
], function (feature) {
|
|
return request
|
|
.post('/features').send(feature)
|
|
.set('Content-Type', 'application/json')
|
|
.expect(201)
|
|
.endAsync();
|
|
});
|
|
}
|
|
|
|
function destroyStrategies() {
|
|
return knex('strategies').del();
|
|
}
|
|
|
|
function destroyFeatures() {
|
|
return knex('features').del();
|
|
}
|
|
|
|
function resetDatabase() {
|
|
return Promise.all([destroyStrategies(), destroyFeatures()]);
|
|
}
|
|
|
|
function setupDatabase() {
|
|
return Promise.all([createStrategies(), createFeatures()]);
|
|
}
|
|
|
|
module.exports = {
|
|
request: request,
|
|
db: {
|
|
reset: resetDatabase,
|
|
setup: setupDatabase,
|
|
resetAndSetup: function () { return resetDatabase().then(setupDatabase); }
|
|
}
|
|
}; |