Skip to content

Commit 5259039

Browse files
Add tests for flag sets evaluation in consumer mode
1 parent cf7ca15 commit 5259039

2 files changed

Lines changed: 118 additions & 45 deletions

File tree

src/__tests__/consumer/browser_consumer.spec.js

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import sinon from 'sinon';
33
import { inMemoryWrapperFactory } from '@splitsoftware/splitio-commons/src/storages/pluggable/inMemoryWrapper';
44
import { SDK_NOT_READY, EXCEPTION } from '@splitsoftware/splitio-commons/src/utils/labels';
55
import { truncateTimeFrame } from '@splitsoftware/splitio-commons/src/utils/time';
6-
import { applyOperations } from './wrapper-commands';
6+
import { applyOperations, OPERATIONS_FLAG_SETS } from './wrapper-commands';
77
import { nearlyEqual } from '../testUtils';
88
import { version } from '../../../package.json';
99

@@ -549,4 +549,77 @@ tape('Browser Consumer mode with pluggable storage', function (t) {
549549

550550
});
551551

552+
t.test('Getting treatments with flag sets', async assert => {
553+
const wrapperInstance = inMemoryWrapperFactory();
554+
await applyOperations(wrapperInstance, OPERATIONS_FLAG_SETS);
555+
556+
const sdk = SplitFactory({
557+
...config,
558+
storage: PluggableStorage({
559+
prefix: wrapperPrefix,
560+
wrapper: wrapperInstance
561+
})
562+
});
563+
564+
const client = sdk.client();
565+
const otherClient = sdk.client('emi@split');
566+
567+
client.getTreatmentsWithConfigByFlagSets('other', ['set_one']).then(result => assert.deepEqual(result, {}, 'Flag sets evaluations using pluggable storage should be empty until connection is ready.'));
568+
569+
await client.ready();
570+
await otherClient.ready();
571+
572+
assert.deepEqual(
573+
await client.getTreatmentsByFlagSet('set_one'),
574+
{ 'always-on': 'on', 'always-off': 'off' },
575+
'Evaluations using pluggable storage should be correct for a set.'
576+
);
577+
578+
assert.deepEqual(
579+
await otherClient.getTreatmentsWithConfigByFlagSet('set_one'),
580+
{ 'always-on': { treatment: 'on', config: null }, 'always-off': { treatment: 'off', config: null } },
581+
'Evaluations with configs using pluggable storage should be correct for a set.'
582+
);
583+
584+
assert.deepEqual(
585+
await client.getTreatmentsByFlagSet('set_two'),
586+
{ 'always-off': 'off', 'nico_not': 'off' },
587+
'Evaluations using Redipluggables storage should be correct for a set.'
588+
);
589+
590+
assert.deepEqual(
591+
await client.getTreatmentsByFlagSet('set_invalid'),
592+
{},
593+
'Evaluations using pluggable storage should properly handle all invalid sets.'
594+
);
595+
596+
assert.deepEqual(
597+
await client.getTreatmentsByFlagSets(['set_two', 'set_one']),
598+
{ 'always-on': 'on', 'always-off': 'off', 'nico_not': 'off' },
599+
'Evaluations using pluggable storage should be correct for multiple sets.'
600+
);
601+
602+
assert.deepEqual(
603+
await client.getTreatmentsWithConfigByFlagSets(['set_two', 'set_one']),
604+
{ 'always-on': { treatment: 'on', config: null }, 'always-off': { treatment: 'off', config: null }, 'nico_not': { treatment: 'off', config: '{"text":"Gallardiola"}' } },
605+
'Evaluations with configs using pluggable storage should be correct for multiple sets.'
606+
);
607+
608+
assert.deepEqual(
609+
await client.getTreatmentsByFlagSets([243, null, 'set_two', 'set_one', 'invalid_set']),
610+
{ 'always-on': 'on', 'always-off': 'off', 'nico_not': 'off' },
611+
'Evaluations using pluggable storage should be correct for multiple sets, discarding invalids.'
612+
);
613+
614+
assert.deepEqual(
615+
await otherClient.getTreatmentsByFlagSets([243, null, 'invalid_set']),
616+
{},
617+
'Evaluations using pluggable storage should properly handle all invalid sets.'
618+
);
619+
620+
await otherClient.destroy();
621+
await client.destroy();
622+
623+
assert.end();
624+
});
552625
});

0 commit comments

Comments
 (0)