@@ -60,6 +60,11 @@ - (void)tearDown {
6060
6161- (void )testSelectPlacementsSimpleWithValidParameters {
6262 MParticleUser *currentUser = [MParticle sharedInstance ].identity .currentUser ;
63+
64+ // Set up IDFA on the current user
65+ MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine: [MParticle sharedInstance ].stateMachine backendController: [MParticle sharedInstance ].backendController identity: [MParticle sharedInstance ].identity];
66+ NSArray *userIdentityArray = @[@{@" n" : @(MPIdentityIOSAdvertiserId), @" i" : @" ABC123-IDFA-TEST" }];
67+ [userDefaults setMPObject: userIdentityArray forKey: kMPUserIdentityArrayKey userId: currentUser.userId];
6368
6469 [[[self .mockRokt stub ] andReturn: @[]] getRoktPlacementAttributesMapping ];
6570 MParticle *instance = [MParticle sharedInstance ];
@@ -82,7 +87,7 @@ - (void)testSelectPlacementsSimpleWithValidParameters {
8287
8388 // Set up test parameters
8489 NSString *identifier = @" testView" ;
85- NSDictionary *attributes = @{
@" email" :
@" [email protected] " ,
@" sandbox" :
@" false" };
90+ NSDictionary *attributes = @{
@" email" :
@" [email protected] " ,
@" idfa " : @" ABC123-IDFA-TEST " , @" sandbox" :
@" false" };
8691
8792 // Set up expectations for kit container
8893 XCTestExpectation *expectation = [self expectationWithDescription: @" Wait for async operation" ];
@@ -113,17 +118,36 @@ - (void)testSelectPlacementsSimpleWithValidParameters {
113118}
114119
115120- (void )testSelectPlacementsExpandedWithValidParameters {
121+ MParticleUser *currentUser = [MParticle sharedInstance ].identity .currentUser ;
122+
123+ // Set up IDFA on the current user
124+ MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine: [MParticle sharedInstance ].stateMachine backendController: [MParticle sharedInstance ].backendController identity: [MParticle sharedInstance ].identity];
125+ NSArray *userIdentityArray = @[@{@" n" : @(MPIdentityIOSAdvertiserId), @" i" : @" DEF456-IDFA-TEST" }];
126+ [userDefaults setMPObject: userIdentityArray forKey: kMPUserIdentityArrayKey userId: currentUser.userId];
127+
116128 [[[self .mockRokt stub ] andReturn: @[]] getRoktPlacementAttributesMapping ];
117129 MParticle *instance = [MParticle sharedInstance ];
118130 self.mockInstance = OCMPartialMock (instance);
131+ self.identityMock = OCMClassMock ([MPIdentityApi class ]);
132+ OCMStub ([(MParticle *)self .mockInstance identity ]).andReturn (self.identityMock );
119133 self.mockContainer = OCMClassMock ([MPKitContainer_PRIVATE class ]);
120134 [[[self .mockInstance stub ] andReturn: self .mockContainer] kitContainer_PRIVATE ];
121135 [[[self .mockInstance stub ] andReturn: self .mockInstance] sharedInstance ];
136+ [[[self .identityMock stub ] andReturn: currentUser] currentUser ];
137+
138+ self.mockApiResult = OCMClassMock ([MPIdentityApiResult class ]);
139+ OCMStub ([self .mockApiResult user ]).andReturn (currentUser);
140+
141+ [[[self .identityMock stub ] andDo: ^(NSInvocation *invocation) {
142+ void (^completion)(MPIdentityApiResult * _Nullable, NSError * _Nullable);
143+ [invocation getArgument: &completion atIndex: 3 ];
144+ completion (self.mockApiResult , nil );
145+ }] identify: [OCMArg any ] completion: [OCMArg any ]];
122146
123147 // Set up test parameters
124148 NSString *identifier = @" testView" ;
125149 NSDictionary *attributes = @{@" key" : @" value" };
126- NSDictionary *finalAttributes = @{@" key" : @" value" , @" sandbox" : @" true" };
150+ NSDictionary *finalAttributes = @{@" key" : @" value" , @" idfa " : @" DEF456-IDFA-TEST " , @" sandbox" : @" true" };
127151 MPRoktEmbeddedView *exampleView = [[MPRoktEmbeddedView alloc ] initWithFrame: CGRectZero];
128152 NSDictionary *embeddedViews = @{@" placement" : exampleView};
129153 MPRoktEventCallback *exampleCallbacks = [[MPRoktEventCallback alloc ] init ];
@@ -221,17 +245,36 @@ - (void)testSelectPlacementsExpandedWithNilParameters {
221245}
222246
223247- (void )testSelectPlacementsSimpleWithMapping {
248+ MParticleUser *currentUser = [MParticle sharedInstance ].identity .currentUser ;
249+
250+ // Set up IDFA on the current user
251+ MPUserDefaults *userDefaults = [MPUserDefaults standardUserDefaultsWithStateMachine: [MParticle sharedInstance ].stateMachine backendController: [MParticle sharedInstance ].backendController identity: [MParticle sharedInstance ].identity];
252+ NSArray *userIdentityArray = @[@{@" n" : @(MPIdentityIOSAdvertiserId), @" i" : @" C56A4180-65AA-42EC-A945-5FD21DEC0538" }];
253+ [userDefaults setMPObject: userIdentityArray forKey: kMPUserIdentityArrayKey userId: currentUser.userId];
254+
224255 [[[self .mockRokt stub ] andReturn: @[@{@" map" : @" f.name" , @" maptype" : @" UserAttributeClass.Name" , @" value" : @" firstname" }, @{@" map" : @" zip" , @" maptype" : @" UserAttributeClass.Name" , @" value" : @" billingzipcode" }, @{@" map" : @" l.name" , @" maptype" : @" UserAttributeClass.Name" , @" value" : @" lastname" }]] getRoktPlacementAttributesMapping ];
225256 MParticle *instance = [MParticle sharedInstance ];
226257 self.mockInstance = OCMPartialMock (instance);
258+ self.identityMock = OCMClassMock ([MPIdentityApi class ]);
259+ OCMStub ([(MParticle *)self .mockInstance identity ]).andReturn (self.identityMock );
227260 self.mockContainer = OCMClassMock ([MPKitContainer_PRIVATE class ]);
228261 [[[self .mockInstance stub ] andReturn: self .mockContainer] kitContainer_PRIVATE ];
229262 [[[self .mockInstance stub ] andReturn: self .mockInstance] sharedInstance ];
263+ [[[self .identityMock stub ] andReturn: currentUser] currentUser ];
264+
265+ self.mockApiResult = OCMClassMock ([MPIdentityApiResult class ]);
266+ OCMStub ([self .mockApiResult user ]).andReturn (currentUser);
267+
268+ [[[self .identityMock stub ] andDo: ^(NSInvocation *invocation) {
269+ void (^completion)(MPIdentityApiResult * _Nullable, NSError * _Nullable);
270+ [invocation getArgument: &completion atIndex: 3 ];
271+ completion (self.mockApiResult , nil );
272+ }] identify: [OCMArg any ] completion: [OCMArg any ]];
230273
231274 // Set up test parameters
232275 NSString *identifier = @" testView" ;
233276 NSDictionary *attributes = @{@" f.name" : @" Brandon" };
234- NSDictionary *mappedAttributes = @{@" firstname" : @" Brandon" , @" sandbox" : @" true" };
277+ NSDictionary *mappedAttributes = @{@" firstname" : @" Brandon" , @" idfa " : @" C56A4180-65AA-42EC-A945-5FD21DEC0538 " , @" sandbox" : @" true" };
235278
236279 // Set up expectations for kit container
237280 XCTestExpectation *expectation = [self expectationWithDescription: @" Wait for async operation" ];
0 commit comments