@@ -35,6 +35,8 @@ + (RoktConfig *)convertMPRoktConfig:(MPRoktConfig *)mpRoktConfig;
3535
3636+ (NSDictionary <NSString *, NSString *> *)transformValuesToString : (NSDictionary <NSString *, id> * _Nullable)originalDictionary ;
3737
38+ + (void )logSelectPlacementEvent : (NSDictionary <NSString *, NSString *> * _Nonnull)attributes ;
39+
3840@end
3941
4042@interface mParticle_RoktTests : XCTestCase
@@ -727,4 +729,71 @@ - (void)testGetRoktHashedEmailUserIdentityTypeNil {
727729 [mockMPKitRoktClass stopMocking ];
728730}
729731
732+ #pragma mark - logSelectPlacementEvent tests
733+
734+ - (void )testExecuteWithIdentifierLogsSelectPlacementEventWithPreparedAttributes {
735+ id mockRoktSDK = OCMClassMock ([Rokt class ]);
736+ id mockMParticleInstance = OCMClassMock ([MParticle class ]);
737+
738+ // Stub the class method sharedInstance to return our mock
739+ id mockMParticleClass = OCMClassMock ([MParticle class ]);
740+ OCMStub ([mockMParticleClass sharedInstance ]).andReturn (mockMParticleInstance);
741+ OCMStub ([(MParticle *)mockMParticleInstance environment ]).andReturn (MPEnvironmentDevelopment);
742+
743+ NSString *identifier = @" TestView" ;
744+ NSDictionary *attributes = @{@" email" : @" test@example.com" };
745+
746+ // Create a mock user with MPID and identities
747+ FilteredMParticleUser *user = [[FilteredMParticleUser alloc ] init ];
748+ id mockUser = OCMPartialMock (user);
749+ OCMStub ([mockUser userId ]).andReturn (@(123456 ));
750+ OCMStub ([mockUser userIdentities ]).andReturn (@{@(MPIdentityEmail): @" test@example.com" });
751+ OCMStub ([mockUser userAttributes ]).andReturn (@{});
752+
753+ // Expect logEvent and verify MPEvent object contains prepared attributes (email, mpid, sandbox)
754+ OCMExpect ([(MParticle *)mockMParticleInstance logEvent: [OCMArg checkWithBlock: ^BOOL (MPEvent *event) {
755+ // Verify the MPEvent object was created correctly
756+ XCTAssertNotNil (event, @" Event object should not be nil" );
757+ XCTAssertEqualObjects (event.name , @" selectPlacements" , @" Event name should be 'selectPlacements'" );
758+ XCTAssertEqual (event.type , MPEventTypeOther, @" Event type should be MPEventTypeOther" );
759+
760+ // Verify custom attributes contain prepared user data
761+ XCTAssertEqualObjects (event.customAttributes [@" email" ], @" test@example.com" , @" Email should be in attributes" );
762+ XCTAssertEqualObjects (event.customAttributes [@" mpid" ], @" 123456" , @" MPID should be in attributes" );
763+ XCTAssertNotNil (event.customAttributes [@" sandbox" ], @" Sandbox should be in attributes" );
764+
765+ return YES ;
766+ }]]);
767+
768+ // Stub Rokt execute call
769+ OCMStub ([mockRoktSDK executeWithViewName: OCMOCK_ANY
770+ attributes: OCMOCK_ANY
771+ placements: OCMOCK_ANY
772+ config: OCMOCK_ANY
773+ onLoad: OCMOCK_ANY
774+ onUnLoad: OCMOCK_ANY
775+ onShouldShowLoadingIndicator: OCMOCK_ANY
776+ onShouldHideLoadingIndicator: OCMOCK_ANY
777+ onEmbeddedSizeChange: OCMOCK_ANY ]);
778+
779+ // Call executeWithIdentifier which triggers logSelectPlacementEvent with prepareAttributes
780+ MPKitExecStatus *status = [self .kitInstance executeWithIdentifier: identifier
781+ attributes: attributes
782+ embeddedViews: nil
783+ config: nil
784+ callbacks: nil
785+ filteredUser: user];
786+
787+ // Verify that logEvent was called with the correct MPEvent object
788+ OCMVerifyAll (mockMParticleInstance);
789+
790+ // Verify execution status
791+ XCTAssertNotNil (status);
792+ XCTAssertEqual (status.returnCode , MPKitReturnCodeSuccess);
793+
794+ [mockRoktSDK stopMocking ];
795+ [mockMParticleClass stopMocking ];
796+ [mockMParticleInstance stopMocking ];
797+ }
798+
730799@end
0 commit comments