mirror of
https://github.com/Unleash/unleash.git
synced 2025-05-31 01:16:01 +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)
|
||||
.max(1000)
|
||||
.required(),
|
||||
weightType: joi
|
||||
.string()
|
||||
.valid('variable', 'fix')
|
||||
.default('variable'),
|
||||
payload: joi
|
||||
.object()
|
||||
.keys({
|
||||
|
@ -44,6 +44,45 @@ test('should strip extra variant fields', t => {
|
||||
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 => {
|
||||
const toggle = {
|
||||
name: 'app.name',
|
||||
@ -53,6 +92,7 @@ test('should be possible to define variant overrides', t => {
|
||||
{
|
||||
name: 'variant-a',
|
||||
weight: 1,
|
||||
weightType: 'variable',
|
||||
overrides: [
|
||||
{
|
||||
contextName: 'userId',
|
||||
|
Loading…
Reference in New Issue
Block a user