Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,33 @@ describe('given an LDClient with test data', () => {
client.close();
});

it('evaluates a flag which has a fallthrough and a rule', async () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a clone of the test case the user encountered.

const testId = 'abcd'.repeat(8);
const flagKey = 'testFlag';
await td.update(td.flag(flagKey).booleanFlag().variationForAll(true));
await td.update(td.flag(flagKey).ifMatch('user', 'testId', testId).thenReturn(false));

// Evaluate with no testId
const flagsState = await client.allFlagsState({
kind: 'user',
key: 'fake',
testId: undefined,
});

const features = flagsState.allValues();

expect(features[flagKey]).toBeTruthy();

const flagsStateWithTenant = await client.allFlagsState({
kind: 'user',
key: testId,
testId,
});

const featuresWithTenant = flagsStateWithTenant.allValues();
expect(featuresWithTenant[flagKey]).toBeFalsy();
});

it('evaluates an existing flag', async () => {
td.update(td.flag('flagkey').on(true).variations('a', 'b').fallthroughVariation(1));
expect(await client.variation('flagkey', defaultUser, 'c')).toBe('b');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ describe('given a TestData instance', () => {
it('can clone a complex flag configuration', () => {
const flag = td
.flag('test-flag')
.offVariation(true)
.variationForAll(false)
.variationForUser('billy', true)
.ifMatch('user', 'name', 'ben', 'christian')
.andNotMatch('user', 'country', 'fr')
.thenReturn(true);
Expand Down Expand Up @@ -199,7 +202,14 @@ describe('given a TestData instance', () => {
},
];

expect(flagCopy.build(1).rules).toEqual(flagRules);
const builtFlag = flagCopy.build(1);
expect(builtFlag.fallthrough).toEqual({ variation: 1 });
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test only verified rules before. Now it covers the basics as well.

expect(builtFlag.offVariation).toEqual(0);
expect(builtFlag.variations).toEqual([true, false]);
expect(builtFlag.contextTargets).toEqual([
{ contextKind: 'user', values: ['billy'], variation: 0 },
]);
expect(builtFlag.rules).toEqual(flagRules);
});

it('defaults a new flag to on', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default class TestDataFlagBuilder {
this.data.offVariation = data.offVariation;
}
if (data.fallthroughVariation !== undefined) {
this.data.offVariation = data.offVariation;
this.data.fallthroughVariation = data.fallthroughVariation;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actual copy/paste error.

}
if (data.targetsByVariation) {
this.data.targetsByVariation = JSON.parse(JSON.stringify(data.targetsByVariation));
Expand Down