1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-28 00:06:53 +01:00
unleash.unleash/packages/unleash-api/test/unit/helper/legacy-feature-mapper.test.js

66 lines
2.0 KiB
JavaScript
Raw Normal View History

'use strict';
const assert = require('assert');
const mapper = require('../../../lib/helper/legacy-feature-mapper');
describe('legacy-feature-mapper', () => {
it('adds old fields to feature', () => {
const feature = {
name: 'test',
enabled: 0,
strategies: [{
name: 'default',
parameters: {
val: 'bar',
},
}],
};
const mappedFeature = mapper.addOldFields(feature);
assert.equal(mappedFeature.name, feature.name);
assert.equal(mappedFeature.enabled, feature.enabled);
assert.equal(mappedFeature.strategy, feature.strategies[0].name);
assert.notEqual(mappedFeature.parameters, feature.strategies[0].parameters);
assert.deepEqual(mappedFeature.parameters, feature.strategies[0].parameters);
});
it('transforms fields to new format', () => {
const feature = {
name: 'test',
enabled: 0,
strategy: 'default',
parameters: {
val: 'bar',
},
};
const mappedFeature = mapper.toNewFormat(feature);
assert.equal(mappedFeature.name, feature.name);
assert.equal(mappedFeature.enabled, feature.enabled);
assert.equal(mappedFeature.strategies.length, 1);
assert.equal(mappedFeature.strategies[0].name, feature.strategy);
assert.deepEqual(mappedFeature.strategies[0].parameters, feature.parameters);
assert(mappedFeature.strategy === undefined);
assert(mappedFeature.parameters === undefined);
});
2016-07-02 17:05:14 +02:00
it('should not transform if it already is the new format', () => {
const feature = {
name: 'test',
enabled: 0,
strategies: [{
name: 'default',
parameters: {
val: 'bar',
},
}],
};
const mappedFeature = mapper.toNewFormat(feature);
assert.equal(mappedFeature, feature);
});
});