mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-31 00:16:47 +01:00
fix: Update variant protocol
This commit is contained in:
parent
24ca56e041
commit
13e431ed17
@ -28,9 +28,11 @@ This endpoint is the one all admin ui should use to fetch all available feature
|
|||||||
"variants": [
|
"variants": [
|
||||||
{
|
{
|
||||||
"name": "variant1",
|
"name": "variant1",
|
||||||
|
"weight": 50
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "variant2",
|
"name": "variant2",
|
||||||
|
"weight": 50
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -18,7 +18,7 @@ const DEFAULT_OPTIONS = {
|
|||||||
enableRequestLogger: isDev(),
|
enableRequestLogger: isDev(),
|
||||||
secret: 'UNLEASH-SECRET',
|
secret: 'UNLEASH-SECRET',
|
||||||
sessionAge: THIRTY_DAYS,
|
sessionAge: THIRTY_DAYS,
|
||||||
adminAuthentication: 'none',
|
adminAuthentication: 'unsecure',
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -12,7 +12,18 @@ const strategiesSchema = joi.object().keys({
|
|||||||
|
|
||||||
const variantsSchema = joi.object().keys({
|
const variantsSchema = joi.object().keys({
|
||||||
name: nameType,
|
name: nameType,
|
||||||
percentage: joi.number(),
|
weight: joi
|
||||||
|
.number()
|
||||||
|
.min(0)
|
||||||
|
.max(100)
|
||||||
|
.required(),
|
||||||
|
payload: joi
|
||||||
|
.object()
|
||||||
|
.keys({
|
||||||
|
type: joi.string().required(),
|
||||||
|
value: joi.string().required(),
|
||||||
|
})
|
||||||
|
.optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const featureShema = joi
|
const featureShema = joi
|
||||||
@ -28,6 +39,7 @@ const featureShema = joi
|
|||||||
.items(strategiesSchema),
|
.items(strategiesSchema),
|
||||||
variants: joi
|
variants: joi
|
||||||
.array()
|
.array()
|
||||||
|
.unique((a, b) => a.name === b.name)
|
||||||
.optional()
|
.optional()
|
||||||
.items(variantsSchema),
|
.items(variantsSchema),
|
||||||
})
|
})
|
||||||
|
@ -241,22 +241,29 @@ test('invalid feature names should have error msg', t => {
|
|||||||
|
|
||||||
test('should not allow variants with same name when creating feature flag', t => {
|
test('should not allow variants with same name when creating feature flag', t => {
|
||||||
t.plan(0);
|
t.plan(0);
|
||||||
const { request, base } = getSetup();
|
const { request, base, perms } = getSetup();
|
||||||
|
perms.withPermissions(CREATE_FEATURE);
|
||||||
|
|
||||||
return request
|
return request
|
||||||
.post(`${base}/api/admin/features`)
|
.post(`${base}/api/admin/features`)
|
||||||
.send({
|
.send({
|
||||||
name: 'ts',
|
name: 't.variant',
|
||||||
|
enabled: true,
|
||||||
strategies: [{ name: 'default' }],
|
strategies: [{ name: 'default' }],
|
||||||
variants: [{ name: 'variant1' }, { name: 'variant1' }],
|
variants: [
|
||||||
|
{ name: 'variant1', weight: 50 },
|
||||||
|
{ name: 'variant1', weight: 50 },
|
||||||
|
],
|
||||||
})
|
})
|
||||||
.set('Content-Type', 'application/json')
|
.set('Content-Type', 'application/json')
|
||||||
.expect(403);
|
.expect(400);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should not allow variants with same name when updating feature flag', t => {
|
test('should not allow variants with same name when updating feature flag', t => {
|
||||||
t.plan(0);
|
t.plan(0);
|
||||||
const { request, featureToggleStore, base } = getSetup();
|
const { request, featureToggleStore, base, perms } = getSetup();
|
||||||
|
perms.withPermissions(UPDATE_FEATURE);
|
||||||
|
|
||||||
featureToggleStore.addFeature({
|
featureToggleStore.addFeature({
|
||||||
name: 'ts',
|
name: 'ts',
|
||||||
strategies: [{ name: 'default' }],
|
strategies: [{ name: 'default' }],
|
||||||
@ -270,5 +277,5 @@ test('should not allow variants with same name when updating feature flag', t =>
|
|||||||
variants: [{ name: 'variant1' }, { name: 'variant1' }],
|
variants: [{ name: 'variant1' }, { name: 'variant1' }],
|
||||||
})
|
})
|
||||||
.set('Content-Type', 'application/json')
|
.set('Content-Type', 'application/json')
|
||||||
.expect(403);
|
.expect(400);
|
||||||
});
|
});
|
||||||
|
@ -59,7 +59,10 @@ test.serial('creates new feature toggle with variants', async t => {
|
|||||||
name: 'com.test.variants',
|
name: 'com.test.variants',
|
||||||
enabled: false,
|
enabled: false,
|
||||||
strategies: [{ name: 'default' }],
|
strategies: [{ name: 'default' }],
|
||||||
variants: [{ name: 'variant1' }, { name: 'variant2' }],
|
variants: [
|
||||||
|
{ name: 'variant1', weight: 50 },
|
||||||
|
{ name: 'variant2', weight: 50 },
|
||||||
|
],
|
||||||
})
|
})
|
||||||
.set('Content-Type', 'application/json')
|
.set('Content-Type', 'application/json')
|
||||||
.expect(201)
|
.expect(201)
|
||||||
|
@ -127,7 +127,10 @@
|
|||||||
"enabled": true,
|
"enabled": true,
|
||||||
"archived": false,
|
"archived": false,
|
||||||
"strategies": [{ "name": "default" }],
|
"strategies": [{ "name": "default" }],
|
||||||
"variants": [{ "name": "control" }, { "name": "new" }]
|
"variants": [
|
||||||
|
{ "name": "control", "weight": 50 },
|
||||||
|
{ "name": "new", "weight": 50 }
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user