From 447940ed0c6c8dbe73d061b23e6e7bad1332261e Mon Sep 17 00:00:00 2001 From: sveisvei Date: Wed, 28 Jun 2017 12:52:27 +0200 Subject: [PATCH] should expose one feature --- lib/routes/client-api/feature.js | 9 +++++++++ lib/routes/client-api/feature.test.js | 17 +++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/lib/routes/client-api/feature.js b/lib/routes/client-api/feature.js index 966c3bb6dc..608095fc68 100644 --- a/lib/routes/client-api/feature.js +++ b/lib/routes/client-api/feature.js @@ -14,5 +14,14 @@ exports.router = config => { .then(features => res.json({ version, features })); }); + router.get('/:featureName', (req, res) => { + featureToggleStore + .getFeature(req.params.featureName) + .then(feature => res.json(feature).end()) + .catch(() => + res.status(404).json({ error: 'Could not find feature' }) + ); + }); + return router; }; diff --git a/lib/routes/client-api/feature.test.js b/lib/routes/client-api/feature.test.js index 46a2ecdf6d..ace8c38549 100644 --- a/lib/routes/client-api/feature.test.js +++ b/lib/routes/client-api/feature.test.js @@ -40,3 +40,20 @@ test('should get empty getFeatures via client', t => { t.true(res.body.features.length === 0); }); }); + +test('fetch single feature', t => { + t.plan(1); + const { request, featureToggleStore, base } = getSetup(); + featureToggleStore.addFeature({ + name: 'test_', + strategies: [{ name: 'default' }], + }); + + return request + .get(`${base}/api/client/features/test_`) + .expect('Content-Type', /json/) + .expect(200) + .expect(res => { + t.true(res.body.name === 'test_'); + }); +});