@@ -894,9 +894,6 @@ describe('RoktManager', () => {
894894 // Ensure store has identityCallInFlight set to false (from beforeEach)
895895 // This prevents re-queuing when selectPlacements is called from the queue
896896 roktManager [ 'store' ] . identityCallInFlight = false ;
897-
898- // Ensure identity service is set up (from beforeEach init)
899- // selectPlacements calls getCurrentUser() which needs to be available
900897
901898 const options = {
902899 attributes : { }
@@ -1818,6 +1815,16 @@ describe('RoktManager', () => {
18181815 } ) ;
18191816
18201817 it ( 'should propagate email after identify completes when identify is called during init' , async ( ) => {
1818+ // Set initial currentUser with first email to mimic real user flow
1819+ roktManager [ 'currentUser' ] = {
1820+ getUserIdentities : ( ) => ( {
1821+ userIdentities : {
1822+ email : 'first@gmail.com'
1823+ }
1824+ } ) ,
1825+ setUserAttributes : jest . fn ( )
1826+ } as unknown as IMParticleUser ;
1827+
18211828 const kit : Partial < IRoktKit > = {
18221829 launcher : {
18231830 selectPlacements : jest . fn ( ) ,
@@ -1901,6 +1908,7 @@ describe('RoktManager', () => {
19011908
19021909 // Verify it was queued (not called yet)
19031910 expect ( kit . selectPlacements ) . not . toHaveBeenCalled ( ) ;
1911+ expect ( roktManager [ 'messageQueue' ] . size ) . toBe ( 1 ) ;
19041912
19051913 // Wait for identity to complete
19061914 await identityCompletePromise ;
@@ -2414,68 +2422,6 @@ describe('RoktManager', () => {
24142422 } ) ;
24152423 } ) ;
24162424
2417- describe ( '#completePendingPromise' , ( ) => {
2418- it ( 'should resolve pending promise when given a direct value' , async ( ) => {
2419- const promise = roktManager [ 'deferredCall' ] < string > ( 'testMethod' , { } ) ;
2420- const queuedMessage = Array . from ( roktManager [ 'messageQueue' ] . values ( ) ) [ 0 ] ;
2421- const messageId = queuedMessage . messageId ! ;
2422-
2423- // Complete the promise with direct value (not wrapped in Promise)
2424- roktManager [ 'completePendingPromise' ] ( messageId , 'success result' ) ;
2425-
2426- // Promise should resolve with the direct value
2427- await expect ( promise ) . resolves . toBe ( 'success result' ) ;
2428-
2429- // Should clean up the message from queue
2430- expect ( roktManager [ 'messageQueue' ] . has ( messageId ) ) . toBe ( false ) ;
2431- } ) ;
2432-
2433- it ( 'should resolve pending promise when given a Promise and unwrap it' , async ( ) => {
2434- const promise = roktManager [ 'deferredCall' ] < any > ( 'testMethod' , { } ) ;
2435- const queuedMessage = Array . from ( roktManager [ 'messageQueue' ] . values ( ) ) [ 0 ] ;
2436- const messageId = queuedMessage . messageId ! ;
2437- const asyncResult = { data : 'async data' } ;
2438-
2439- // Complete with a Promise that needs unwrapping
2440- roktManager [ 'completePendingPromise' ] ( messageId , Promise . resolve ( asyncResult ) ) ;
2441-
2442- // Should get the unwrapped result, not the promise wrapper
2443- const result = await promise ;
2444- expect ( result ) . toEqual ( asyncResult ) ;
2445- expect ( result ) . not . toBeInstanceOf ( Promise ) ;
2446-
2447- // Should clean up the message from queue
2448- expect ( roktManager [ 'messageQueue' ] . has ( messageId ) ) . toBe ( false ) ;
2449- } ) ;
2450-
2451- it ( 'should reject pending promise with error' , async ( ) => {
2452- const promise = roktManager [ 'deferredCall' ] < string > ( 'testMethod' , { } ) ;
2453- const queuedMessage = Array . from ( roktManager [ 'messageQueue' ] . values ( ) ) [ 0 ] ;
2454- const messageId = queuedMessage . messageId ! ;
2455- const error = new Error ( 'test error' ) ;
2456-
2457- // Complete the promise with error (wrapped in rejected promise)
2458- roktManager [ 'completePendingPromise' ] ( messageId , Promise . reject ( error ) ) ;
2459-
2460- // Promise should reject with the error
2461- await expect ( promise ) . rejects . toThrow ( 'test error' ) ;
2462-
2463- // Should clean up the pending promise
2464- expect ( roktManager [ 'messageQueue' ] . has ( messageId ) ) . toBe ( false ) ;
2465- } ) ;
2466-
2467- it ( 'should handle missing messageId gracefully' , ( ) => {
2468- // Should not throw when messageId is undefined
2469- expect ( ( ) => {
2470- roktManager [ 'completePendingPromise' ] ( undefined , 'result' ) ;
2471- } ) . not . toThrow ( ) ;
2472-
2473- // Should not throw when messageId does not exist
2474- expect ( ( ) => {
2475- roktManager [ 'completePendingPromise' ] ( 'nonexistent' , 'result' ) ;
2476- } ) . not . toThrow ( ) ;
2477- } ) ;
2478- } ) ;
24792425
24802426 describe ( '#use' , ( ) => {
24812427 it ( 'should call kit.use with provided name' , async ( ) => {
0 commit comments