mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-25 00:07:47 +01:00
Added fix where we mock database
This commit is contained in:
parent
03086cdd86
commit
ed418bc687
@ -1,15 +1,8 @@
|
|||||||
var eventStore = require('./eventStore'),
|
var eventStore = require('./eventStore'),
|
||||||
eventType = require('./eventType'),
|
eventType = require('./eventType'),
|
||||||
featuresMock = require('./featuresMock'),
|
|
||||||
logger = require('./logger'),
|
logger = require('./logger'),
|
||||||
Promise = require('bluebird'),
|
Promise = require('bluebird'),
|
||||||
dbPool = require('./dbPool');
|
dbPool = require('./dbPool');
|
||||||
/*
|
|
||||||
name varchar(255) PRIMARY KEY NOT NULL,
|
|
||||||
enabled integer default 0,
|
|
||||||
strategy_name varchar(255) references strategies(name),
|
|
||||||
parameters json
|
|
||||||
*/
|
|
||||||
|
|
||||||
eventStore.on(eventType.featureCreated, function (event) {
|
eventStore.on(eventType.featureCreated, function (event) {
|
||||||
var sql = 'INSERT INTO features(name, enabled, strategy_name, parameters) VALUES ($1, $2, $3, $4)';
|
var sql = 'INSERT INTO features(name, enabled, strategy_name, parameters) VALUES ($1, $2, $3, $4)';
|
||||||
@ -29,7 +22,22 @@ eventStore.on(eventType.featureCreated, function (event) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
function getFeatures() {
|
function getFeatures() {
|
||||||
return Promise.resolve(featuresMock);
|
var sql = 'SELECT name, enabled, strategy_name as strategy, parameters FROM features ORDER BY created_at';
|
||||||
|
return new Promise(function (resolve, reject) {
|
||||||
|
dbPool.query(sql, function(err, res) {
|
||||||
|
if(err) {reject(err);}
|
||||||
|
resolve(res.rows.map(mapToToggle));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function mapToToggle(row) {
|
||||||
|
return {
|
||||||
|
name: row.name,
|
||||||
|
enabled: row.enabled > 0,
|
||||||
|
strategy: row.strategy,
|
||||||
|
parameters: row.parameters
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -14,6 +14,7 @@ describe('The api', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
mockery.registerSubstitute('./eventDb', '../test/eventDbMock');
|
mockery.registerSubstitute('./eventDb', '../test/eventDbMock');
|
||||||
|
mockery.registerSubstitute('./featureDb', '../test/featureDbMock');
|
||||||
|
|
||||||
|
|
||||||
server = require('../server');
|
server = require('../server');
|
||||||
|
36
unleash-server/test/featureDbMock.js
Normal file
36
unleash-server/test/featureDbMock.js
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
var Promise = require("bluebird");
|
||||||
|
|
||||||
|
var features = [
|
||||||
|
{
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
getFeatures: function() {
|
||||||
|
return new Promise(function (resolve) {
|
||||||
|
resolve(features);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user