diff --git a/lib/services/strategy-schema.js b/lib/services/strategy-schema.js index fd15dfd3b9..d3acf73194 100644 --- a/lib/services/strategy-schema.js +++ b/lib/services/strategy-schema.js @@ -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; diff --git a/test/e2e/api/admin/strategy.e2e.test.js b/test/e2e/api/admin/strategy.e2e.test.js index d522928c16..576ee0c53e 100644 --- a/test/e2e/api/admin/strategy.e2e.test.js +++ b/test/e2e/api/admin/strategy.e2e.test.js @@ -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); +});