@@ -2058,6 +2058,127 @@ describe('identity', function() {
20582058 done ( ) ;
20592059 } ) ;
20602060
2061+ it ( "should find the related MPID's cookies when given a UI with fewer IDs when passed to login, logout, and identify, and then log events with updated cookies" , async ( ) => {
2062+ mParticle . _resetForTests ( MPConfig ) ;
2063+ fetchMock . restore ( ) ;
2064+ const user1 : IdentityApiData = {
2065+ userIdentities : {
2066+ customerid : 'customerid1' ,
2067+ } ,
2068+ } ;
2069+
2070+ const user1modified : IdentityApiData = {
2071+ userIdentities : {
2072+ email : 'email2@test.com' ,
2073+ } ,
2074+ } ;
2075+
2076+ fetchMockSuccess ( urls . events , { } ) ;
2077+ fetchMockSuccess ( urls . identify , {
2078+ context : null ,
2079+ matched_identities : {
2080+ device_application_stamp : 'my-das' ,
2081+ } ,
2082+ is_ephemeral : true ,
2083+ mpid : testMPID ,
2084+ is_logged_in : false ,
2085+ } ) ;
2086+
2087+ mParticle . config . identifyRequest = user1 ;
2088+
2089+ mParticle . init ( apiKey , window . mParticle . config ) ;
2090+
2091+ fetchMockSuccess ( urls . modify , {
2092+ change_results : [
2093+ {
2094+ identity_type : 'email' ,
2095+ modified_mpid : testMPID ,
2096+ } ,
2097+ ] ,
2098+ } ) ;
2099+
2100+ await waitForCondition ( hasIdentifyReturned )
2101+ mParticle . Identity . modify ( user1modified ) ;
2102+ // Should contain the following calls:
2103+ // 1 for the initial identify
2104+ // 3 for the events (Session Start, UAT and UIC)
2105+ // 1 for the modify
2106+ // 1 for the UIC event
2107+ await waitForCondition ( hasIdentityCallInflightReturned )
2108+ expect ( fetchMock . calls ( ) . length ) . to . equal ( 6 ) ;
2109+
2110+ // This will add a new UAC Event to the call
2111+ mParticle . Identity . getCurrentUser ( ) . setUserAttribute ( 'foo1' , 'bar1' ) ;
2112+ expect ( fetchMock . calls ( ) . length ) . to . equal ( 7 ) ;
2113+
2114+ // This will add a new custom event to the call
2115+ mParticle . logEvent ( 'Test Event 1' ) ;
2116+ expect ( fetchMock . calls ( ) . length ) . to . equal ( 8 ) ;
2117+
2118+ const testEvent1Batch = JSON . parse ( fetchMock . calls ( ) [ 7 ] [ 1 ] . body as string ) ;
2119+
2120+ expect ( testEvent1Batch . user_attributes ) . to . deep . equal ( { 'foo1' : 'bar1' } ) ;
2121+ expect ( testEvent1Batch . user_identities ) . to . deep . equal ( {
2122+ 'customer_id' : 'customerid1' ,
2123+ 'email' : 'email2@test.com'
2124+ } ) ;
2125+
2126+ const user2 = {
2127+ userIdentities : {
2128+ customerid : 'customerid2' ,
2129+ } ,
2130+ } ;
2131+
2132+ fetchMockSuccess ( urls . logout , {
2133+ mpid : 'logged-out-user' ,
2134+ is_logged_in : true ,
2135+ } ) ;
2136+
2137+ mParticle . Identity . logout ( user2 ) ;
2138+
2139+ await waitForCondition ( hasLogOutReturned )
2140+
2141+ // This will add the following new calls:
2142+ // 1 for the logout
2143+ // 1 for the UIC event
2144+ // 1 for Test Event 2
2145+ mParticle . logEvent ( 'Test Event 2' ) ;
2146+
2147+ expect ( fetchMock . calls ( ) . length ) . to . equal ( 11 ) ;
2148+
2149+ const testEvent2Batch = JSON . parse ( fetchMock . calls ( ) [ 10 ] [ 1 ] . body as string ) ;
2150+
2151+ Object . keys ( testEvent2Batch . user_attributes ) . length . should . equal ( 0 ) ;
2152+ testEvent2Batch . user_identities . should . have . property (
2153+ 'customer_id' ,
2154+ 'customerid2'
2155+ ) ;
2156+
2157+ fetchMockSuccess ( urls . login , {
2158+ mpid : 'testMPID' ,
2159+ is_logged_in : true ,
2160+ } ) ;
2161+
2162+ mParticle . Identity . login ( user1 ) ;
2163+ await waitForCondition ( ( ) => {
2164+ return mParticle . Identity . getCurrentUser ( ) . getMPID ( ) === 'testMPID' ;
2165+ } )
2166+
2167+ // This will add the following new calls:
2168+ // 1 for the login
2169+ // 1 for Test Event 3
2170+ mParticle . logEvent ( 'Test Event 3' ) ;
2171+ expect ( fetchMock . calls ( ) . length ) . to . equal ( 13 ) ;
2172+
2173+ const testEvent3Batch = JSON . parse ( fetchMock . calls ( ) [ 12 ] [ 1 ] . body as string ) ;
2174+
2175+ expect ( testEvent3Batch . user_attributes ) . to . deep . equal ( { 'foo1' : 'bar1' } ) ;
2176+ expect ( testEvent3Batch . user_identities ) . to . deep . equal ( {
2177+ 'customer_id' : 'customerid1' ,
2178+ 'email' : 'email2@test.com'
2179+ } ) ;
2180+ } ) ;
2181+
20612182 it ( 'should add new MPIDs to cookie structure when initializing new identity requests, returning an existing mpid when reinitializing with a previous identity' , async ( ) => {
20622183 mParticle . _resetForTests ( MPConfig ) ;
20632184
0 commit comments