Skip to content

Commit 426f038

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

2 files changed

Lines changed: 8 additions & 12 deletions

File tree

test/jest/batchUploader.spec.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { BatchUploader } from '../../src/batchUploader';
22
import { IMParticleWebSDKInstance } from '../../src/mp-instance';
3+
import { IStore } from '../../src/store';
34
import { StoragePrivacyMap, StorageTypes } from '../../src/constants';
5+
import { SDKEvent } from '../../src/sdkRuntimeModels';
46

57
describe('BatchUploader', () => {
68
let batchUploader: BatchUploader;
@@ -20,9 +22,9 @@ describe('BatchUploader', () => {
2022
mockMPInstance = {
2123
_Store: {
2224
storageName: 'mprtcl-v4_abcdef',
23-
getNoFunctional: function(this: any) { return this.noFunctional; },
24-
getNoTargeting: function(this: any) { return this.noTargeting; },
25-
getPrivacyFlag: function(this: any, storageType: StorageTypes) {
25+
getNoFunctional: function(this: IStore) { return this.noFunctional; },
26+
getNoTargeting: function(this: IStore) { return this.noTargeting; },
27+
getPrivacyFlag: function(this: IStore, storageType: StorageTypes) {
2628
const privacyControl = StoragePrivacyMap[storageType];
2729
if (privacyControl === 'functional') {
2830
return this.getNoFunctional();
@@ -143,7 +145,7 @@ describe('BatchUploader', () => {
143145
const uploader = new BatchUploader(mockMPInstance, 1000);
144146
expect(uploader['offlineStorageEnabled']).toBe(false);
145147

146-
uploader.queueEvent({ EventDataType: 4 } as any);
148+
uploader.queueEvent({ EventDataType: 4 } as SDKEvent);
147149
expect(sessionStorage.getItem('mprtcl-v4_abcdef-events')).toBeNull();
148150
expect(localStorage.getItem('mprtcl-v4_abcdef-batches')).toBeNull();
149151
});
@@ -153,7 +155,7 @@ describe('BatchUploader', () => {
153155

154156
expect(uploader['offlineStorageEnabled']).toBe(true);
155157

156-
uploader.queueEvent({ EventDataType: 4 } as any);
158+
uploader.queueEvent({ EventDataType: 4 } as SDKEvent);
157159
expect(sessionStorage.getItem('mprtcl-v4_abcdef-events')).not.toBeNull();
158160

159161
jest.advanceTimersByTime(1000);
@@ -167,7 +169,7 @@ describe('BatchUploader', () => {
167169

168170
const uploader = new BatchUploader(mockMPInstance, 1000);
169171

170-
uploader.queueEvent({ EventDataType: 4 } as any);
172+
uploader.queueEvent({ EventDataType: 4 } as SDKEvent);
171173
expect(sessionStorage.getItem('mprtcl-v4_abcdef-events')).not.toBeNull();
172174

173175
jest.advanceTimersByTime(1000);

test/src/tests-batchUploader.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,7 +1750,6 @@ describe('batch uploader', () => {
17501750
const mpInstance = window.mParticle.getInstance();
17511751
const uploader = mpInstance._APIClient.uploader;
17521752
uploader.queueEvent(event0);
1753-
await window.mParticle.getInstance()._APIClient.uploader.prepareAndUpload();
17541753
expect(window.sessionStorage.getItem(eventStorageKey) === '').to.equal(true);
17551754
});
17561755

@@ -1775,9 +1774,7 @@ describe('batch uploader', () => {
17751774
await waitForCondition(hasIdentifyReturned);
17761775
const mpInstance = window.mParticle.getInstance();
17771776
const uploader = mpInstance._APIClient.uploader;
1778-
fetchMock.post(urls.events, 500, { overwriteRoutes: true });
17791777
uploader.queueEvent(event0);
1780-
await window.mParticle.getInstance()._APIClient.uploader.prepareAndUpload();
17811778
expect(!!window.localStorage.getItem(batchStorageKey)).to.equal(true);
17821779
});
17831780

@@ -1794,7 +1791,6 @@ describe('batch uploader', () => {
17941791
const mpInstance = window.mParticle.getInstance();
17951792
const uploader = mpInstance._APIClient.uploader;
17961793
uploader.queueEvent(event0);
1797-
await window.mParticle.getInstance()._APIClient.uploader.prepareAndUpload();
17981794
expect(window.localStorage.getItem(batchStorageKey) === '').to.equal(true);
17991795
});
18001796

@@ -1810,9 +1806,7 @@ describe('batch uploader', () => {
18101806
await waitForCondition(hasIdentifyReturned);
18111807
const mpInstance = window.mParticle.getInstance();
18121808
const uploader = mpInstance._APIClient.uploader;
1813-
fetchMock.post(urls.events, 500, { overwriteRoutes: true });
18141809
uploader.queueEvent(event0);
1815-
await window.mParticle.getInstance()._APIClient.uploader.prepareAndUpload();
18161810
expect(!!window.localStorage.getItem(batchStorageKey)).to.equal(true);
18171811
});
18181812

0 commit comments

Comments
 (0)