mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	This commit changes the features-tables:
- drop columns 'strategy' and 'parameters'
- add column 'strategies' of type json.
- migrates existing strategy-mappings in to the new format.
The idea is that the 'strategies' column should contain a json-array
of strategy-configuration for the toggle:
```
[{
 "name" : "strategy1",
 "parameters": { "name": "vale" }
}]
```
To make sure to not break exiting clients the api is extended with a
mapping layer (adding old fields to the json-respons, and mapping
to the new format on create/update a feature toggle.
this commit is first step in solving #102
		
	
			
		
			
				
	
	
		
			49 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			49 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
'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',
 | 
						|
                },
 | 
						|
            }],
 | 
						|
        };
 | 
						|
 | 
						|
        let 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);
 | 
						|
    });
 | 
						|
});
 |