Skip to content

Commit 612a8c3

Browse files
Add tests
1 parent 2a783d6 commit 612a8c3

File tree

6 files changed

+70
-11
lines changed

6 files changed

+70
-11
lines changed

src/__tests__/browserSuites/evaluations.spec.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ export default function (config, fetchMock, assert) {
362362

363363
};
364364

365-
const evaluationsWithRuleBasedSegments = async (splitio) => {
365+
const evaluationsWithRuleBasedSegmentsAndPrerequisites = async (splitio) => {
366366
fetchMock.getOnce('https://sdk.split.io/api/memberships/emi%40split.io', { status: 200, body: { ms: { k: [{ n: 'segment_excluded_by_rbs' }] } } });
367367
fetchMock.getOnce('https://sdk.split.io/api/memberships/mauro%40split.io', { status: 200, body: { ms: {} } });
368368
fetchMock.getOnce('https://sdk.split.io/api/memberships/bilal%40split.io', { status: 200, body: { ms: {} } });
@@ -372,24 +372,28 @@ export default function (config, fetchMock, assert) {
372372
await client1.ready();
373373
assert.equal(client1.getTreatment('rbs_test_flag'), 'v2', 'key in excluded segment');
374374
assert.equal(client1.getTreatment('rbs_test_flag_negated'), 'v1', 'key in excluded segment');
375+
assert.equal(client1.getTreatment('always_on_if_prerequisite'), 'off', 'prerequisite not satisfied (key in excluded segment)');
375376
await client1.destroy();
376377

377378
const client2 = splitio.client('[email protected]');
378379
await client2.ready();
379380
assert.equal(client2.getTreatment('rbs_test_flag'), 'v2', 'excluded key');
380381
assert.equal(client2.getTreatment('rbs_test_flag_negated'), 'v1', 'excluded key');
382+
assert.equal(client2.getTreatment('always_on_if_prerequisite'), 'off', 'prerequisite not satisfied (excluded key)');
381383
await client2.destroy();
382384

383385
const client3 = splitio.client('[email protected]');
384386
await client3.ready();
385387
assert.equal(client3.getTreatment('rbs_test_flag'), 'v1', 'key satisfies the rbs condition');
386388
assert.equal(client3.getTreatment('rbs_test_flag_negated'), 'v2', 'key satisfies the rbs condition');
389+
assert.equal(client3.getTreatment('always_on_if_prerequisite'), 'on', 'prerequisite satisfied (key satisfies the rbs condition)');
387390
await client3.destroy();
388391

389392
const client4 = splitio.client('other_key');
390393
await client4.ready();
391394
assert.equal(client4.getTreatment('rbs_test_flag'), 'v2', 'key not in segment');
392395
assert.equal(client4.getTreatment('rbs_test_flag_negated'), 'v1', 'key not in segment');
396+
assert.equal(client4.getTreatment('always_on_if_prerequisite'), 'off', 'prerequisite not satisfied (key not in segment)');
393397
await client4.destroy();
394398
};
395399

@@ -408,7 +412,7 @@ export default function (config, fetchMock, assert) {
408412
getTreatmentsWithConfigTests(client);
409413
getTreatmentsWithInMemoryAttributes(client);
410414

411-
evaluationsWithRuleBasedSegments(splitio).then(() => {
415+
evaluationsWithRuleBasedSegmentsAndPrerequisites(splitio).then(() => {
412416
clientTABucket1.destroy();
413417
client.destroy();
414418
tested++;

src/__tests__/browserSuites/ready-from-cache.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ export default function (fetchMock, assert) {
818818
});
819819

820820
await client.ready();
821-
t.equal(manager.names().sort().length, 35, 'active splits should be present for evaluation');
821+
t.equal(manager.names().sort().length, 36, 'active splits should be present for evaluation');
822822

823823
await splitio.destroy();
824824
t.equal(localStorage.getItem('readyFromCache_10.SPLITIO.splits.till'), '1457552620999', 'splits.till must correspond to the till of the last successfully fetched Splits');
@@ -835,7 +835,7 @@ export default function (fetchMock, assert) {
835835

836836
await new Promise(res => client.once(client.Event.SDK_READY_FROM_CACHE, res));
837837

838-
t.equal(manager.names().sort().length, 35, 'active splits should be present for evaluation');
838+
t.equal(manager.names().sort().length, 36, 'active splits should be present for evaluation');
839839
t.false(console.log.calledWithMatch('clearOnInit was set and cache was not cleared in the last 24 hours. Cleaning up cache'), 'It should log a message about cleaning up cache');
840840

841841
await splitio.destroy();
@@ -856,7 +856,7 @@ export default function (fetchMock, assert) {
856856

857857
await new Promise(res => client.once(client.Event.SDK_READY, res));
858858

859-
t.equal(manager.names().sort().length, 35, 'active splits should be present for evaluation');
859+
t.equal(manager.names().sort().length, 36, 'active splits should be present for evaluation');
860860
t.true(console.log.calledWithMatch('clearOnInit was set and cache was not cleared in the last 24 hours. Cleaning up cache'), 'It should log a message about cleaning up cache');
861861

862862
await splitio.destroy();

src/__tests__/browserSuites/telemetry.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export default async function telemetryBrowserSuite(fetchMock, t) {
7676

7777
// @TODO check if iDe value is correct
7878
assert.deepEqual(data, {
79-
mE: {}, hE: { sp: { 500: 1 }, ms: { 500: 1 } }, tR: 0, aR: 0, iQ: 4, iDe: 1, iDr: 0, spC: 35, seC: 1, skC: 1, eQ: 1, eD: 0, sE: [], t: [], ufs: {}
79+
mE: {}, hE: { sp: { 500: 1 }, ms: { 500: 1 } }, tR: 0, aR: 0, iQ: 4, iDe: 1, iDr: 0, spC: 36, seC: 1, skC: 1, eQ: 1, eD: 0, sE: [], t: [], ufs: {}
8080
}, 'metrics/usage JSON payload should be the expected');
8181

8282
finish.next();
@@ -96,7 +96,7 @@ export default async function telemetryBrowserSuite(fetchMock, t) {
9696
// @TODO check if iDe value is correct
9797
assert.deepEqual(data, {
9898
mL: {}, mE: {}, hE: {}, hL: {}, // errors and latencies were popped
99-
tR: 0, aR: 0, iQ: 4, iDe: 1, iDr: 0, spC: 35, seC: 1, skC: 1, eQ: 1, eD: 0, sE: [], t: [], ufs: {}
99+
tR: 0, aR: 0, iQ: 4, iDe: 1, iDr: 0, spC: 36, seC: 1, skC: 1, eQ: 1, eD: 0, sE: [], t: [], ufs: {}
100100
}, '2nd metrics/usage JSON payload should be the expected');
101101
return 200;
102102
});

src/__tests__/mocks/splitchanges.since.-1.json

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@
99
"status": "ACTIVE",
1010
"trafficTypeName": "user",
1111
"excluded": {
12-
13-
"segments": [ "segment_excluded_by_rbs" ]
12+
"keys": [
13+
14+
15+
],
16+
"segments": [
17+
"segment_excluded_by_rbs"
18+
]
1419
},
1520
"conditions": [
1621
{
@@ -1730,6 +1735,52 @@
17301735
"configurations": {},
17311736
"sets": [],
17321737
"impressionsDisabled": false
1738+
},
1739+
{
1740+
"orgId": null,
1741+
"environment": null,
1742+
"trafficTypeId": null,
1743+
"trafficTypeName": null,
1744+
"name": "always_on_if_prerequisite",
1745+
"seed": -790401604,
1746+
"status": "ACTIVE",
1747+
"killed": false,
1748+
"defaultTreatment": "off",
1749+
"prerequisites": [
1750+
{
1751+
"n": "rbs_test_flag",
1752+
"ts": [
1753+
"v1"
1754+
]
1755+
}
1756+
],
1757+
"conditions": [
1758+
{
1759+
"matcherGroup": {
1760+
"combiner": "AND",
1761+
"matchers": [
1762+
{
1763+
"keySelector": {
1764+
"trafficType": "user",
1765+
"attribute": null
1766+
},
1767+
"matcherType": "ALL_KEYS",
1768+
"negate": false,
1769+
"userDefinedSegmentMatcherData": null,
1770+
"whitelistMatcherData": null,
1771+
"unaryNumericMatcherData": null,
1772+
"betweenMatcherData": null
1773+
}
1774+
]
1775+
},
1776+
"partitions": [
1777+
{
1778+
"treatment": "on",
1779+
"size": 100
1780+
}
1781+
]
1782+
}
1783+
]
17331784
}
17341785
],
17351786
"s": -1,

src/__tests__/nodeSuites/evaluations.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ export default async function (config, key, assert) {
175175
assert.equal(client.getTreatment('[email protected]', 'rbs_test_flag_negated'), 'v1', 'excluded key');
176176
assert.equal(client.getTreatment('[email protected]', 'rbs_test_flag_negated'), 'v2', 'key satisfies the rbs condition');
177177
assert.equal(client.getTreatment('other_key', 'rbs_test_flag_negated'), 'v1', 'key not in segment');
178+
179+
// Prerequisites
180+
assert.equal(client.getTreatment('[email protected]', 'always_on_if_prerequisite'), 'on', 'prerequisite satisfied (key satisfies the rbs condition)');
181+
assert.equal(client.getTreatment('[email protected]', 'always_on_if_prerequisite'), 'off', 'prerequisite not satisfied (key in excluded segment)');
178182
};
179183

180184
const getTreatmentsTests = (client, sdkInstance) => {

src/__tests__/nodeSuites/telemetry.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export default async function telemetryNodejsSuite(key, fetchMock, assert) {
6666

6767
// @TODO check if iDe value is correct
6868
assert.deepEqual(data, {
69-
mE: {}, hE: { sp: { 500: 1 } }, tR: 0, aR: 0, iQ: 4, iDe: 1, iDr: 0, spC: 35, seC: 4, skC: 4, eQ: 1, eD: 0, sE: [], t: [], ufs: {}
69+
mE: {}, hE: { sp: { 500: 1 } }, tR: 0, aR: 0, iQ: 4, iDe: 1, iDr: 0, spC: 36, seC: 4, skC: 4, eQ: 1, eD: 0, sE: [], t: [], ufs: {}
7070
}, 'metrics/usage JSON payload should be the expected');
7171

7272
finish.next();
@@ -85,7 +85,7 @@ export default async function telemetryNodejsSuite(key, fetchMock, assert) {
8585
// @TODO check if iDe value is correct
8686
assert.deepEqual(data, {
8787
mL: {}, mE: {}, hE: {}, hL: {}, // errors and latencies were popped
88-
tR: 0, aR: 0, iQ: 4, iDe: 1, iDr: 0, spC: 35, seC: 4, skC: 4, eQ: 1, eD: 0, sE: [], t: [], ufs: {}
88+
tR: 0, aR: 0, iQ: 4, iDe: 1, iDr: 0, spC: 36, seC: 4, skC: 4, eQ: 1, eD: 0, sE: [], t: [], ufs: {}
8989
}, '2nd metrics/usage JSON payload should be the expected');
9090
return 200;
9191
});

0 commit comments

Comments
 (0)