Skip to content

Commit ebb3843

Browse files
Jaissica HoraJaissica Hora
authored andcommitted
test: updated tests for batchUploader
1 parent aeeb3bd commit ebb3843

2 files changed

Lines changed: 5 additions & 7 deletions

File tree

test/jest/batchUploader.spec.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ import { StoragePrivacyMap, StorageTypes } from '../../src/constants';
55
describe('BatchUploader', () => {
66
let batchUploader: BatchUploader;
77
let mockMPInstance: IMParticleWebSDKInstance;
8+
let originalFetch: typeof global.fetch;
89

910
beforeEach(() => {
1011
const now = Date.now();
1112
jest.useFakeTimers({
1213
now: now,
1314
advanceTimers: true // This improves the performance of nested timers, equivalent to Sinon's shouldAdvanceTime
1415
});
16+
originalFetch = global.fetch;
1517
global.fetch = jest.fn().mockResolvedValue({ ok: true, status: 200 });
1618

1719
// Create a mock mParticle instance with mocked methods for instantiating a BatchUploader
@@ -58,7 +60,7 @@ describe('BatchUploader', () => {
5860

5961
afterEach(() => {
6062
jest.useRealTimers();
61-
delete global.fetch;
63+
global.fetch = originalFetch;
6264
});
6365

6466
describe('shouldDebounceAST', () => {
@@ -151,7 +153,7 @@ describe('BatchUploader', () => {
151153

152154
expect(uploader['OfflineStorage']).toBe(true);
153155

154-
uploader.queueEvent({ EventDataType: 4, SessionId: 's1' } as any);
156+
uploader.queueEvent({ EventDataType: 4 } as any);
155157
expect(sessionStorage.getItem('mprtcl-v4_abcdef-events')).not.toBeNull();
156158

157159
jest.advanceTimersByTime(1000);
@@ -165,7 +167,7 @@ describe('BatchUploader', () => {
165167

166168
const uploader = new BatchUploader(mockMPInstance, 1000);
167169

168-
uploader.queueEvent({ EventDataType: 4, SessionId: 's1' } as any);
170+
uploader.queueEvent({ EventDataType: 4 } as any);
169171
expect(sessionStorage.getItem('mprtcl-v4_abcdef-events')).not.toBeNull();
170172

171173
jest.advanceTimersByTime(1000);

test/src/tests-batchUploader.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,7 +1744,6 @@ describe('batch uploader', () => {
17441744
...enableBatchingConfigFlags,
17451745
};
17461746
window.mParticle.config.launcherOptions = {
1747-
...(window.mParticle.config.launcherOptions || {}),
17481747
noFunctional: true,
17491748
};
17501749
window.mParticle.init(apiKey, window.mParticle.config);
@@ -1762,7 +1761,6 @@ describe('batch uploader', () => {
17621761
...enableBatchingConfigFlags,
17631762
};
17641763
window.mParticle.config.launcherOptions = {
1765-
...(window.mParticle.config.launcherOptions || {}),
17661764
noFunctional: false,
17671765
};
17681766
window.mParticle.init(apiKey, window.mParticle.config);
@@ -1790,7 +1788,6 @@ describe('batch uploader', () => {
17901788
...enableBatchingConfigFlags,
17911789
};
17921790
window.mParticle.config.launcherOptions = {
1793-
...(window.mParticle.config.launcherOptions || {}),
17941791
noFunctional: true,
17951792
};
17961793
window.mParticle.init(apiKey, window.mParticle.config);
@@ -1808,7 +1805,6 @@ describe('batch uploader', () => {
18081805
...enableBatchingConfigFlags,
18091806
};
18101807
window.mParticle.config.launcherOptions = {
1811-
...(window.mParticle.config.launcherOptions || {}),
18121808
noFunctional: false,
18131809
};
18141810
window.mParticle.init(apiKey, window.mParticle.config);

0 commit comments

Comments
 (0)