1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00
unleash.unleash/test/fixtures/fake-strategies-store.js
2021-01-21 15:53:24 +01:00

56 lines
1.9 KiB
JavaScript

'use strict';
const NotFoundError = require('../../lib/error/notfound-error');
module.exports = () => {
const _strategies = [
{ name: 'default', editable: false, parameters: {}, deprecated: false },
];
return {
getStrategies: () => Promise.resolve(_strategies),
getEditableStrategies: () =>
Promise.resolve(_strategies.filter(s => s.editable)),
getStrategy: name => {
const strategy = _strategies.find(s => s.name === name);
if (strategy) {
return Promise.resolve(strategy);
}
return Promise.reject(new NotFoundError('Not found!'));
},
createStrategy: strat => _strategies.push(strat),
updateStrategy: strat => {
_strategies.splice(
_strategies.indexOf(({ name }) => name === strat.name),
1,
);
_strategies.push(strat);
},
importStrategy: strat => Promise.resolve(_strategies.push(strat)),
dropStrategies: () => _strategies.splice(0, _strategies.length),
deleteStrategy: strat =>
_strategies.splice(
_strategies.indexOf(({ name }) => name === strat.name),
1,
),
deprecateStrategy: ({ name }) => {
const deprecatedStrat = _strategies.find(s => s.name === name);
deprecatedStrat.deprecated = true;
_strategies.splice(
_strategies.indexOf(s => name === s.name),
1,
);
_strategies.push(deprecatedStrat);
},
reactivateStrategy: ({ name }) => {
const reactivatedStrat = _strategies.find(s => s.name === name);
reactivatedStrat.deprecated = false;
_strategies.splice(
_strategies.indexOf(s => name === s.name),
1,
);
_strategies.push(reactivatedStrat);
},
};
};