From 88ecb1e94985ae623365561cc0fd422128e1a3e8 Mon Sep 17 00:00:00 2001 From: Stokes Player Date: Mon, 26 Sep 2022 16:58:57 -0400 Subject: [PATCH] fix: update way that cohorts are cached to remove duplicate key (#23985) --- packages/server/lib/cache.js | 12 ++++++++++-- packages/server/test/unit/cohort_spec.ts | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/server/lib/cache.js b/packages/server/lib/cache.js index 69840844181c..5cad00e6d63c 100644 --- a/packages/server/lib/cache.js +++ b/packages/server/lib/cache.js @@ -186,7 +186,13 @@ module.exports = { }, getCohorts () { - return fileUtil.get('COHORTS', {}) + return fileUtil.get('COHORTS', {}).then((cohorts) => { + Object.keys(cohorts).forEach((key) => { + cohorts[key].name = key + }) + + return cohorts + }) }, insertCohort (cohort) { @@ -194,7 +200,9 @@ module.exports = { return tx.get('COHORTS', {}).then((cohorts) => { return tx.set('COHORTS', { ...cohorts, - [cohort.name]: cohort, + [cohort.name]: { + cohort: cohort.cohort, + }, }) }) }) diff --git a/packages/server/test/unit/cohort_spec.ts b/packages/server/test/unit/cohort_spec.ts index aa33c0f83743..8915df45c622 100644 --- a/packages/server/test/unit/cohort_spec.ts +++ b/packages/server/test/unit/cohort_spec.ts @@ -55,7 +55,7 @@ describe('lib/cohort', () => { return cohorts.set(cohortTest).then(() => { return cohorts.getByName(cohortTest.name).then((cohort) => { - expect(cohort).to.eq(cohortTest) + expect(cohort).to.deep.eq(cohortTest) }) }) })