1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

fix: Strategy schema should allow deprecated field (#700)

fixes: #698
This commit is contained in:
Ivar Conradi Østhus 2021-02-01 09:41:50 +01:00 committed by GitHub
parent 187798262e
commit c500128f07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 55 additions and 24 deletions

View File

@ -3,29 +3,33 @@
const joi = require('joi');
const { nameType } = require('../routes/admin-api/util');
const strategySchema = joi.object().keys({
name: nameType,
editable: joi.boolean().default(true),
description: joi
.string()
.allow(null)
.allow('')
.optional(),
parameters: joi
.array()
.required()
.items(
joi.object().keys({
name: joi.string().required(),
type: joi.string().required(),
description: joi
.string()
.allow(null)
.allow('')
.optional(),
required: joi.boolean(),
}),
),
});
const strategySchema = joi
.object()
.keys({
name: nameType,
editable: joi.boolean().default(true),
deprecated: joi.boolean().default(false),
description: joi
.string()
.allow(null)
.allow('')
.optional(),
parameters: joi
.array()
.required()
.items(
joi.object().keys({
name: joi.string().required(),
type: joi.string().required(),
description: joi
.string()
.allow(null)
.allow('')
.optional(),
required: joi.boolean(),
}),
),
})
.options({ allowUnknown: false, stripUnknown: true, abortEarly: false });
module.exports = strategySchema;

View File

@ -172,3 +172,30 @@ test.serial('cannot deprecate default strategy', async t => {
const request = await setupApp(stores);
await request.post('/api/admin/strategies/default/deprecate').expect(403);
});
test.serial('can update a exiting strategy with deprecated', async t => {
t.plan(0);
const request = await setupApp(stores);
await request
.post('/api/admin/strategies')
.send({
name: 'myCustomStrategyDepreacted',
description: 'Best strategy ever.',
parameters: [],
deprecated: true,
})
.set('Content-Type', 'application/json');
const { body: strategy } = await request.get(
'/api/admin/strategies/myCustomStrategyDepreacted',
);
strategy.description = 'A new desc';
return request
.put('/api/admin/strategies/default')
.send(strategy)
.set('Content-Type', 'application/json')
.expect(200);
});