1
0
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:
Ivar Conradi Østhus 2020-08-03 13:24:51 +02:00 committed by GitHub
parent 2a4130548a
commit e42337e523
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 0 deletions

View File

@ -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({

View File

@ -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',