mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-22 19:07:54 +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'),
|
||||
eventType = require('./eventType'),
|
||||
featuresMock = require('./featuresMock'),
|
||||
logger = require('./logger'),
|
||||
Promise = require('bluebird'),
|
||||
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) {
|
||||
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() {
|
||||
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 = {
|
||||
|
@ -14,6 +14,7 @@ describe('The api', function () {
|
||||
});
|
||||
|
||||
mockery.registerSubstitute('./eventDb', '../test/eventDbMock');
|
||||
mockery.registerSubstitute('./featureDb', '../test/featureDbMock');
|
||||
|
||||
|
||||
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