-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3e49e70
commit f907103
Showing
5 changed files
with
33 additions
and
31 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]'; | ||
|
@@ -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]'; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
|
||
|
@@ -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 }); | ||
|
@@ -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 }); | ||
|
@@ -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.'); | ||
|
@@ -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' | ||
|
@@ -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(); | ||
}); | ||
|
||
|
@@ -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(); | ||
|
@@ -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(); | ||
}); | ||
|
@@ -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(); | ||
}); | ||
|
@@ -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(); | ||
}); | ||
|
@@ -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(); | ||
}); | ||
|
||
|
@@ -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(); | ||
}); | ||
|
@@ -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(); | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters