Skip to content

Commit

Permalink
Fix error
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilianoSanchez committed Apr 19, 2024
1 parent 7560bea commit 0e76311
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
7 changes: 6 additions & 1 deletion src/__tests__/selectors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"', () => {
Expand All @@ -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")', () => {
Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/selectors.ts
Original file line number Diff line number Diff line change
@@ -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];

Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 0e76311

Please sign in to comment.