11import { BatchUploader } from '../../src/batchUploader' ;
22import { IMParticleWebSDKInstance } from '../../src/mp-instance' ;
3- import { IStore } from '../../src/store' ;
4- import { StoragePrivacyMap , StorageTypes } from '../../src/constants' ;
5- import { SDKEvent } from '../../src/sdkRuntimeModels' ;
63
74describe ( 'BatchUploader' , ( ) => {
85 let batchUploader : BatchUploader ;
@@ -21,39 +18,18 @@ describe('BatchUploader', () => {
2118 // Create a mock mParticle instance with mocked methods for instantiating a BatchUploader
2219 mockMPInstance = {
2320 _Store : {
24- storageName : 'mprtcl-v4_abcdef' ,
25- getNoFunctional : function ( this : IStore ) { return this . noFunctional ; } ,
26- getNoTargeting : function ( this : IStore ) { return this . noTargeting ; } ,
27- getPrivacyFlag : function ( this : IStore , storageType : StorageTypes ) {
28- const privacyControl = StoragePrivacyMap [ storageType ] ;
29- if ( privacyControl === 'functional' ) {
30- return this . getNoFunctional ( ) ;
31- }
32- if ( privacyControl === 'targeting' ) {
33- return this . getNoTargeting ( ) ;
34- }
35- return false ;
36- } ,
37- deviceId : 'device-1' ,
3821 SDKConfig : {
3922 flags : { }
4023 }
4124 } ,
4225 _Helpers : {
43- getFeatureFlag : jest . fn ( ) . mockReturnValue ( '100' ) ,
26+ getFeatureFlag : jest . fn ( ) . mockReturnValue ( false ) ,
4427 createServiceUrl : jest . fn ( ) . mockReturnValue ( 'https://mock-url.com' ) ,
45- generateUniqueId : jest . fn ( ) . mockReturnValue ( 'req-1' ) ,
4628 } ,
4729 Identity : {
4830 getCurrentUser : jest . fn ( ) . mockReturnValue ( {
49- getMPID : ( ) => 'test-mpid' ,
50- getConsentState : jest . fn ( ) . mockReturnValue ( null ) ,
31+ getMPID : ( ) => 'test-mpid'
5132 } )
52- } ,
53- Logger : {
54- verbose : jest . fn ( ) ,
55- error : jest . fn ( ) ,
56- warning : jest . fn ( ) ,
5733 }
5834 } as unknown as IMParticleWebSDKInstance ;
5935
@@ -132,50 +108,4 @@ describe('BatchUploader', () => {
132108 expect ( secondCallTime ) . toBe ( firstCallTime ) ;
133109 } ) ;
134110 } ) ;
135-
136- describe ( 'noFunctional' , ( ) => {
137- beforeEach ( ( ) => {
138- localStorage . clear ( ) ;
139- sessionStorage . clear ( ) ;
140- } ) ;
141-
142- it ( 'should disable offline storage when noFunctional is true' , ( ) => {
143- mockMPInstance . _Store . noFunctional = true ;
144-
145- const uploader = new BatchUploader ( mockMPInstance , 1000 ) ;
146- expect ( uploader [ 'offlineStorageEnabled' ] ) . toBe ( false ) ;
147-
148- uploader . queueEvent ( { EventDataType : 4 } as SDKEvent ) ;
149- expect ( sessionStorage . getItem ( 'mprtcl-v4_abcdef-events' ) ) . toBeNull ( ) ;
150- expect ( localStorage . getItem ( 'mprtcl-v4_abcdef-batches' ) ) . toBeNull ( ) ;
151- } ) ;
152-
153- it ( 'should enable offline storage when noFunctional is false by default' , async ( ) => {
154- const uploader = new BatchUploader ( mockMPInstance , 1000 ) ;
155-
156- expect ( uploader [ 'offlineStorageEnabled' ] ) . toBe ( true ) ;
157-
158- uploader . queueEvent ( { EventDataType : 4 } as SDKEvent ) ;
159- expect ( sessionStorage . getItem ( 'mprtcl-v4_abcdef-events' ) ) . not . toBeNull ( ) ;
160-
161- jest . advanceTimersByTime ( 1000 ) ;
162- await Promise . resolve ( ) ;
163-
164- expect ( localStorage . getItem ( 'mprtcl-v4_abcdef-batches' ) ) . not . toBeNull ( ) ;
165- } ) ;
166-
167- it ( 'should enable offline storage when noFunctional is false' , async ( ) => {
168- mockMPInstance . _Store . noFunctional = false ;
169-
170- const uploader = new BatchUploader ( mockMPInstance , 1000 ) ;
171-
172- uploader . queueEvent ( { EventDataType : 4 } as SDKEvent ) ;
173- expect ( sessionStorage . getItem ( 'mprtcl-v4_abcdef-events' ) ) . not . toBeNull ( ) ;
174-
175- jest . advanceTimersByTime ( 1000 ) ;
176- await Promise . resolve ( ) ;
177-
178- expect ( localStorage . getItem ( 'mprtcl-v4_abcdef-batches' ) ) . not . toBeNull ( ) ;
179- } ) ;
180- } ) ;
181111} ) ;
0 commit comments