mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-31 00:16:47 +01:00
feat: Added feature toggle variants
This commit is contained in:
parent
ca8d2fdae0
commit
3623052c36
@ -24,6 +24,14 @@ This endpoint is the one all admin ui should use to fetch all available feature
|
|||||||
"name": "default",
|
"name": "default",
|
||||||
"parameters": {}
|
"parameters": {}
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
"variants": [
|
||||||
|
{
|
||||||
|
"name": "variant1",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "variant2",
|
||||||
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -43,7 +51,8 @@ This endpoint is the one all admin ui should use to fetch all available feature
|
|||||||
"percentage": "10"
|
"percentage": "10"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"variants": []
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@ -63,7 +72,8 @@ Used to fetch details about a specific featureToggle. This is mostly provded to
|
|||||||
"name": "default",
|
"name": "default",
|
||||||
"parameters": {}
|
"parameters": {}
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"variants": []
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -107,7 +117,8 @@ Returns 200-respose if the feature toggle was created successfully.
|
|||||||
"name": "default",
|
"name": "default",
|
||||||
"parameters": {}
|
"parameters": {}
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"variants": []
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -145,6 +156,7 @@ Used to fetch list of archived feature toggles
|
|||||||
"parameters": {}
|
"parameters": {}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
"variants": [],
|
||||||
"strategy": "default",
|
"strategy": "default",
|
||||||
"parameters": {}
|
"parameters": {}
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ const FEATURE_COLUMNS = [
|
|||||||
'description',
|
'description',
|
||||||
'enabled',
|
'enabled',
|
||||||
'strategies',
|
'strategies',
|
||||||
|
'variants',
|
||||||
'created_at',
|
'created_at',
|
||||||
];
|
];
|
||||||
const TABLE = 'features';
|
const TABLE = 'features';
|
||||||
@ -85,6 +86,7 @@ class FeatureToggleStore {
|
|||||||
description: row.description,
|
description: row.description,
|
||||||
enabled: row.enabled > 0,
|
enabled: row.enabled > 0,
|
||||||
strategies: row.strategies,
|
strategies: row.strategies,
|
||||||
|
variants: row.variants,
|
||||||
createdAt: row.created_at,
|
createdAt: row.created_at,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -96,6 +98,7 @@ class FeatureToggleStore {
|
|||||||
enabled: data.enabled ? 1 : 0,
|
enabled: data.enabled ? 1 : 0,
|
||||||
archived: data.archived ? 1 : 0,
|
archived: data.archived ? 1 : 0,
|
||||||
strategies: JSON.stringify(data.strategies),
|
strategies: JSON.stringify(data.strategies),
|
||||||
|
variants: data.variants ? JSON.stringify(data.variants) : null,
|
||||||
created_at: data.createdAt, // eslint-disable-line
|
created_at: data.createdAt, // eslint-disable-line
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ const DEFAULT_OPTIONS = {
|
|||||||
enableRequestLogger: isDev(),
|
enableRequestLogger: isDev(),
|
||||||
secret: 'UNLEASH-SECRET',
|
secret: 'UNLEASH-SECRET',
|
||||||
sessionAge: THIRTY_DAYS,
|
sessionAge: THIRTY_DAYS,
|
||||||
adminAuthentication: 'unsecure',
|
adminAuthentication: 'none',
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -10,6 +10,11 @@ const strategiesSchema = joi.object().keys({
|
|||||||
parameters: joi.object(),
|
parameters: joi.object(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const variantsSchema = joi.object().keys({
|
||||||
|
name: nameType,
|
||||||
|
percentage: joi.number(),
|
||||||
|
});
|
||||||
|
|
||||||
const featureShema = joi
|
const featureShema = joi
|
||||||
.object()
|
.object()
|
||||||
.keys({
|
.keys({
|
||||||
@ -21,6 +26,10 @@ const featureShema = joi
|
|||||||
.required()
|
.required()
|
||||||
.min(1)
|
.min(1)
|
||||||
.items(strategiesSchema),
|
.items(strategiesSchema),
|
||||||
|
variants: joi
|
||||||
|
.array()
|
||||||
|
.optional()
|
||||||
|
.items(variantsSchema),
|
||||||
})
|
})
|
||||||
.options({ allowUnknown: false, stripUnknown: true });
|
.options({ allowUnknown: false, stripUnknown: true });
|
||||||
|
|
||||||
|
15
migrations/20190123204125-add-variants-to-features.js
Normal file
15
migrations/20190123204125-add-variants-to-features.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
exports.up = function(db, callback) {
|
||||||
|
db.runSql(
|
||||||
|
`
|
||||||
|
ALTER TABLE features ADD "variants" json;
|
||||||
|
ALTER TABLE features ALTER COLUMN "variants" SET DEFAULT '[]';
|
||||||
|
`,
|
||||||
|
callback
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.down = function(db, callback) {
|
||||||
|
db.runSql(`ALTER TABLE features DROP COLUMN "variants";`, callback);
|
||||||
|
};
|
@ -50,6 +50,26 @@ test.serial('creates new feature toggle', async t => {
|
|||||||
.then(destroy);
|
.then(destroy);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test.serial('creates new feature toggle with variants', async t => {
|
||||||
|
t.plan(1);
|
||||||
|
const { request, destroy } = await setupApp('feature_api_serial');
|
||||||
|
await request
|
||||||
|
.post('/api/admin/features')
|
||||||
|
.send({
|
||||||
|
name: 'com.test.variants',
|
||||||
|
enabled: false,
|
||||||
|
strategies: [{ name: 'default' }],
|
||||||
|
variants: [{ name: 'variant1' }, { name: 'variant2' }],
|
||||||
|
})
|
||||||
|
.set('Content-Type', 'application/json');
|
||||||
|
await request
|
||||||
|
.get('/api/admin/features/com.test.variants')
|
||||||
|
.expect(res => {
|
||||||
|
t.true(res.body.variants.length === 2);
|
||||||
|
})
|
||||||
|
.then(destroy);
|
||||||
|
});
|
||||||
|
|
||||||
test.serial('creates new feature toggle with createdBy unknown', async t => {
|
test.serial('creates new feature toggle with createdBy unknown', async t => {
|
||||||
t.plan(1);
|
t.plan(1);
|
||||||
const { request, destroy } = await setupApp('feature_api_serial');
|
const { request, destroy } = await setupApp('feature_api_serial');
|
||||||
|
Loading…
Reference in New Issue
Block a user