@@ -218,7 +218,6 @@ describe('CookieSyncManager', () => {
218218 ) ;
219219 } ) ;
220220
221- // QUESTION: What is the purpose of this code path?
222221 it ( 'should call performCookieSync with mpid if previousMpid and mpid match' , ( ) => {
223222 const mockMPInstance = ( {
224223 _Store : {
@@ -247,6 +246,33 @@ describe('CookieSyncManager', () => {
247246 ) ;
248247 } ) ;
249248
249+ it ( 'should perform a cookie sync if lastSyncDateForModule is null' , ( ) => {
250+ const mockMPInstance = ( {
251+ _Store : {
252+ webviewBridgeEnabled : false ,
253+ pixelConfigurations : [ pixelSettings ] ,
254+ } ,
255+ _Persistence : {
256+ getPersistence : ( ) => ( { testMPID : { } } ) ,
257+ } ,
258+ } as unknown ) as MParticleWebSDK ;
259+
260+ const cookieSyncManager = new CookieSyncManager ( mockMPInstance ) ;
261+ cookieSyncManager . performCookieSync = jest . fn ( ) ;
262+
263+ cookieSyncManager . attemptCookieSync ( null , testMPID , true ) ;
264+
265+ expect ( cookieSyncManager . performCookieSync ) . toHaveBeenCalledWith (
266+ '' ,
267+ '5' ,
268+ testMPID ,
269+ { } ,
270+ undefined ,
271+ true ,
272+ false ,
273+ ) ;
274+ } ) ;
275+
250276 it ( 'should perform a cookie sync if lastSyncDateForModule has passed the frequency cap' , ( ) => {
251277 const now = new Date ( ) . getTime ( ) ;
252278
@@ -331,6 +357,25 @@ describe('CookieSyncManager', () => {
331357 expect ( mockMPInstance . _Store . pixelConfigurations . length ) . toBe ( 1 ) ;
332358 expect ( mockMPInstance . _Store . pixelConfigurations [ 0 ] . moduleId ) . toBe ( 5 ) ;
333359 } ) ;
360+
361+ it ( 'should not perform a cookie sync if persistence is empty' , ( ) => {
362+ const mockMPInstance = ( {
363+ _Store : {
364+ webviewBridgeEnabled : false ,
365+ pixelConfigurations : [ pixelSettings ] ,
366+ } ,
367+ _Persistence : {
368+ getPersistence : ( ) => ( { } ) ,
369+ } ,
370+ } as unknown ) as MParticleWebSDK ;
371+
372+ const cookieSyncManager = new CookieSyncManager ( mockMPInstance ) ;
373+ cookieSyncManager . performCookieSync = jest . fn ( ) ;
374+
375+ cookieSyncManager . attemptCookieSync ( null , testMPID , true ) ;
376+
377+ expect ( cookieSyncManager . performCookieSync ) . not . toHaveBeenCalled ( ) ;
378+ } ) ;
334379 } ) ;
335380
336381 describe ( '#performCookieSync' , ( ) => {
@@ -560,13 +605,16 @@ describe('CookieSyncManager', () => {
560605
561606 const cookieSyncManager = new CookieSyncManager ( mockMPInstance ) ;
562607
608+ // Note: We expect that the input of the pixelUrl will include a `?`
609+ // (ideally at the end of the string)
610+ // so that the redirectUrl can be processed by the backend correctly
563611 const result = cookieSyncManager . combineUrlWithRedirect (
564612 '1234' ,
565- 'https://test.com/some/path' ,
613+ 'https://test.com/some/path? ' ,
566614 'https://redirect.mparticle.com/v1/sync?esid=1234&MPID=%%mpid%%&ID=$UID&Key=testMPID&env=2'
567615 ) ;
568616
569- expect ( result ) . toBe ( 'https://test.com/some/pathhttps %3A%2F%2Fredirect.mparticle.com%2Fv1%2Fsync%3Fesid%3D1234%26amp%3BMPID%3D1234%26amp%3BID%3D%24UID%26amp%3BKey%3DtestMPID%26amp%3Benv%3D2' ) ;
617+ expect ( result ) . toBe ( 'https://test.com/some/path?https %3A%2F%2Fredirect.mparticle.com%2Fv1%2Fsync%3Fesid%3D1234%26amp%3BMPID%3D1234%26amp%3BID%3D%24UID%26amp%3BKey%3DtestMPID%26amp%3Benv%3D2' ) ;
570618 } ) ;
571619
572620 it ( 'should return the pixelUrl if no redirectUrl is defined' , ( ) => {
0 commit comments