Skip to content

Commit 7d8a17d

Browse files
Fix manager tests in partial consumer mode
1 parent 5259039 commit 7d8a17d

1 file changed

Lines changed: 9 additions & 32 deletions

File tree

src/__tests__/consumer/browser_consumer_partial.spec.js

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +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 = 17;
18-
const TOTAL_RAW_IMPRESSIONS_IN_EVALUATIONS_WITH_FLAGSETS = 10;
19-
const TOTAL_OPTIMIZED_IMPRESSIONS_IN_EVALUATIONS_WITH_FLAGSETS = 3;
2018
const TOTAL_EVENTS = 5;
2119

2220
/** @type SplitIO.IBrowserAsyncSettings */
@@ -53,7 +51,7 @@ tape('Browser Consumer Partial mode with pluggable storage', function (t) {
5351
const resp = JSON.parse(req.body);
5452
assert.equal(resp.reduce((prev, cur) => {
5553
return prev + cur.i.length;
56-
}, 0), TOTAL_RAW_IMPRESSIONS - 1 + TOTAL_OPTIMIZED_IMPRESSIONS_IN_EVALUATIONS_WITH_FLAGSETS, 'Impressions were deduped');
54+
}, 0), TOTAL_RAW_IMPRESSIONS - 1, 'Impressions were deduped');
5755
return 200;
5856
});
5957

@@ -90,27 +88,16 @@ tape('Browser Consumer Partial mode with pluggable storage', function (t) {
9088

9189
/** Evaluation, track and manager methods before SDK_READY */
9290

93-
const getTreatmentResult = client.getTreatment('UT_IN_SEGMENT');
94-
const getTreatmentsWithConfigByFlagSetsResult = client.getTreatmentsWithConfigByFlagSets(['set_a']);
95-
96-
const namesResult = manager.names();
97-
const splitResult = manager.split(expectedSplitName);
98-
const splitsResult = manager.splits();
99-
10091
assert.equal(client.__getStatus().isReadyFromCache, false, 'SDK in consumer mode is not operational inmediatelly');
10192
assert.equal(client.__getStatus().isReady, false, 'SDK in consumer mode is not operational inmediatelly');
102-
assert.equal(typeof getTreatmentResult.then, 'function', 'GetTreatment calls should always return a promise on Consumer mode.');
103-
assert.equal(await getTreatmentResult, 'control', 'Evaluations using pluggable storage should be control if initiated before SDK_READY.');
104-
assert.deepEqual(await getTreatmentsWithConfigByFlagSetsResult, {}, 'Flag sets evaluations using pluggable storage should be empty if initiated before SDK_READY.');
10593

106-
const trackResult = otherClient.track('user', 'test.event', 18);
107-
assert.equal(typeof trackResult.then, 'function', 'Track calls should always return a promise on Consumer mode.');
108-
assert.true(await trackResult, 'If the wrapper operation success to queue the event, the promise will resolve to true');
94+
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'));
95+
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'));
10996

11097
// Manager methods
111-
assert.deepEqual(await namesResult, [], 'manager `names` method returns an empty list of split names if called before SDK_READY or wrapper operation fail');
112-
assert.deepEqual(await splitResult, null, 'manager `split` method returns a null split view if called before SDK_READY or wrapper operation fail');
113-
assert.deepEqual(await splitsResult, [], 'manager `splits` method returns an empty list of split views if called before SDK_READY or wrapper operation fail');
98+
manager.names().then(namesResult => assert.deepEqual(namesResult, [], 'manager `names` method returns an empty list of split names if called before SDK_READY or wrapper operation fail'));
99+
manager.split(expectedSplitName).then(splitResult => assert.deepEqual(splitResult, null, 'manager `split` method returns a null split view if called before SDK_READY or wrapper operation fail'));
100+
manager.splits().then(splitsResult => assert.deepEqual(splitsResult, [], 'manager `splits` method returns an empty list of split views if called before SDK_READY or wrapper operation fail'));
114101

115102
/** Evaluation, track and manager methods on SDK_READY */
116103

@@ -161,23 +148,13 @@ tape('Browser Consumer Partial mode with pluggable storage', function (t) {
161148
assert.true(await client.track('user', 'test.event', 18), 'If the event was successfully queued the promise will resolve to true');
162149
assert.false(await client.track(), 'If the event was NOT successfully queued the promise will resolve to false');
163150

164-
// Evaluations with flag sets
165-
assert.deepEqual(await client.getTreatmentsByFlagSet('set_a'), { with_set_a: 'on', with_sets_a_b: 'on' }, 'Evaluations with getTreatmentsByFlagSet should be correct.');
166-
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.');
167-
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.');
168-
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.');
169-
170-
assert.deepEqual(await client.getTreatmentsByFlagSet(), {}, 'Evaluations without flag set should be empty.');
171-
assert.deepEqual(await client.getTreatmentsByFlagSets([]), {}, 'Evaluations without flag sets should be empty.');
172-
assert.deepEqual(await client.getTreatmentsByFlagSets(['non_existent_set']), {}, 'Evaluations with non existent flag sets should be empty.');
173-
174151
// Manager methods
175152
const splitNames = await manager.names();
176-
assert.equal(splitNames.length, 28, 'manager `names` method returns the list of split names asynchronously');
153+
assert.equal(splitNames.length, 25, 'manager `names` method returns the list of split names asynchronously');
177154
assert.equal(splitNames.indexOf(expectedSplitName) > -1, true, 'list of split names should contain expected splits');
178155
assert.deepEqual(await manager.split(expectedSplitName), expectedSplitView, 'manager `split` method returns the split view of the given split name asynchronously');
179156
const splitViews = await manager.splits();
180-
assert.equal(splitViews.length, 28, 'manager `splits` method returns the list of split views asynchronously');
157+
assert.equal(splitViews.length, 25, 'manager `splits` method returns the list of split views asynchronously');
181158
assert.deepEqual(splitViews.find(splitView => splitView.name === expectedSplitName), expectedSplitView, 'manager `split` method returns the split view of the given split name asynchronously');
182159

183160
// New shared client created
@@ -201,7 +178,7 @@ tape('Browser Consumer Partial mode with pluggable storage', function (t) {
201178

202179
// Assert impressionsListener
203180
setTimeout(() => {
204-
assert.equal(impressions.length, TOTAL_RAW_IMPRESSIONS + TOTAL_RAW_IMPRESSIONS_IN_EVALUATIONS_WITH_FLAGSETS, 'Each evaluation has its corresponding impression');
181+
assert.equal(impressions.length, TOTAL_RAW_IMPRESSIONS, 'Each evaluation has its corresponding impression');
205182
assert.equal(impressions[0].impression.label, SDK_NOT_READY, 'The first impression is control with label "sdk not ready"');
206183

207184
assert.end();

0 commit comments

Comments
 (0)