Skip to content

Commit cf7ca15

Browse files
Fix manager tests
1 parent 08e1050 commit cf7ca15

2 files changed

Lines changed: 56 additions & 37 deletions

File tree

src/__tests__/consumer/browser_consumer.spec.js

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ const expectedSplitView = { name: 'hierarchical_splits_testing_on', trafficType:
1515
const wrapperPrefix = 'PLUGGABLE_STORAGE_UT';
1616
const wrapperInstance = inMemoryWrapperFactory();
1717
const TOTAL_RAW_IMPRESSIONS = 18;
18-
const TOTAL_RAW_IMPRESSIONS_IN_EVALUATIONS_WITH_FLAGSETS = 10;
1918
const TOTAL_EVENTS = 5;
2019
const DEDUPED_IMPRESSIONS = 2;
2120
const timeFrame = Date.now();
@@ -63,27 +62,16 @@ tape('Browser Consumer mode with pluggable storage', function (t) {
6362

6463
/** Evaluation, track and manager methods before SDK_READY */
6564

66-
const getTreatmentResult = client.getTreatment('UT_IN_SEGMENT');
67-
const getTreatmentsWithConfigByFlagSetsResult = client.getTreatmentsWithConfigByFlagSets(['set_a']);
68-
69-
const namesResult = manager.names();
70-
const splitResult = manager.split(expectedSplitName);
71-
const splitsResult = manager.splits();
72-
7365
assert.equal(client.__getStatus().isReadyFromCache, false, 'SDK in consumer mode is not operational inmediatelly');
7466
assert.equal(client.__getStatus().isReady, false, 'SDK in consumer mode is not operational inmediatelly');
75-
assert.equal(typeof getTreatmentResult.then, 'function', 'GetTreatment calls should always return a promise on Consumer mode.');
76-
assert.equal(await getTreatmentResult, 'control', 'Evaluations using pluggable storage should be control if initiated before SDK_READY.');
77-
assert.deepEqual(await getTreatmentsWithConfigByFlagSetsResult, {}, 'Flag sets evaluations using pluggable storage should be empty if initiated before SDK_READY.');
7867

79-
const trackResult = otherClient.track('user', 'test.event', 18);
80-
assert.equal(typeof trackResult.then, 'function', 'Track calls should always return a promise on Consumer mode.');
81-
assert.true(await trackResult, 'If the wrapper operation success to queue the event, the promise will resolve to true');
68+
client.getTreatment('UT_IN_SEGMENT').then(treatment => assert.equal(treatment, 'control', 'Evaluations using pluggable storage returns a promise that resolves to control if initiated before SDK_READY'));
69+
otherClient.track('user', 'test.event', 18).then(result => assert.true(result, 'Track calls returns a promise on consumer mode, that resolves to true if the wrapper push operation success to queue the event'));
8270

8371
// Manager methods
84-
assert.deepEqual(await namesResult, [], 'manager `names` method returns an empty list of split names if called before SDK_READY or wrapper operation fail');
85-
assert.deepEqual(await splitResult, null, 'manager `split` method returns a null split view if called before SDK_READY or wrapper operation fail');
86-
assert.deepEqual(await splitsResult, [], 'manager `splits` method returns an empty list of split views if called before SDK_READY or wrapper operation fail');
72+
manager.names().then(namesResult => assert.deepEqual(namesResult, [], 'manager `names` method returns a promise that resolved to an empty list of split names if called before SDK_READY or wrapper operation fail'));
73+
manager.split(expectedSplitName).then(splitResult => assert.deepEqual(splitResult, null, 'manager `split` method returns a promise that resolved to a null split view if called before SDK_READY or wrapper operation fail'));
74+
manager.splits().then(splitsResult => assert.deepEqual(splitsResult, [], 'manager `splits` method returns a promise that resolved to an empty list of split views if called before SDK_READY or wrapper operation fail'));
8775

8876
/** Evaluation, track and manager methods on SDK_READY */
8977

@@ -135,23 +123,13 @@ tape('Browser Consumer mode with pluggable storage', function (t) {
135123
assert.true(await client.track('user', 'test.event', 18), 'If the event was successfully queued the promise will resolve to true');
136124
assert.false(await client.track(), 'If the event was NOT successfully queued the promise will resolve to false');
137125

138-
// Evaluations with flag sets
139-
assert.deepEqual(await client.getTreatmentsByFlagSet('set_a'), { with_set_a: 'on', with_sets_a_b: 'on' }, 'Evaluations with getTreatmentsByFlagSet should be correct.');
140-
assert.deepEqual(await client.getTreatmentsByFlagSets(['set_a', 'set_b']), { with_set_a: 'on', with_set_b: 'on', with_sets_a_b: 'on' }, 'Evaluations with getTreatmentsByFlagSets should be correct.');
141-
assert.deepEqual(await client.getTreatmentsWithConfigByFlagSet('set_b'), { with_set_b: { treatment: 'on', config: '{}' }, with_sets_a_b: { treatment: 'on', config: null } }, 'Evaluations with getTreatmentsWithConfigByFlagSet should be correct.');
142-
assert.deepEqual(await client.getTreatmentsWithConfigByFlagSets(['set_a', 'set_b']), { with_set_a: { treatment: 'on', config: null }, with_set_b: { treatment: 'on', config: '{}' }, with_sets_a_b: { treatment: 'on', config: null } }, 'Evaluations with getTreatmentsWithConfigByFlagSets should be correct.');
143-
144-
assert.deepEqual(await client.getTreatmentsByFlagSet(), {}, 'Evaluations without flag set should be empty.');
145-
assert.deepEqual(await client.getTreatmentsByFlagSets([]), {}, 'Evaluations without flag sets should be empty.');
146-
assert.deepEqual(await client.getTreatmentsByFlagSets(['non_existent_set']), {}, 'Evaluations with non existent flag sets should be empty.');
147-
148126
// Manager methods
149127
const splitNames = await manager.names();
150-
assert.equal(splitNames.length, 28, 'manager `names` method returns the list of split names asynchronously');
128+
assert.equal(splitNames.length, 25, 'manager `names` method returns the list of split names asynchronously');
151129
assert.equal(splitNames.indexOf(expectedSplitName) > -1, true, 'list of split names should contain expected splits');
152130
assert.deepEqual(await manager.split(expectedSplitName), expectedSplitView, 'manager `split` method returns the split view of the given split name asynchronously');
153131
const splitViews = await manager.splits();
154-
assert.equal(splitViews.length, 28, 'manager `splits` method returns the list of split views asynchronously');
132+
assert.equal(splitViews.length, 25, 'manager `splits` method returns the list of split views asynchronously');
155133
assert.deepEqual(splitViews.find(splitView => splitView.name === expectedSplitName), expectedSplitView, 'manager `split` method returns the split view of the given split name asynchronously');
156134

157135
// New shared client created
@@ -173,7 +151,7 @@ tape('Browser Consumer mode with pluggable storage', function (t) {
173151
// Validate stored impressions and events
174152
const trackedImpressions = await wrapperInstance.popItems('PLUGGABLE_STORAGE_UT.SPLITIO.impressions', await wrapperInstance.getItemsCount('PLUGGABLE_STORAGE_UT.SPLITIO.impressions'));
175153
const trackedEvents = await wrapperInstance.popItems('PLUGGABLE_STORAGE_UT.SPLITIO.events', await wrapperInstance.getItemsCount('PLUGGABLE_STORAGE_UT.SPLITIO.events'));
176-
assert.equal(trackedImpressions.length, TOTAL_RAW_IMPRESSIONS + TOTAL_RAW_IMPRESSIONS_IN_EVALUATIONS_WITH_FLAGSETS, 'Tracked impressions should be present in the external storage');
154+
assert.equal(trackedImpressions.length, TOTAL_RAW_IMPRESSIONS, 'Tracked impressions should be present in the external storage');
177155
assert.equal(trackedEvents.length, TOTAL_EVENTS, 'Tracked events should be present in the external storage');
178156

179157
// Validate stored telemetry
@@ -186,7 +164,7 @@ tape('Browser Consumer mode with pluggable storage', function (t) {
186164

187165
// Assert impressionsListener
188166
setTimeout(() => {
189-
assert.equal(impressions.length, TOTAL_RAW_IMPRESSIONS + TOTAL_RAW_IMPRESSIONS_IN_EVALUATIONS_WITH_FLAGSETS, 'Each evaluation has its corresponding impression');
167+
assert.equal(impressions.length, TOTAL_RAW_IMPRESSIONS, 'Each evaluation has its corresponding impression');
190168
assert.equal(impressions[0].impression.label, SDK_NOT_READY, 'The first impression is control with label "sdk not ready"');
191169

192170
assert.end();

0 commit comments

Comments
 (0)