@@ -50,6 +50,7 @@ interface IMockForwarderInstance {
5050 onUserIdentifiedCalled ?: boolean ;
5151 onUserIdentifiedUser ?: IMParticleUser ;
5252 receivedEvent ?: SDKEvent ;
53+ receivedEvents ?: SDKEvent [ ] ;
5354 removeUserAttributeCalled ?: boolean ;
5455 setUserAttributeCalled ?: boolean ;
5556 setSessionAttributeCalled ?: boolean ;
@@ -273,6 +274,7 @@ describe('forwarders', function() {
273274
274275 await waitForCondition ( ( ) => window . mParticle . getInstance ( ) ?. _Store ?. identityCallInFlight === false ) ;
275276
277+ expect ( mParticle . isInitialized ( ) ) . to . equal ( true ) ;
276278 expect ( mParticle . getInstance ( ) . _getActiveForwarders ( ) . length ) . to . equal ( 1 ) ;
277279 window . MockForwarder1 . instance . receivedEvent = null ;
278280
@@ -283,6 +285,63 @@ describe('forwarders', function() {
283285 window . MockForwarder1 . instance . receivedEvent . EventName . should . equal ( 'NoFunctional Test Event' ) ;
284286 } ) ;
285287
288+ it ( 'when noFunctional is true, after explicit Identity.identify() returns, mParticle is fully initialized' , async ( ) => {
289+ window . mParticle . config . launcherOptions = { noFunctional : true , noTargeting : false } ;
290+ window . mParticle . config . identifyRequest = undefined ;
291+
292+ const mockForwarder = new MockForwarder ( ) ;
293+ mockForwarder . register ( window . mParticle . config ) ;
294+ window . mParticle . config . kitConfigs . push (
295+ forwarderDefaultConfiguration ( 'MockForwarder' , 1 )
296+ ) ;
297+
298+ mParticle . init ( apiKey , window . mParticle . config ) ;
299+
300+ expect ( mParticle . isInitialized ( ) ) . to . not . equal ( true ) ;
301+
302+ mParticle . Identity . identify ( {
303+ userIdentities :
{ email :
'[email protected] ' } , 304+ } ) ;
305+
306+ await waitForCondition ( ( ) => window . mParticle . getInstance ( ) ?. _Store ?. identityCallInFlight === false ) ;
307+
308+ expect ( mParticle . isInitialized ( ) ) . to . equal ( true ) ;
309+ } ) ;
310+
311+ it ( 'when noFunctional and explicit identity is provided, queued events are processed after identify returns and mParticle is fully initialized' , async ( ) => {
312+ window . mParticle . config . launcherOptions = { noFunctional : true , noTargeting : false } ;
313+ window . mParticle . config . identifyRequest = undefined ;
314+
315+ const mockForwarder = new MockForwarder ( ) ;
316+ mockForwarder . register ( window . mParticle . config ) ;
317+ window . mParticle . config . kitConfigs . push (
318+ forwarderDefaultConfiguration ( 'MockForwarder' , 1 )
319+ ) ;
320+
321+ mParticle . init ( apiKey , window . mParticle . config ) ;
322+
323+ expect ( mParticle . getInstance ( ) . _getActiveForwarders ( ) . length ) . to . equal ( 1 ) ;
324+ expect ( mParticle . isInitialized ( ) ) . to . not . equal ( true ) ;
325+
326+ mParticle . logEvent ( 'QueuedEvent1' , mParticle . EventType . Navigation ) ;
327+ mParticle . logEvent ( 'QueuedEvent2' , mParticle . EventType . Navigation ) ;
328+
329+ const store = mParticle . getInstance ( ) . _Store ;
330+ expect ( store . eventQueue ) . to . have . length ( 2 ) ;
331+
332+ mParticle . Identity . identify ( {
333+ userIdentities :
{ email :
'[email protected] ' } , 334+ } ) ;
335+ await waitForCondition ( ( ) => window . mParticle . getInstance ( ) ?. _Store ?. identityCallInFlight === false ) ;
336+
337+ expect ( mParticle . isInitialized ( ) ) . to . equal ( true ) ;
338+ expect ( store . eventQueue ) . to . have . length ( 0 ) ;
339+
340+ const names = window . MockForwarder1 . instance . receivedEvents ! . map ( ( e ) => e . EventName ) ;
341+ expect ( names ) . to . include ( 'QueuedEvent1' ) ;
342+ expect ( names ) . to . include ( 'QueuedEvent2' ) ;
343+ } ) ;
344+
286345 it ( 'should still deliver setSessionAttribute to forwarders when noFunctional is true and no identity passed' , ( ) => {
287346 window . mParticle . config . launcherOptions = { noFunctional : true , noTargeting : false } ;
288347 window . mParticle . config . identifyRequest = undefined ;
0 commit comments