Skip to content

Commit 3b3b9b3

Browse files
committed
test: updated tests for batch uploader
1 parent 426f038 commit 3b3b9b3

1 file changed

Lines changed: 18 additions & 19 deletions

File tree

test/src/tests-batchUploader.ts

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,9 +1722,11 @@ describe('batch uploader', () => {
17221722
const batchStorageKey = 'mprtcl-v4_abcdef-batches';
17231723
beforeEach(() => {
17241724
window.mParticle._resetForTests(MPConfig);
1725+
window.localStorage.clear();
1726+
window.sessionStorage.clear();
17251727
});
17261728

1727-
it('should store batches in local storage when noFunctional is false by default', async () => {
1729+
it('should store batches in session storage when noFunctional is false by default', async () => {
17281730
window.mParticle.config.flags = {
17291731
offlineStorage: '100',
17301732
...enableBatchingConfigFlags,
@@ -1734,80 +1736,77 @@ describe('batch uploader', () => {
17341736
const mpInstance = window.mParticle.getInstance();
17351737
const uploader = mpInstance._APIClient.uploader;
17361738
uploader.queueEvent(event0);
1737-
expect(!!window.sessionStorage.getItem(eventStorageKey)).to.equal(true);
1739+
expect(window.sessionStorage.getItem(eventStorageKey)).to.not.equal(null);
17381740
});
17391741

17401742
it('should NOT store events in session storage when noFunctional is true', async () => {
17411743
window.mParticle.config.flags = {
17421744
offlineStorage: '100',
17431745
...enableBatchingConfigFlags,
17441746
};
1745-
window.mParticle.config.launcherOptions = {
1746-
noFunctional: true,
1747-
};
1747+
window.mParticle.config.noFunctional = true;
17481748
window.mParticle.init(apiKey, window.mParticle.config);
17491749
await waitForCondition(hasIdentifyReturned);
17501750
const mpInstance = window.mParticle.getInstance();
17511751
const uploader = mpInstance._APIClient.uploader;
17521752
uploader.queueEvent(event0);
1753-
expect(window.sessionStorage.getItem(eventStorageKey) === '').to.equal(true);
1753+
expect(window.sessionStorage.getItem(eventStorageKey)).to.equal(null);
17541754
});
17551755

17561756
it('should store events in session storage when noFunctional is false', async () => {
17571757
window.mParticle.config.flags = {
17581758
offlineStorage: '100',
17591759
...enableBatchingConfigFlags,
17601760
};
1761-
window.mParticle.config.launcherOptions = {
1762-
noFunctional: false,
1763-
};
1761+
window.mParticle.config.noFunctional = false;
17641762
window.mParticle.init(apiKey, window.mParticle.config);
17651763
await waitForCondition(hasIdentifyReturned);
17661764
const mpInstance = window.mParticle.getInstance();
17671765
const uploader = mpInstance._APIClient.uploader;
17681766
uploader.queueEvent(event0);
1769-
expect(!!window.sessionStorage.getItem(eventStorageKey)).to.equal(true);
1767+
expect(window.sessionStorage.getItem(eventStorageKey)).to.not.equal(null);
17701768
});
17711769

17721770
it('should store batches in local storage when noFunctional is false by default', async () => {
17731771
window.mParticle.init(apiKey, window.mParticle.config);
17741772
await waitForCondition(hasIdentifyReturned);
17751773
const mpInstance = window.mParticle.getInstance();
17761774
const uploader = mpInstance._APIClient.uploader;
1775+
fetchMock.post(urls.events, 500, { overwriteRoutes: true });
17771776
uploader.queueEvent(event0);
1778-
expect(!!window.localStorage.getItem(batchStorageKey)).to.equal(true);
1777+
await window.mParticle.getInstance()._APIClient.uploader.prepareAndUpload();
1778+
expect(window.localStorage.getItem(batchStorageKey)).to.not.equal(null);
17791779
});
17801780

17811781
it('should NOT store batches in local storage when noFunctional is true', async () => {
17821782
window.mParticle.config.flags = {
17831783
offlineStorage: '100',
17841784
...enableBatchingConfigFlags,
17851785
};
1786-
window.mParticle.config.launcherOptions = {
1787-
noFunctional: true,
1788-
};
1786+
window.mParticle.config.noFunctional = true;
17891787
window.mParticle.init(apiKey, window.mParticle.config);
17901788
await waitForCondition(hasIdentifyReturned);
17911789
const mpInstance = window.mParticle.getInstance();
17921790
const uploader = mpInstance._APIClient.uploader;
17931791
uploader.queueEvent(event0);
1794-
expect(window.localStorage.getItem(batchStorageKey) === '').to.equal(true);
1792+
await window.mParticle.getInstance()._APIClient.uploader.prepareAndUpload();
1793+
expect(window.localStorage.getItem(batchStorageKey)).to.equal(null);
17951794
});
17961795

17971796
it('should store batches in local storage when noFunctional is false', async () => {
17981797
window.mParticle.config.flags = {
17991798
offlineStorage: '100',
18001799
...enableBatchingConfigFlags,
18011800
};
1802-
window.mParticle.config.launcherOptions = {
1803-
noFunctional: false,
1804-
};
1801+
window.mParticle.config.noFunctional = false;
18051802
window.mParticle.init(apiKey, window.mParticle.config);
18061803
await waitForCondition(hasIdentifyReturned);
18071804
const mpInstance = window.mParticle.getInstance();
18081805
const uploader = mpInstance._APIClient.uploader;
1806+
fetchMock.post(urls.events, 500, { overwriteRoutes: true });
18091807
uploader.queueEvent(event0);
1810-
expect(!!window.localStorage.getItem(batchStorageKey)).to.equal(true);
1808+
await window.mParticle.getInstance()._APIClient.uploader.prepareAndUpload();
1809+
expect(window.localStorage.getItem(batchStorageKey)).to.not.equal(null);
18111810
});
18121811

18131812
});

0 commit comments

Comments
 (0)