From 0e7631104e883bcfbff63895c284b6fad21c6902 Mon Sep 17 00:00:00 2001 From: Emiliano Sanchez Date: Fri, 19 Apr 2024 17:48:26 -0300 Subject: [PATCH] Fix error --- CHANGES.txt | 3 +++ package-lock.json | 4 ++-- package.json | 2 +- src/__tests__/selectors.test.ts | 7 ++++++- src/selectors.ts | 3 ++- 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 9c8c840..f0d5cf8 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,6 @@ +1.11.1 (May XX, 2024) + - Bugfixing - Fixed error when calling `selectTreatmentValue` and `selectTreatmentWithConfig` selectors with an object as a key, caused by the key not being stringified correctly. + 1.11.0 (April 3, 2024) - Added `sideEffects: false` property in the package.json file to allow tree shaking. - Updated Redux-Thunk peer dependency range to include redux-thunk@3.x.x. diff --git a/package-lock.json b/package-lock.json index 76d7aff..da60e1b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@splitsoftware/splitio-redux", - "version": "1.11.0", + "version": "1.11.1-rc.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@splitsoftware/splitio-redux", - "version": "1.11.0", + "version": "1.11.1-rc.0", "license": "Apache-2.0", "dependencies": { "@splitsoftware/splitio": "10.25.2", diff --git a/package.json b/package.json index 87d07c6..eb8e732 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@splitsoftware/splitio-redux", - "version": "1.11.0", + "version": "1.11.1-rc.0", "description": "A library to easily use Split JS SDK with Redux and React Redux", "main": "lib/index.js", "module": "es/index.js", diff --git a/src/__tests__/selectors.test.ts b/src/__tests__/selectors.test.ts index d7deec3..f2a1fbf 100644 --- a/src/__tests__/selectors.test.ts +++ b/src/__tests__/selectors.test.ts @@ -20,6 +20,9 @@ describe('selectTreatmentValue', () => { it('returns the treatment value of the given feature flag name and key', () => { /** The treatment value for the USER_1 key for SPLIT_1 is 'off' */ expect(selectTreatmentValue(STATE_READY.splitio, SPLIT_2, USER_1)).toBe(OFF); + // Using a key object + expect(selectTreatmentValue(STATE_READY.splitio, SPLIT_2, { matchingKey: USER_1, bucketingKey: 'some_bucket' })).toBe(OFF); // @ts-expect-error bucketingKey is not in SplitKey type, but it's not used in the selector + expect(selectTreatmentValue(STATE_READY.splitio, SPLIT_2, { matchingKey: USER_1 })).toBe(OFF); }); it('returns "control" value if the given feature flag name or key are invalid (were not evaluated with getTreatment, or returned "control"', () => { @@ -46,6 +49,8 @@ describe('selectTreatmentWithConfig', () => { it('returns the treatment of the given feature flag name and key', () => { expect(selectTreatmentWithConfig(STATE_READY.splitio, SPLIT_2, USER_1)).toBe(STATE_READY.splitio.treatments[SPLIT_2][USER_1]); + // Using a key object + expect(selectTreatmentWithConfig(STATE_READY.splitio, SPLIT_2, { matchingKey: USER_1, bucketingKey: 'some_bucket' })).toBe(STATE_READY.splitio.treatments[SPLIT_2][USER_1]); }); it('returns "control" treatment if the given feature flag name or key are invalid (were not evaluated with getTreatment, or returned "control")', () => { @@ -54,7 +59,7 @@ describe('selectTreatmentWithConfig', () => { }); it('returns the passed default treatment insteaad of "control" if the given feature flag name or key are invalid', () => { - const DEFAULT_TREATMENT = {treatment: 'some_value', config: 'some_config'}; + const DEFAULT_TREATMENT = { treatment: 'some_value', config: 'some_config' }; expect(selectTreatmentWithConfig(STATE_READY.splitio, SPLIT_1, USER_INVALID, DEFAULT_TREATMENT)).toBe(DEFAULT_TREATMENT); expect(selectTreatmentWithConfig(STATE_READY.splitio, SPLIT_INVALID, USER_1, DEFAULT_TREATMENT)).toBe(DEFAULT_TREATMENT); diff --git a/src/selectors.ts b/src/selectors.ts index ef0683f..25ca3d0 100644 --- a/src/selectors.ts +++ b/src/selectors.ts @@ -1,5 +1,6 @@ import { ISplitState } from './types'; import { CONTROL, CONTROL_WITH_CONFIG, DEFAULT_SPLIT_STATE_SLICE, ERROR_SELECTOR_NO_SPLITSTATE } from './constants'; +import { matching } from './utils'; export const getStateSlice = (sliceName: string) => (state: any) => state[sliceName]; @@ -30,7 +31,7 @@ export function selectTreatmentWithConfig(splitState: ISplitState, featureFlagNa const treatment = splitTreatments ? key ? - splitTreatments[key.toString()] : + splitTreatments[matching(key)] : Object.values(splitTreatments)[0] : undefined;