Skip to content
This repository has been archived by the owner on May 30, 2024. It is now read-only.

Commit

Permalink
use TestData in our own tests (#231)
Browse files Browse the repository at this point in the history
* use TestData in our own tests

* update TS interface

* lint

* typo
  • Loading branch information
eli-darkly authored Jan 4, 2022
1 parent a8b19f3 commit 94af72c
Show file tree
Hide file tree
Showing 9 changed files with 315 additions and 223 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ env:
es6: true
node: true
parserOptions:
ecmaVersion: 2017 # allows us to use async/await, now that our Node version is always >= 8
ecmaVersion: 2018
plugins:
#- babel
- prettier
Expand Down
38 changes: 38 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,44 @@ declare module 'launchdarkly-node-server-sdk/integrations' {
* @return a promise that will resolve when the feature stores are updated
*/
update(flagBuilder: TestDataFlagBuilder): Promise<any>;

/**
* Copies a full feature flag data model object into the test data.
*
* It immediately propagates the flag change to any [[LDClient]] instance(s) that you have already
* configured to use this `TestData`. If no [[LDClient]] has been started yet, it simply adds
* this flag to the test data which will be provided to any LDClient that you subsequently
* configure.
*
* Use this method if you need to use advanced flag configuration properties that are not supported by
* the simplified [[TestDataFlagBuilder]] API. Otherwise it is recommended to use the regular
* [[flag]]/[[update]] mechanism to avoid dependencies on details of the data model.
*
* You cannot make incremental changes with [[flag]]/[[update]] to a flag that has been added in this way;
* you can only replace it with an entirely new flag configuration.
*
* @param flagConfig the flag configuration as a JSON object
* @return a promise that will resolve when the feature stores are updated
*/
usePreconfiguredFlag(flagConfig: any): Promise<any>;

/**
* Copies a full user segment data model object into the test data.
*
* It immediately propagates the change to any [[LDClient]] instance(s) that you have already
* configured to use this `TestData`. If no [[LDClient]] has been started yet, it simply adds
* this segment to the test data which will be provided to any LDClient that you subsequently
* configure.
*
* This method is currently the only way to inject user segment data, since there is no builder
* API for segments. It is mainly intended for the SDK's own tests of user segment functionality,
* since application tests that need to produce a desired evaluation state could do so more easily
* by just setting flag values.
*
* @param segmentConfig the segment configuration as a JSON object
* @return a promise that will resolve when the feature stores are updated
*/
usePreconfiguredSegment(segmentConfig: any): Promise<any>;
}

/**
Expand Down
17 changes: 7 additions & 10 deletions test/LDClient-big-segments-test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
const { hashForUserKey } = require('../big_segments');
const { makeBigSegmentRef } = require('../evaluator');
const InMemoryFeatureStore = require('../feature_store');
const dataKind = require('../versioned_data_kind');
const { TestData } = require('../integrations');
const stubs = require('./stubs');
const { makeSegmentMatchClause } = require('./evaluator_helpers');
const { promisifySingle, withCloseable } = require('launchdarkly-js-test-helpers');
const { withCloseable } = require('launchdarkly-js-test-helpers');

describe('LDClient - big segments', () => {

Expand All @@ -26,18 +25,16 @@ describe('LDClient - big segments', () => {
}

async function makeClient(bigSegmentsStore, config) {
const dataStore = InMemoryFeatureStore();
const initData = {
[dataKind.features.namespace]: { [flag.key]: flag },
[dataKind.segments.namespace]: { [bigSegment.key]: bigSegment },
};
await promisifySingle(dataStore.init)(initData);
const td = TestData();
td.usePreconfiguredFlag(flag);
td.usePreconfiguredSegment(bigSegment);

const bigSegmentsConfig = {
store: bigSegmentsStore && (() => bigSegmentsStore),
...(config && config.bigSegments),
};
return stubs.createClient({ ...config, featureStore: dataStore, bigSegments: bigSegmentsConfig });

return stubs.createClient({ ...config, updateProcessor: td, bigSegments: bigSegmentsConfig });
}

it('user not found in big segment store', async () => {
Expand Down
Loading

0 comments on commit 94af72c

Please sign in to comment.