@@ -444,6 +444,113 @@ describe('Rokt Forwarder', () => {
444444 } ) ;
445445 } ) ;
446446
447+ describe ( '#attachLauncher' , ( ) => {
448+ let mockMessageQueue ;
449+
450+ beforeEach ( ( ) => {
451+ mockMessageQueue = [ ] ;
452+
453+ // Reset forwarder state between tests
454+ window . mParticle . forwarder . isInitialized = false ;
455+
456+ window . Rokt = new MockRoktForwarder ( ) ;
457+ window . mParticle . Rokt = window . Rokt ;
458+ window . mParticle . Rokt . attachKitCalled = false ;
459+
460+ // Set attachKit as async to allow for await calls in the test
461+ // This is necessary to simiulate a race condition between the
462+ // core sdk and the Rokt forwarder
463+ window . mParticle . Rokt . attachKit = async ( kit ) => {
464+ window . mParticle . Rokt . attachKitCalled = true ;
465+ window . mParticle . Rokt . kit = kit ;
466+
467+ // Call queued messages
468+ mockMessageQueue . forEach ( ( message ) => message ( ) ) ;
469+ mockMessageQueue = [ ] ;
470+
471+ return Promise . resolve ( ) ;
472+ } ;
473+ window . mParticle . Rokt . filters = {
474+ userAttributesFilters : [ ] ,
475+ filterUserAttributes : function ( attributes ) {
476+ return attributes ;
477+ } ,
478+ filteredUser : {
479+ getMPID : function ( ) {
480+ return '123' ;
481+ } ,
482+ } ,
483+ } ;
484+ } ) ;
485+
486+ it ( 'should call attachKit' , async ( ) => {
487+ await window . mParticle . forwarder . init (
488+ { accountId : '123456' } ,
489+ reportService . cb ,
490+ true ,
491+ null ,
492+ { }
493+ ) ;
494+
495+ await waitForCondition ( ( ) => window . mParticle . Rokt . attachKitCalled ) ;
496+
497+ window . mParticle . Rokt . attachKitCalled . should . equal ( true ) ;
498+ } ) ;
499+
500+ it ( 'should set isInitialized to true' , async ( ) => {
501+ await window . mParticle . forwarder . init (
502+ { accountId : '123456' } ,
503+ reportService . cb ,
504+ true ,
505+ null ,
506+ { }
507+ ) ;
508+
509+ await waitForCondition ( ( ) => window . mParticle . Rokt . attachKitCalled ) ;
510+
511+ window . mParticle . forwarder . isInitialized . should . equal ( true ) ;
512+ } ) ;
513+
514+ // This test is to ensure the kit is initialized before attaching to the Rokt manager
515+ // so we can ensure that the Rokt Manager's message queue is processed and that
516+ // all the isReady() checks are properly handled in by the Rokt Manager.
517+ // This is to validate in case a bug that was found in the Rokt Manager's
518+ // queueing logic regresses.
519+ it ( 'should initialize the kit before calling queued messages' , async ( ) => {
520+ let queuedMessageCalled = false ;
521+ let wasKitInitializedFirst = false ;
522+
523+ const queuedMessage = ( ) => {
524+ wasKitInitializedFirst =
525+ window . mParticle . Rokt . kit &&
526+ window . mParticle . Rokt . kit . isInitialized ;
527+ queuedMessageCalled = true ;
528+ } ;
529+
530+ mockMessageQueue . push ( queuedMessage ) ;
531+
532+ await window . mParticle . forwarder . init (
533+ { accountId : '123456' } ,
534+ reportService . cb ,
535+ true ,
536+ null ,
537+ { }
538+ ) ;
539+
540+ window . mParticle . forwarder . isInitialized . should . equal ( false ) ;
541+ queuedMessageCalled . should . equal ( false ) ;
542+
543+ await waitForCondition ( ( ) => window . mParticle . Rokt . attachKitCalled ) ;
544+
545+ window . mParticle . forwarder . isInitialized . should . equal ( true ) ;
546+ queuedMessageCalled . should . equal ( true ) ;
547+
548+ wasKitInitializedFirst . should . equal ( true ) ;
549+
550+ mockMessageQueue . length . should . equal ( 0 ) ;
551+ } ) ;
552+ } ) ;
553+
447554 describe ( '#selectPlacements' , ( ) => {
448555 beforeEach ( ( ) => {
449556 window . Rokt = new MockRoktForwarder ( ) ;
0 commit comments