2016-07-02 16:25:30 +02:00
|
|
|
'use strict';
|
2016-10-26 10:43:11 +02:00
|
|
|
|
2016-11-13 15:41:35 +01:00
|
|
|
const test = require('ava');
|
2016-11-13 20:33:23 +01:00
|
|
|
const mapper = require('./legacy-feature-mapper');
|
2016-07-02 16:25:30 +02:00
|
|
|
|
2016-11-13 15:41:35 +01:00
|
|
|
test('adds old fields to feature', t => {
|
|
|
|
const feature = {
|
|
|
|
name: 'test',
|
|
|
|
enabled: 0,
|
|
|
|
strategies: [{
|
|
|
|
name: 'default',
|
2016-07-02 16:25:30 +02:00
|
|
|
parameters: {
|
|
|
|
val: 'bar',
|
|
|
|
},
|
2016-11-13 15:41:35 +01:00
|
|
|
}],
|
|
|
|
};
|
|
|
|
|
|
|
|
const mappedFeature = mapper.addOldFields(feature);
|
2016-07-02 16:25:30 +02:00
|
|
|
|
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-07-02 16:25:30 +02:00
|
|
|
|
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,
|
2016-11-22 22:21:10 +01:00
|
|
|
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
|
|
|
|
2016-11-22 22:21:10 +01:00
|
|
|
t.deepEqual(mappedFeature, feature);
|
2016-07-02 16:25:30 +02:00
|
|
|
});
|