Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilianoSanchez committed Dec 11, 2023
1 parent 3e49e70 commit f907103
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 31 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"node": ">=6"
},
"dependencies": {
"@splitsoftware/splitio-commons": "1.12.1-rc.6",
"@splitsoftware/splitio-commons": "1.12.1-rc.7",
"@types/google.analytics": "0.0.40",
"@types/ioredis": "^4.28.0",
"bloom-filters": "^3.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/browserSuites/push-corner-cases.spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getStorageHash } from '@splitsoftware/splitio-commons/src/storages/KeyBuilder';
import splitChangesMock1 from '../mocks/splitchanges.since.-1.json';
import splitKillMessage from '../mocks/message.SPLIT_KILL.1457552650000.json';
import authPushEnabledNicolas from '../mocks/[email protected]';
Expand All @@ -9,7 +10,6 @@ window.EventSource = EventSourceMock;

import { SplitFactory } from '../../';
import { settingsFactory } from '../../settings';
import { getStorageHash } from '@splitsoftware/splitio-commons/src/storages/KeyBuilder';

const userKey = '[email protected]';

Expand Down
44 changes: 23 additions & 21 deletions src/__tests__/browserSuites/ready-from-cache.spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { getStorageHash } from '@splitsoftware/splitio-commons/src/storages/KeyBuilder';
import { SplitFactory } from '../../';

import splitChangesMock1 from '../mocks/splitchanges.since.-1.json';
import splitChangesMock2 from '../mocks/splitchanges.since.1457552620999.json';
import mySegmentsNicolas from '../mocks/[email protected]';
import { getStorageHash } from '@splitsoftware/splitio-commons/src/storages/KeyBuilder';

import { nearlyEqual } from '../testUtils';

Expand Down Expand Up @@ -256,7 +256,7 @@ export default function (fetchMock, assert) {
t.plan(12 * 2 + 5);

fetchMock.get(testUrls.sdk + '/splitChanges?since=25', function () {
t.equal(localStorage.getItem('readyFromCache_3.SPLITIO.split.always_on'), alwaysOnSplitInverted, 'splits must not be cleaned from cache');
t.equal(localStorage.getItem('readyFromCache_3.SPLITIO.split.always_on'), alwaysOnSplitInverted, 'feature flags must not be cleaned from cache');
return new Promise(res => { setTimeout(() => res({ status: 200, body: { ...splitChangesMock1, since: 25 }, headers: {} }), 200); }); // 400ms is how long it'll take to reply with Splits, no SDK_READY should be emitted before that.
});
fetchMock.get(testUrls.sdk + '/splitChanges?since=1457552620999', { status: 200, body: splitChangesMock2 });
Expand Down Expand Up @@ -371,11 +371,11 @@ export default function (fetchMock, assert) {
events: 'https://events.baseurl/readyFromCacheWithData4'
};
localStorage.clear();
t.plan(9 * 2 + 5);

fetchMock.get(testUrls.sdk + '/splitChanges?since=-1', function () {
t.equal(localStorage.getItem('some_user_item'), 'user_item', 'user items at localStorage must not be changed');
t.equal(localStorage.length, 1, 'split cache data must be cleaned from localStorage');
t.equal(localStorage.getItem('readyFromCache_4.SPLITIO.hash'), expectedHashNullFilter, 'storage hash must not be changed');
t.equal(localStorage.length, 2, 'feature flags cache data must be cleaned from localStorage');
return { status: 200, body: splitChangesMock1 };
});
fetchMock.get(testUrls.sdk + '/splitChanges?since=1457552620999', { status: 200, body: splitChangesMock2 });
Expand Down Expand Up @@ -461,6 +461,8 @@ export default function (fetchMock, assert) {
t.equal(localStorage.getItem('some_user_item'), 'user_item', 'user items at localStorage must not be changed');
t.equal(localStorage.getItem('readyFromCache_4.SPLITIO.splits.till'), '1457552620999', 'splits.till must correspond to the till of the last successfully fetched Splits');
t.true(nearlyEqual(parseInt(localStorage.getItem('readyFromCache_4.SPLITIO.splits.lastUpdated')), Date.now() - 1000 /* 1000 ms between last Split and MySegments fetch */), 'lastUpdated must correspond to the timestamp of the last successfully fetched Splits');

t.end();
});
});
t.true(Date.now() - startTime >= 1000, 'It should emit SDK_READY after syncing with the cloud.');
Expand All @@ -478,7 +480,7 @@ export default function (fetchMock, assert) {

/** Fetch specific splits **/

assert.test(t => { // Testing when we start with cached data but without storage hash (JS SDK version 10.24.0 and below), and a valid split filter config
assert.test(t => { // Testing when we start with cached data but without storage hash (JS SDK <=v10.24.0 and Browser SDK <=v0.12.0), and a valid split filter config
const testUrls = {
sdk: 'https://sdk.baseurl/readyFromCache_5',
events: 'https://events.baseurl/readyFromCache_5'
Expand Down Expand Up @@ -512,7 +514,7 @@ export default function (fetchMock, assert) {
const manager = splitio.manager();

client.once(client.Event.SDK_READY_FROM_CACHE, () => {
t.fail('It should not emit SDK_READY_FROM_CACHE because localstorage is cleaned and there isn\'t cached data');
t.fail('It should not emit SDK_READY_FROM_CACHE because localStorage is cleaned and there isn\'t cached feature flags');
t.end();
});

Expand All @@ -522,8 +524,8 @@ export default function (fetchMock, assert) {
client.destroy().then(() => {
t.equal(localStorage.getItem('some_user_item'), 'user_item', 'user items at localStorage must not be changed');
t.equal(localStorage.getItem('readyFromCache_5.SPLITIO.splits.till'), '1457552620999', 'splits.till must correspond to the till of the last successfully fetched Splits');
t.equal(localStorage.getItem('readyFromCache_5.SPLITIO.split.p1__split'), JSON.stringify(splitDeclarations.p1__split), 'split declarations must be cached');
t.equal(localStorage.getItem('readyFromCache_5.SPLITIO.split.p2__split'), JSON.stringify(splitDeclarations.p2__split), 'split declarations must be cached');
t.equal(localStorage.getItem('readyFromCache_5.SPLITIO.split.p1__split'), JSON.stringify(splitDeclarations.p1__split), 'feature flag declarations must be cached');
t.equal(localStorage.getItem('readyFromCache_5.SPLITIO.split.p2__split'), JSON.stringify(splitDeclarations.p2__split), 'feature flag declarations must be cached');
t.equal(localStorage.getItem('readyFromCache_5.SPLITIO.hash'), expectedHashWithFilter, 'Storage hash must correspond to the one for the SDK key and feature flag filter query');
t.equal(localStorage.getItem('readyFromCache_5.SPLITIO.splits.filterQuery'), null);
t.end();
Expand Down Expand Up @@ -567,8 +569,8 @@ export default function (fetchMock, assert) {

client.destroy().then(() => {
t.equal(localStorage.getItem('readyFromCache_5B.SPLITIO.splits.till'), '1457552620999', 'splits.till must correspond to the till of the last successfully fetched Splits');
t.equal(localStorage.getItem('readyFromCache_5B.SPLITIO.split.p1__split'), JSON.stringify(splitDeclarations.p1__split), 'split declarations must be cached');
t.equal(localStorage.getItem('readyFromCache_5B.SPLITIO.split.p2__split'), JSON.stringify(splitDeclarations.p2__split), 'split declarations must be cached');
t.equal(localStorage.getItem('readyFromCache_5B.SPLITIO.split.p1__split'), JSON.stringify(splitDeclarations.p1__split), 'feature flag declarations must be cached');
t.equal(localStorage.getItem('readyFromCache_5B.SPLITIO.split.p2__split'), JSON.stringify(splitDeclarations.p2__split), 'feature flag declarations must be cached');
t.equal(localStorage.getItem('readyFromCache_5B.SPLITIO.hash'), expectedHashWithFilter, 'Storage hash must correspond to the split filter query and SDK key');
t.end();
});
Expand Down Expand Up @@ -618,8 +620,8 @@ export default function (fetchMock, assert) {
client.destroy().then(() => {
t.equal(localStorage.getItem('some_user_item'), 'user_item', 'user items at localStorage must not be changed');
t.equal(localStorage.getItem('readyFromCache_6.SPLITIO.splits.till'), '1457552620999', 'splits.till must correspond to the till of the last successfully fetched Splits');
t.equal(localStorage.getItem('readyFromCache_6.SPLITIO.split.p1__split'), JSON.stringify(splitDeclarations.p1__split), 'split declarations must be cached');
t.equal(localStorage.getItem('readyFromCache_6.SPLITIO.split.p2__split'), JSON.stringify(splitDeclarations.p2__split), 'split declarations must be cached');
t.equal(localStorage.getItem('readyFromCache_6.SPLITIO.split.p1__split'), JSON.stringify(splitDeclarations.p1__split), 'feature flag declarations must be cached');
t.equal(localStorage.getItem('readyFromCache_6.SPLITIO.split.p2__split'), JSON.stringify(splitDeclarations.p2__split), 'feature flag declarations must be cached');
t.equal(localStorage.getItem('readyFromCache_6.SPLITIO.hash'), expectedHash, 'Storage hash must correspond to the split filter query and SDK key');
t.end();
});
Expand Down Expand Up @@ -671,8 +673,8 @@ export default function (fetchMock, assert) {
client.destroy().then(() => {
t.equal(localStorage.getItem('some_user_item'), 'user_item', 'user items at localStorage must not be changed');
t.equal(localStorage.getItem('readyFromCache_7.SPLITIO.splits.till'), '1457552620999', 'splits.till must correspond to the till of the last successfully fetched Splits');
t.equal(localStorage.getItem('readyFromCache_7.SPLITIO.split.p1__split'), JSON.stringify(splitDeclarations.p1__split), 'split declarations must be cached');
t.equal(localStorage.getItem('readyFromCache_7.SPLITIO.split.p2__split'), JSON.stringify(splitDeclarations.p2__split), 'split declarations must be cached');
t.equal(localStorage.getItem('readyFromCache_7.SPLITIO.split.p1__split'), JSON.stringify(splitDeclarations.p1__split), 'feature flag declarations must be cached');
t.equal(localStorage.getItem('readyFromCache_7.SPLITIO.split.p2__split'), JSON.stringify(splitDeclarations.p2__split), 'feature flag declarations must be cached');
t.equal(localStorage.getItem('readyFromCache_7.SPLITIO.hash'), expectedHash, 'Storage hash must correspond to the split filter query and SDK key');
t.end();
});
Expand Down Expand Up @@ -724,7 +726,7 @@ export default function (fetchMock, assert) {
const manager = splitio.manager();

client.once(client.Event.SDK_READY_FROM_CACHE, () => {
t.fail('It should not emit SDK_READY_FROM_CACHE because all splits were removed from cache since the filter query changed.');
t.fail('It should not emit SDK_READY_FROM_CACHE because all feature flags were removed from cache since the filter query changed.');
t.end();
});

Expand All @@ -734,9 +736,9 @@ export default function (fetchMock, assert) {
client.destroy().then(() => {
t.equal(localStorage.getItem('some_user_item'), 'user_item', 'user items at localStorage must not be changed');
t.equal(localStorage.getItem('readyFromCache_8.SPLITIO.splits.till'), '1457552620999', 'splits.till must correspond to the till of the last successfully fetched Splits');
t.equal(localStorage.getItem('readyFromCache_8.SPLITIO.split.p1__split'), JSON.stringify(splitDeclarations.p1__split), 'split declarations must be cached');
t.equal(localStorage.getItem('readyFromCache_8.SPLITIO.split.p2__split'), JSON.stringify(splitDeclarations.p2__split), 'split declarations must be cached');
t.equal(localStorage.getItem('readyFromCache_8.SPLITIO.split.p3__split'), JSON.stringify(splitDeclarations.p3__split), 'split declarations must be cached');
t.equal(localStorage.getItem('readyFromCache_8.SPLITIO.split.p1__split'), JSON.stringify(splitDeclarations.p1__split), 'feature flag declarations must be cached');
t.equal(localStorage.getItem('readyFromCache_8.SPLITIO.split.p2__split'), JSON.stringify(splitDeclarations.p2__split), 'feature flag declarations must be cached');
t.equal(localStorage.getItem('readyFromCache_8.SPLITIO.split.p3__split'), JSON.stringify(splitDeclarations.p3__split), 'feature flag declarations must be cached');
t.equal(localStorage.getItem('readyFromCache_8.SPLITIO.hash'), expectedHashNullFilter, 'Storage hash must correspond to the split filter query and SDK key');
t.end();
});
Expand Down Expand Up @@ -784,9 +786,9 @@ export default function (fetchMock, assert) {
client.destroy().then(() => {
t.equal(localStorage.getItem('some_user_item'), 'user_item', 'user items at localStorage must not be changed');
t.equal(localStorage.getItem('readyFromCache_9.SPLITIO.splits.till'), '1457552620999', 'splits.till must correspond to the till of the last successfully fetched Splits');
t.equal(localStorage.getItem('readyFromCache_9.SPLITIO.split.p2__split'), JSON.stringify(splitDeclarations.p2__split), 'split declarations must be cached');
t.equal(localStorage.getItem('readyFromCache_9.SPLITIO.split.p3__split'), JSON.stringify(splitDeclarations.p3__split), 'split declarations must be cached');
t.equal(localStorage.getItem('readyFromCache_9.SPLITIO.hash'), getStorageHash({ ...baseConfig, sync: { __splitFiltersValidation: { queryString: '&names=no%20exist%20trim,no_exist,p3__split&prefixes=no%20exist%20trim,p2' } } }), 'splits.filterQuery must correspond to the split filter query');
t.equal(localStorage.getItem('readyFromCache_9.SPLITIO.split.p2__split'), JSON.stringify(splitDeclarations.p2__split), 'feature flag declarations must be cached');
t.equal(localStorage.getItem('readyFromCache_9.SPLITIO.split.p3__split'), JSON.stringify(splitDeclarations.p3__split), 'feature flag declarations must be cached');
t.equal(localStorage.getItem('readyFromCache_9.SPLITIO.hash'), getStorageHash({ ...baseConfig, sync: { __splitFiltersValidation: { queryString: '&names=no%20exist%20trim,no_exist,p3__split&prefixes=no%20exist%20trim,p2' } } }), 'Storage hash must correspond to the split filter query and SDK key');
t.end();
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/errorCatching/browser.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Here we are testing exceptions and the handler should be ours, we need to avoid tape-catch
import { getStorageHash } from '@splitsoftware/splitio-commons/src/storages/KeyBuilder';
import tape from 'tape';
import includes from 'lodash/includes';
import fetchMock from '../testUtils/fetchMock';
Expand All @@ -9,7 +10,6 @@ import splitChangesMock2 from '../mocks/splitChanges.since.1500492097547.till.15
import splitChangesMock3 from '../mocks/splitChanges.since.1500492297547.json';
import { SplitFactory } from '../../';
import { settingsFactory } from '../../settings';
import { getStorageHash } from '@splitsoftware/splitio-commons/src/storages/KeyBuilder';

const settings = settingsFactory({
core: {
Expand Down

0 comments on commit f907103

Please sign in to comment.