diff --git a/lib/db/feature-toggle-store.js b/lib/db/feature-toggle-store.js index 2c3fbe71bb..8db10c8340 100644 --- a/lib/db/feature-toggle-store.js +++ b/lib/db/feature-toggle-store.js @@ -47,7 +47,7 @@ class FeatureToggleStore { return this.db .first(FEATURE_COLUMNS) .from(TABLE) - .where({ name }) + .where({ name, archived: 0 }) .then(this.rowToFeature); } @@ -103,10 +103,10 @@ class FeatureToggleStore { _archiveFeature({ name }) { return this.db(TABLE) .where({ name }) - .update({ archived: 1 }) - .catch(err => - logger.error('Could not archive feature, error was: ', err) - ); + .update({ archived: 1, enabled: 0 }) + .catch(err => { + logger.error('Could not archive feature, error was: ', err); + }); } _reviveFeature({ name }) { diff --git a/test/e2e/api/admin/feature-archive.e2e.test.js b/test/e2e/api/admin/feature-archive.e2e.test.js index c07f47388f..72983b7344 100644 --- a/test/e2e/api/admin/feature-archive.e2e.test.js +++ b/test/e2e/api/admin/feature-archive.e2e.test.js @@ -31,6 +31,30 @@ test.serial('revives a feature by name', async t => { .then(destroy); }); +test.serial( + 'archived feature is not accessible via /features/:featureName', + async t => { + t.plan(0); + const { request, destroy } = await setupApp('archive_serial2'); + + await request + .get('/api/admin/features/featureX') + .set('Content-Type', 'application/json') + .expect(200); + + await request + .delete('/api/admin/features/featureX') + .set('Content-Type', 'application/json') + .expect(200); + + return request + .get('/api/admin/features/featureX') + .set('Content-Type', 'application/json') + .expect(404) + .then(destroy); + } +); + test.serial('must set name when reviving toggle', async t => { t.plan(0); const { request, destroy } = await setupApp('archive_serial');