Skip to content
Open
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
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@splitsoftware/splitio",
"version": "11.8.0",
"version": "11.8.1-rc.1",
"description": "Split SDK",
"files": [
"README.md",
Expand Down Expand Up @@ -38,7 +38,7 @@
"node": ">=14.0.0"
},
"dependencies": {
"@splitsoftware/splitio-commons": "2.8.0",
"@splitsoftware/splitio-commons": "2.8.1-rc.1",
"bloom-filters": "^3.0.4",
"ioredis": "^4.28.0",
"js-yaml": "^3.13.1",
Expand Down
26 changes: 22 additions & 4 deletions src/__tests__/consumer/node_redis.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const expectedImpressionCount = [
`UT_SET_MATCHER::${truncateTimeFrame(timeFrame)}`, '2',
`UT_NOT_SET_MATCHER::${truncateTimeFrame(timeFrame)}`, '3',
`always-o.n-with-config::${truncateTimeFrame(timeFrame)}`, '1',
`always-on::${truncateTimeFrame(timeFrame)}`, '1',
`always-on::${truncateTimeFrame(timeFrame)}`, '5',
`hierarchical_splits_testing_on::${truncateTimeFrame(timeFrame)}`, '1',
`hierarchical_splits_testing_off::${truncateTimeFrame(timeFrame)}`, '1',
`hierarchical_splits_testing_on_negated::${truncateTimeFrame(timeFrame)}`, '1',
Expand Down Expand Up @@ -158,6 +158,12 @@ tape('Node.js Redis', function (t) {
assert.equal(await client.getTreatment('UT_Segment_member', 'hierarchical_splits_testing_on_negated'), 'off', 'Evaluations using Redis storage should be correct.');
assert.equal(await client.getTreatment('other_key', 'always-on-impressions-disabled-true'), 'on', 'Evaluations using Redis storage should be correct.');

// Verify impressionsDisabled option
assert.deepEqual(await client.getTreatment('other_key', 'always-on', undefined, { impressionsDisabled: true }), 'on', 'Evaluations with impressionsDisabled: true should be correct.');
assert.deepEqual(await client.getTreatmentWithConfig('other_key', 'always-on', undefined, { impressionsDisabled: true }), { treatment: 'on', config: null }, 'Evaluations with impressionsDisabled: true should be correct.');
assert.deepEqual(await client.getTreatments('other_key', ['always-on'], undefined, { impressionsDisabled: true }), { 'always-on': 'on' }, 'Evaluations with impressionsDisabled: true should be correct.');
assert.deepEqual(await client.getTreatmentsWithConfig('other_key', ['always-on'], undefined, { impressionsDisabled: true }), { 'always-on': { treatment: 'on', config: null } }, 'Evaluations with impressionsDisabled: true should be correct.');

// Evaluations with rule-based segments
assert.equal(await client.getTreatment('emi@split.io', 'rbs_test_flag'), 'v2', 'key in excluded segment');
assert.equal(await client.getTreatment('mauro@split.io', 'rbs_test_flag'), 'v2', 'excluded key');
Expand Down Expand Up @@ -189,11 +195,11 @@ tape('Node.js Redis', function (t) {
// Validate Impression Counts and Unique Keys for 'always-on-impressions-disabled-true'
exec(`echo "HGETALL ${config.storage.prefix}.SPLITIO.impressions.count" | redis-cli -p ${redisPort}`, async (error, stdout) => {
const trackedImpressionCounts = stdout.split('\n').filter(line => line !== '');
assert.deepEqual(trackedImpressionCounts, [`always-on-impressions-disabled-true::${truncateTimeFrame(timeFrame)}`, '1',], 'Tracked impression counts should be stored in Redis TODO');
assert.deepEqual(trackedImpressionCounts, [`always-on-impressions-disabled-true::${truncateTimeFrame(timeFrame)}`, '1',`always-on::${truncateTimeFrame(timeFrame)}`, '4',], 'Tracked impression counts should be stored in Redis TODO');

exec(`echo "LRANGE ${config.storage.prefix}.SPLITIO.uniquekeys 0 20" | redis-cli -p ${redisPort}`, async (error, stdout) => {
const storedUniqueKeys = stdout.split('\n').filter(line => line !== '').map(JSON.parse);
assert.deepEqual(storedUniqueKeys, [{ 'f': 'always-on-impressions-disabled-true', 'ks': ['other_key'] }], 'Unique keys should be stored in Redis TODO');
assert.deepEqual(storedUniqueKeys, [{ 'f': 'always-on-impressions-disabled-true', 'ks': ['other_key'] }, { f: 'always-on', ks: [ 'other_key' ] }], 'Unique keys should be stored in Redis TODO');

// Validate stored impressions and events
exec(`echo "LLEN ${config.storage.prefix}.SPLITIO.impressions \n LLEN ${config.storage.prefix}.SPLITIO.events" | redis-cli -p ${redisPort}`, (error, stdout) => {
Expand Down Expand Up @@ -308,6 +314,12 @@ tape('Node.js Redis', function (t) {
// this should be deduped
assert.equal(await client.getTreatment('UT_Segment_member', 'hierarchical_splits_testing_on_negated'), 'off', 'Evaluations using Redis storage should be correct.');

// Verify impressionsDisabled option
assert.deepEqual(await client.getTreatment('other_key', 'always-on', undefined, { impressionsDisabled: true }), 'on', 'Evaluations with impressionsDisabled: true should be correct.');
assert.deepEqual(await client.getTreatmentWithConfig('other_key', 'always-on', undefined, { impressionsDisabled: true }), { treatment: 'on', config: null }, 'Evaluations with impressionsDisabled: true should be correct.');
assert.deepEqual(await client.getTreatments('other_key', ['always-on'], undefined, { impressionsDisabled: true }), { 'always-on': 'on' }, 'Evaluations with impressionsDisabled: true should be correct.');
assert.deepEqual(await client.getTreatmentsWithConfig('other_key', ['always-on'], undefined, { impressionsDisabled: true }), { 'always-on': { treatment: 'on', config: null } }, 'Evaluations with impressionsDisabled: true should be correct.');

assert.equal(typeof client.track('nicolas@split.io', 'user', 'test.redis.event', 18).then, 'function', 'Track calls should always return a promise on Redis mode.');
assert.equal(typeof client.track().then, 'function', 'Track calls should always return a promise on Redis mode, even when parameters are incorrect.');

Expand Down Expand Up @@ -357,7 +369,7 @@ tape('Node.js Redis', function (t) {
{ 'f': 'UT_SET_MATCHER', 'ks': ['UT_Segment_member'] },
{ 'f': 'UT_NOT_SET_MATCHER', 'ks': ['UT_Segment_member'] },
{ 'f': 'always-o.n-with-config', 'ks': ['UT_Segment_member'] },
{ 'f': 'always-on', 'ks': ['UT_Segment_member'] },
{ 'f': 'always-on', 'ks': ['UT_Segment_member', 'other_key'] },
{ 'f': 'hierarchical_splits_testing_on', 'ks': ['UT_Segment_member'] },
{ 'f': 'hierarchical_splits_testing_off', 'ks': ['UT_Segment_member'] },
{ 'f': 'hierarchical_splits_testing_on_negated', 'ks': ['UT_Segment_member'] },
Expand Down Expand Up @@ -404,6 +416,12 @@ tape('Node.js Redis', function (t) {
assert.equal(await client.getTreatment('UT_Segment_member', 'hierarchical_splits_testing_off'), 'off', 'Evaluations using Redis storage should be correct.');
assert.equal(await client.getTreatment('UT_Segment_member', 'hierarchical_splits_testing_on_negated'), 'off', 'Evaluations using Redis storage should be correct.');

// Verify impressionsDisabled option
assert.deepEqual(await client.getTreatment('other_key', 'always-on', undefined, { impressionsDisabled: true }), 'on', 'Evaluations with impressionsDisabled: true should be correct.');
assert.deepEqual(await client.getTreatmentWithConfig('other_key', 'always-on', undefined, { impressionsDisabled: true }), { treatment: 'on', config: null }, 'Evaluations with impressionsDisabled: true should be correct.');
assert.deepEqual(await client.getTreatments('other_key', ['always-on'], undefined, { impressionsDisabled: true }), { 'always-on': 'on' }, 'Evaluations with impressionsDisabled: true should be correct.');
assert.deepEqual(await client.getTreatmentsWithConfig('other_key', ['always-on'], undefined, { impressionsDisabled: true }), { 'always-on': { treatment: 'on', config: null } }, 'Evaluations with impressionsDisabled: true should be correct.');

assert.equal(typeof client.track('nicolas@split.io', 'user', 'test.redis.event', 18).then, 'function', 'Track calls should always return a promise on Redis mode.');
assert.equal(typeof client.track().then, 'function', 'Track calls should always return a promise on Redis mode, even when parameters are incorrect.');

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { SplitFactory } from '../..';
import { settingsFactory } from '../../settings';
import splitChangesMock1 from '../mocks/splitchanges.since.-1.json';
import { url } from '../testUtils';

const baseUrls = {
sdk: 'https://sdk.baseurl/evaluationsImpressionsDisabledSuite',
events: 'https://events.baseurl/evaluationsImpressionsDisabledSuite',
telemetry: 'https://telemetry.baseurl/evaluationsImpressionsDisabledSuite'
};

const settings = settingsFactory({
core: {
key: '<fake id>'
},
urls: baseUrls,
streamingEnabled: false
});

const config = {
core: {
authorizationKey: '<fake-token>'
},
urls: baseUrls,
streamingEnabled: false
};

export default async function (fetchMock, assert) {

assert.test('Evaluations / impressionsDisabled option', async t => {
// Mocking split changes
fetchMock.getOnce(url(settings, '/splitChanges?s=1.3&since=-1&rbSince=-1'), { status: 200, body: splitChangesMock1 });
fetchMock.get(new RegExp(`${url(settings, '/segmentChanges/')}.*`), { status: 200, body: { since: 10, till: 10, name: 'segmentName', added: [], removed: [] } });
fetchMock.post(url(settings, '/v1/keys/ss'), 200);
fetchMock.post(url(settings, '/v1/metrics/usage'), 200);
fetchMock.post(url(settings, '/v1/metrics/config'), 200);
// Mock default telemetry URLs as fallback
fetchMock.post('https://telemetry.split.io/api/v1/keys/ss', 200);
fetchMock.post('https://telemetry.split.io/api/v1/metrics/usage', 200);
fetchMock.post('https://telemetry.split.io/api/v1/metrics/usage', 200);
fetchMock.post('https://telemetry.split.io/api/v1/metrics/config', 200);

fetchMock.post(url(settings, '/testImpressions/bulk'), 200);
fetchMock.post(url(settings, '/testImpressions/count'), 200);

const splitio = SplitFactory(config);
const client = splitio.client();

await client.ready();

// getTreatment
t.equal(client.getTreatment('emi@split.io', 'split_with_config', { impressionsDisabled: true }), 'o.n', 'getTreatment with impressionsDisabled: true returns correct treatment');
t.equal(client.getTreatment('emi@split.io', 'split_with_config', { impressionsDisabled: false }), 'o.n', 'getTreatment with impressionsDisabled: false returns correct treatment');

// getTreatments
t.deepEqual(client.getTreatments('emi@split.io', ['split_with_config', 'whitelist'], { impressionsDisabled: true }), {
split_with_config: 'o.n',
whitelist: 'not_allowed'
}, 'getTreatments with impressionsDisabled: true returns correct treatments');

// getTreatmentWithConfig
const expectedConfig = '{"color":"brown","dimensions":{"height":12,"width":14},"text":{"inner":"click me"}}';
t.deepEqual(client.getTreatmentWithConfig('emi@split.io', 'split_with_config', { impressionsDisabled: true }), {
treatment: 'o.n',
config: expectedConfig
}, 'getTreatmentWithConfig with impressionsDisabled: true returns correct treatment and config');

// getTreatmentsWithConfig
t.deepEqual(client.getTreatmentsWithConfig('emi@split.io', ['split_with_config', 'whitelist'], { impressionsDisabled: true }), {
split_with_config: { treatment: 'o.n', config: expectedConfig },
whitelist: { treatment: 'not_allowed', config: null }
}, 'getTreatmentsWithConfig with impressionsDisabled: true returns correct treatments and configs');

await client.destroy();
t.end();
});
}
Loading