-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9ea8bc1
commit 57cf02e
Showing
2 changed files
with
97 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import StatsigClient from '../StatsigClient'; | ||
import { | ||
APIInitializeDataWithPrefetchedUsers, | ||
UserCacheValues, | ||
} from '../StatsigStore'; | ||
|
||
describe('On merge deltas', () => { | ||
test('V2 values merge correctly', async () => { | ||
const statsig = new StatsigClient( | ||
'client-key', | ||
{}, | ||
{ | ||
overrideStableID: '123', | ||
}, | ||
); | ||
const data: APIInitializeDataWithPrefetchedUsers = { | ||
feature_gates: { | ||
a_gate: { | ||
value: true, | ||
rule_id: '123', | ||
name: 'a_gate', | ||
secondary_exposures: [], | ||
}, | ||
}, | ||
dynamic_configs: {}, | ||
layer_configs: {}, | ||
time: 2, | ||
}; | ||
const mergedValues: Record<string, UserCacheValues> = { | ||
v2_key: { | ||
feature_gates: { | ||
a_gate: { | ||
value: false, | ||
rule_id: 'default', | ||
name: 'a_gate', | ||
secondary_exposures: [], | ||
}, | ||
b_gate: { | ||
value: true, | ||
rule_id: 'default', | ||
name: 'b_gate', | ||
secondary_exposures: [], | ||
}, | ||
}, | ||
dynamic_configs: {}, | ||
layer_configs: {}, | ||
time: 0, | ||
sticky_experiments: {}, | ||
}, | ||
}; | ||
statsig | ||
.getStore() | ||
.mergeInitializeResponseIntoUserMap( | ||
data, | ||
mergedValues, | ||
{ v1: 'v1_key', v2: 'v2_key', v3: 'v3_key' }, | ||
{}, | ||
statsig.getStore().getDeltasMergeFunction(mergedValues), | ||
); | ||
expect(mergedValues.v3_key.feature_gates).toEqual({ | ||
a_gate: { | ||
value: true, | ||
rule_id: '123', | ||
name: 'a_gate', | ||
secondary_exposures: [], | ||
}, | ||
b_gate: { | ||
value: true, | ||
rule_id: 'default', | ||
name: 'b_gate', | ||
secondary_exposures: [], | ||
}, | ||
}); | ||
expect(mergedValues.v3_key.time).toEqual(2); | ||
}); | ||
}); |