From 1745bc177c018981efcc9ce6e7d435f137dbacf6 Mon Sep 17 00:00:00 2001 From: Emiliano Sanchez Date: Mon, 18 Dec 2023 11:29:09 -0300 Subject: [PATCH] Polishing --- src/__tests__/index.test.ts | 46 +++++++++++++++++++++++++++++++++++++ src/utils.ts | 6 ++--- 2 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 src/__tests__/index.test.ts diff --git a/src/__tests__/index.test.ts b/src/__tests__/index.test.ts new file mode 100644 index 0000000..69e68cd --- /dev/null +++ b/src/__tests__/index.test.ts @@ -0,0 +1,46 @@ +import { + splitReducer as exportedSplitReducer, + initSplitSdk as exportedInitSplitSdk, + getTreatments as exportedGetTreatments, + destroySplitSdk as exportedDestroySplitSdk, + splitSdk as exportedSplitSdk, + track as exportedTrack, + getSplitNames as exportedGetSplitNames, + getSplit as exportedGetSplit, + getSplits as exportedGetSplits, + selectTreatmentValue as exportedSelectTreatmentValue, + selectTreatmentWithConfig as exportedSelectTreatmentWithConfig, + connectSplit as exportedConnectSplit, + connectToggler as exportedConnectToggler, + mapTreatmentToProps as exportedMapTreatmentToProps, + mapIsFeatureOnToProps as exportedMapIsFeatureOnToProps, + // Checks that types are exported. Otherwise, the test would fail with a TS error. + ISplitState, +} from '../index'; + +import { splitReducer } from '../reducer'; +import { initSplitSdk, getTreatments, destroySplitSdk, splitSdk } from '../asyncActions'; +import { track, getSplitNames, getSplit, getSplits } from '../helpers'; +import { selectTreatmentValue, selectTreatmentWithConfig } from '../selectors'; +import { connectSplit } from '../react-redux/connectSplit'; +import { connectToggler, mapTreatmentToProps, mapIsFeatureOnToProps } from '../react-redux/connectToggler'; + +it('index should export modules', () => { + + expect(exportedSplitReducer).toBe(splitReducer); + expect(exportedInitSplitSdk).toBe(initSplitSdk); + expect(exportedGetTreatments).toBe(getTreatments); + expect(exportedDestroySplitSdk).toBe(destroySplitSdk); + expect(exportedSplitSdk).toBe(splitSdk); + expect(exportedTrack).toBe(track); + expect(exportedGetSplitNames).toBe(getSplitNames); + expect(exportedGetSplit).toBe(getSplit); + expect(exportedGetSplits).toBe(getSplits); + expect(exportedSelectTreatmentValue).toBe(selectTreatmentValue); + expect(exportedSelectTreatmentWithConfig).toBe(selectTreatmentWithConfig); + expect(exportedConnectSplit).toBe(connectSplit); + expect(exportedConnectToggler).toBe(connectToggler); + expect(exportedMapTreatmentToProps).toBe(mapTreatmentToProps); + expect(exportedMapIsFeatureOnToProps).toBe(mapIsFeatureOnToProps); + +}); diff --git a/src/utils.ts b/src/utils.ts index 62bb68c..0a90e0f 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -51,10 +51,8 @@ export function validateGetTreatmentsParams(params: any): IGetTreatmentsParams | if (!splitNames) return false; // Ignore flagSets if splitNames are provided - if (flagSets) { - console.log(WARN_FEATUREFLAGS_AND_FLAGSETS); - flagSets = undefined; - } + if (flagSets) console.log(WARN_FEATUREFLAGS_AND_FLAGSETS); + flagSets = undefined; } else { // Flag set names are not sanitized, because they are not used by Redux SDK directly. We just make sure it is an array. flagSets = typeof flagSets === 'string' ? [flagSets] : flagSets;