From d35a4910f118e248a45be2e7749cec6d0178fef0 Mon Sep 17 00:00:00 2001 From: Benjamin Petetot Date: Wed, 5 Feb 2025 17:27:41 +0100 Subject: [PATCH] feat(api): save feature toggles config in redis --- .../feature-toggles/feature-toggles-client.js | 2 ++ .../feature-toggles/feature-toggles-client.test.js | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/api/src/shared/infrastructure/feature-toggles/feature-toggles-client.js b/api/src/shared/infrastructure/feature-toggles/feature-toggles-client.js index 00173272ff4..5e13967d7f2 100644 --- a/api/src/shared/infrastructure/feature-toggles/feature-toggles-client.js +++ b/api/src/shared/infrastructure/feature-toggles/feature-toggles-client.js @@ -51,6 +51,8 @@ export class FeatureTogglesClient { await this.storage.save({ key, value: featureToggle.defaultValue }); } } + + await this.storage.save({ key: '_config', value: this.config }); } /** diff --git a/api/tests/shared/unit/infrastructure/feature-toggles/feature-toggles-client.test.js b/api/tests/shared/unit/infrastructure/feature-toggles/feature-toggles-client.test.js index 923fab8e165..20e7b59de12 100644 --- a/api/tests/shared/unit/infrastructure/feature-toggles/feature-toggles-client.test.js +++ b/api/tests/shared/unit/infrastructure/feature-toggles/feature-toggles-client.test.js @@ -18,7 +18,7 @@ describe('Unit | Infrastructure | FeatureToggles | FeatureTogglesClient', functi }); describe('init', function () { - it('initialize the storage with default values', async function () { + it('initialize the storage with config and default values', async function () { // given const featureToggles = new FeatureTogglesClient(storage); @@ -26,6 +26,9 @@ describe('Unit | Infrastructure | FeatureToggles | FeatureTogglesClient', functi await featureToggles.init(config); // then + const savedConfig = await storage.get('_config'); + expect(savedConfig).to.deep.equal(config); + const all = await featureToggles.all(); expect(all).to.deep.equal({ myToggle1: false, myToggle2: true, myToggle3: 'foo' }); }); @@ -44,7 +47,7 @@ describe('Unit | Infrastructure | FeatureToggles | FeatureTogglesClient', functi // then const keys = await storage.keys('*'); - expect(keys).to.deep.equal(['myToggle1', 'myToggle4']); + expect(keys).to.deep.equal(['myToggle1', 'myToggle4', '_config']); const all = await featureToggles.all(); expect(all).to.deep.equal({ myToggle1: false, myToggle4: 1 });