Skip to content

Commit e9cf09d

Browse files
authored
fix: Preserve fallthrough variation when cloning test data. (#194)
1 parent 466b165 commit e9cf09d

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

packages/shared/sdk-server/__tests__/LDClient.evaluation.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,33 @@ describe('given an LDClient with test data', () => {
3434
client.close();
3535
});
3636

37+
it('evaluates a flag which has a fallthrough and a rule', async () => {
38+
const testId = 'abcd'.repeat(8);
39+
const flagKey = 'testFlag';
40+
await td.update(td.flag(flagKey).booleanFlag().variationForAll(true));
41+
await td.update(td.flag(flagKey).ifMatch('user', 'testId', testId).thenReturn(false));
42+
43+
// Evaluate with no testId
44+
const flagsState = await client.allFlagsState({
45+
kind: 'user',
46+
key: 'fake',
47+
testId: undefined,
48+
});
49+
50+
const features = flagsState.allValues();
51+
52+
expect(features[flagKey]).toBeTruthy();
53+
54+
const flagsStateWithTenant = await client.allFlagsState({
55+
kind: 'user',
56+
key: testId,
57+
testId,
58+
});
59+
60+
const featuresWithTenant = flagsStateWithTenant.allValues();
61+
expect(featuresWithTenant[flagKey]).toBeFalsy();
62+
});
63+
3764
it('evaluates an existing flag', async () => {
3865
td.update(td.flag('flagkey').on(true).variations('a', 'b').fallthroughVariation(1));
3966
expect(await client.variation('flagkey', defaultUser, 'c')).toBe('b');

packages/shared/sdk-server/__tests__/integrations/test_data/TestData.test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ describe('given a TestData instance', () => {
167167
it('can clone a complex flag configuration', () => {
168168
const flag = td
169169
.flag('test-flag')
170+
.offVariation(true)
171+
.variationForAll(false)
172+
.variationForUser('billy', true)
170173
.ifMatch('user', 'name', 'ben', 'christian')
171174
.andNotMatch('user', 'country', 'fr')
172175
.thenReturn(true);
@@ -199,7 +202,14 @@ describe('given a TestData instance', () => {
199202
},
200203
];
201204

202-
expect(flagCopy.build(1).rules).toEqual(flagRules);
205+
const builtFlag = flagCopy.build(1);
206+
expect(builtFlag.fallthrough).toEqual({ variation: 1 });
207+
expect(builtFlag.offVariation).toEqual(0);
208+
expect(builtFlag.variations).toEqual([true, false]);
209+
expect(builtFlag.contextTargets).toEqual([
210+
{ contextKind: 'user', values: ['billy'], variation: 0 },
211+
]);
212+
expect(builtFlag.rules).toEqual(flagRules);
203213
});
204214

205215
it('defaults a new flag to on', () => {

packages/shared/sdk-server/src/integrations/test_data/TestDataFlagBuilder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export default class TestDataFlagBuilder {
4242
this.data.offVariation = data.offVariation;
4343
}
4444
if (data.fallthroughVariation !== undefined) {
45-
this.data.offVariation = data.offVariation;
45+
this.data.fallthroughVariation = data.fallthroughVariation;
4646
}
4747
if (data.targetsByVariation) {
4848
this.data.targetsByVariation = JSON.parse(JSON.stringify(data.targetsByVariation));

0 commit comments

Comments
 (0)