Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion mParticle-Rokt/MPKitRokt.m
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,9 @@ + (NSString *)stringForIdentityType:(MPIdentity)identityType {
}

+ (NSNumber *)identityTypeForString:(NSString *)identityString {
if (identityString == nil) {
return nil;
}
NSDictionary<NSString *, NSNumber *> *identityNumbers = @{@"customerid": @(MPIdentityCustomerId),
@"email": @(MPIdentityEmail),
@"facebook": @(MPIdentityFacebook),
Expand Down Expand Up @@ -434,7 +437,7 @@ + (NSNumber *)identityTypeForString:(NSString *)identityString {
return identityNumbers[identityString];
}

+ (NSNumber *)getRoktHashedEmailUserIdentityType {
+ (NSDictionary *)getKitConfig {
// Get the kit configuration
NSArray<NSDictionary *> *kitConfigs = [MParticle sharedInstance].kitContainer_PRIVATE.originalConfig.copy;
NSDictionary *roktKitConfig;
Expand All @@ -444,6 +447,12 @@ + (NSNumber *)getRoktHashedEmailUserIdentityType {
}
}

return roktKitConfig;
}

+ (NSNumber *)getRoktHashedEmailUserIdentityType {
NSDictionary *roktKitConfig = [MPKitRokt getKitConfig];

// Get the string representing which identity to use and convert it to the key (NSNumber)
NSString *hashedIdentityTypeString = roktKitConfig[kMPHashedEmailUserIdentityType];
NSNumber *hashedIdentityTypeNumber = [MPKitRokt identityTypeForString:hashedIdentityTypeString.lowercaseString];
Expand Down
50 changes: 50 additions & 0 deletions mParticle_RoktTests/mParticle_RoktTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#import <mParticle_Rokt/mParticle_Rokt.h>
#import "MPKitRokt.h"

NSInteger const kMPRoktKitCode = 181;
NSString * const kMPHashedEmailUserIdentityType = @"hashedEmailUserIdentityType";

@interface MPKitRokt ()

- (MPKitExecStatus *)executeWithIdentifier:(NSString * _Nullable)identifier
Expand All @@ -24,6 +27,8 @@ + (void)addIdentityAttributes:(NSMutableDictionary<NSString *, NSString *> * _Nu

+ (void)handleHashedEmail:(NSMutableDictionary<NSString *, NSString *> * _Nullable)attributes;

+ (NSDictionary *)getKitConfig;

+ (NSNumber *)getRoktHashedEmailUserIdentityType;

+ (RoktConfig *)convertMPRoktConfig:(MPRoktConfig *)mpRoktConfig;
Expand Down Expand Up @@ -677,4 +682,49 @@ - (void)testTransformValuesToString {
XCTAssertTrue(finalAtt.allKeys.count == 4);
}

- (void)testGetRoktHashedEmailUserIdentityTypeOther4 {
// Test case 1: When kit configuration exists with hashed email identity type
NSDictionary *roktKitConfig = @{
@"id": @(kMPRoktKitCode),
kMPHashedEmailUserIdentityType: @"other4"
};

// Mock the MParticle shared instance and kit container
id mockMPKitRoktClass = OCMClassMock([MPKitRokt class]);
[[[mockMPKitRoktClass stub] andReturn:roktKitConfig] getKitConfig];

// Call the method and verify result
NSNumber *result = [MPKitRokt getRoktHashedEmailUserIdentityType];
XCTAssertEqualObjects(result, @(MPIdentityOther4), @"Should return MPIdentityOther4 when configured with 'other4'");

[mockMPKitRoktClass stopMocking];
}

- (void)testGetRoktHashedEmailUserIdentityTypeConfigNil {
// Test case 2: When kit config nil
// Mock the MParticle shared instance and kit container
id mockMPKitRoktClass = OCMClassMock([MPKitRokt class]);
[[[mockMPKitRoktClass stub] andReturn:nil] getKitConfig];

NSNumber *defaultResult = [MPKitRokt getRoktHashedEmailUserIdentityType];
XCTAssertNil(defaultResult, @"Should return nil when when no configuration exists");

[mockMPKitRoktClass stopMocking];
}

- (void)testGetRoktHashedEmailUserIdentityTypeNil {
// Mock the MParticle shared instance and kit container
id mockMPKitRoktClass = OCMClassMock([MPKitRokt class]);
// Test case 3: When kit config exists but no hashed email identity type specified
NSDictionary *roktKitConfigNoHash = @{
@"id": @(kMPRoktKitCode)
};
[[[mockMPKitRoktClass stub] andReturn:roktKitConfigNoHash] getKitConfig];

NSNumber *noHashResult = [MPKitRokt getRoktHashedEmailUserIdentityType];
XCTAssertNil(noHashResult, @"Should return nil when hashed email identity type not specified");

[mockMPKitRoktClass stopMocking];
}

@end
Loading