mirror of
https://github.com/Unleash/unleash.git
synced 2025-10-09 11:14:29 +02:00
feat: add weightType as legal property on variant schema (#614)
This commit is contained in:
parent
2a4130548a
commit
e42337e523
@ -27,6 +27,10 @@ const variantsSchema = joi.object().keys({
|
|||||||
.min(0)
|
.min(0)
|
||||||
.max(1000)
|
.max(1000)
|
||||||
.required(),
|
.required(),
|
||||||
|
weightType: joi
|
||||||
|
.string()
|
||||||
|
.valid('variable', 'fix')
|
||||||
|
.default('variable'),
|
||||||
payload: joi
|
payload: joi
|
||||||
.object()
|
.object()
|
||||||
.keys({
|
.keys({
|
||||||
|
@ -44,6 +44,45 @@ test('should strip extra variant fields', t => {
|
|||||||
t.falsy(value.variants[0].unkown);
|
t.falsy(value.variants[0].unkown);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should allow weightType=fix', t => {
|
||||||
|
const toggle = {
|
||||||
|
name: 'app.name',
|
||||||
|
enabled: false,
|
||||||
|
strategies: [{ name: 'default' }],
|
||||||
|
variants: [
|
||||||
|
{
|
||||||
|
name: 'variant-a',
|
||||||
|
weight: 1,
|
||||||
|
weightType: 'fix',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
const { value } = featureShema.validate(toggle);
|
||||||
|
t.deepEqual(value, toggle);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should disallow weightType=unknown', t => {
|
||||||
|
const toggle = {
|
||||||
|
name: 'app.name',
|
||||||
|
enabled: false,
|
||||||
|
strategies: [{ name: 'default' }],
|
||||||
|
variants: [
|
||||||
|
{
|
||||||
|
name: 'variant-a',
|
||||||
|
weight: 1,
|
||||||
|
weightType: 'unknown',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
const { error } = featureShema.validate(toggle);
|
||||||
|
t.deepEqual(
|
||||||
|
error.details[0].message,
|
||||||
|
'"variants[0].weightType" must be one of [variable, fix]',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
test('should be possible to define variant overrides', t => {
|
test('should be possible to define variant overrides', t => {
|
||||||
const toggle = {
|
const toggle = {
|
||||||
name: 'app.name',
|
name: 'app.name',
|
||||||
@ -53,6 +92,7 @@ test('should be possible to define variant overrides', t => {
|
|||||||
{
|
{
|
||||||
name: 'variant-a',
|
name: 'variant-a',
|
||||||
weight: 1,
|
weight: 1,
|
||||||
|
weightType: 'variable',
|
||||||
overrides: [
|
overrides: [
|
||||||
{
|
{
|
||||||
contextName: 'userId',
|
contextName: 'userId',
|
||||||
|
Loading…
Reference in New Issue
Block a user