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

66 lines
1.8 KiB
JavaScript
Raw Normal View History

'use strict';
2016-10-26 10:43:11 +02:00
2016-11-13 15:41:35 +01:00
const test = require('ava');
const mapper = require('./legacy-feature-mapper');
2016-11-13 15:41:35 +01:00
test('adds old fields to feature', t => {
const feature = {
name: 'test',
enabled: 0,
strategies: [{
name: 'default',
parameters: {
val: 'bar',
},
2016-11-13 15:41:35 +01:00
}],
};
const mappedFeature = mapper.addOldFields(feature);
2016-11-13 15:41:35 +01:00
t.true(mappedFeature.name === feature.name);
t.true(mappedFeature.enabled === feature.enabled);
t.true(mappedFeature.strategy === feature.strategies[0].name);
t.true(mappedFeature.parameters !== feature.strategies[0].parameters);
t.deepEqual(mappedFeature.parameters, feature.strategies[0].parameters);
});
2016-11-13 15:41:35 +01:00
test('transforms fields to new format', t => {
const feature = {
name: 'test',
enabled: 0,
strategy: 'default',
parameters: {
val: 'bar',
},
};
const mappedFeature = mapper.toNewFormat(feature);
t.true(mappedFeature.name === feature.name);
t.true(mappedFeature.enabled === feature.enabled);
t.true(mappedFeature.strategies.length === 1);
t.true(mappedFeature.strategies[0].name === feature.strategy);
t.deepEqual(mappedFeature.strategies[0].parameters, feature.parameters);
t.true(mappedFeature.strategy === undefined);
t.true(mappedFeature.parameters === undefined);
});
2016-07-02 17:05:14 +02:00
2016-11-13 15:41:35 +01:00
test('should not transform if it already is the new format', t => {
const feature = {
name: 'test',
enabled: 0,
description: 'test',
createdAt: new Date(),
2016-11-13 15:41:35 +01:00
strategies: [{
name: 'default',
parameters: {
val: 'bar',
},
}],
};
2016-07-02 17:05:14 +02:00
2016-11-13 15:41:35 +01:00
const mappedFeature = mapper.toNewFormat(feature);
2016-07-02 17:05:14 +02:00
t.deepEqual(mappedFeature, feature);
});