Skip to content

Commit 21f2c62

Browse files
fix: Add Nil Check Around Unassigned Logic (#37)
* fix: Add Nil Check Around Unassigned Logic
1 parent e5683fb commit 21f2c62

2 files changed

Lines changed: 60 additions & 1 deletion

File tree

mParticle-Rokt/MPKitRokt.m

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,9 @@ + (NSString *)stringForIdentityType:(MPIdentity)identityType {
405405
}
406406

407407
+ (NSNumber *)identityTypeForString:(NSString *)identityString {
408+
if (identityString == nil) {
409+
return nil;
410+
}
408411
NSDictionary<NSString *, NSNumber *> *identityNumbers = @{@"customerid": @(MPIdentityCustomerId),
409412
@"email": @(MPIdentityEmail),
410413
@"facebook": @(MPIdentityFacebook),
@@ -434,7 +437,7 @@ + (NSNumber *)identityTypeForString:(NSString *)identityString {
434437
return identityNumbers[identityString];
435438
}
436439

437-
+ (NSNumber *)getRoktHashedEmailUserIdentityType {
440+
+ (NSDictionary *)getKitConfig {
438441
// Get the kit configuration
439442
NSArray<NSDictionary *> *kitConfigs = [MParticle sharedInstance].kitContainer_PRIVATE.originalConfig.copy;
440443
NSDictionary *roktKitConfig;
@@ -444,6 +447,12 @@ + (NSNumber *)getRoktHashedEmailUserIdentityType {
444447
}
445448
}
446449

450+
return roktKitConfig;
451+
}
452+
453+
+ (NSNumber *)getRoktHashedEmailUserIdentityType {
454+
NSDictionary *roktKitConfig = [MPKitRokt getKitConfig];
455+
447456
// Get the string representing which identity to use and convert it to the key (NSNumber)
448457
NSString *hashedIdentityTypeString = roktKitConfig[kMPHashedEmailUserIdentityType];
449458
NSNumber *hashedIdentityTypeNumber = [MPKitRokt identityTypeForString:hashedIdentityTypeString.lowercaseString];

mParticle_RoktTests/mParticle_RoktTests.m

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
#import <mParticle_Rokt/mParticle_Rokt.h>
55
#import "MPKitRokt.h"
66

7+
NSInteger const kMPRoktKitCode = 181;
8+
NSString * const kMPHashedEmailUserIdentityType = @"hashedEmailUserIdentityType";
9+
710
@interface MPKitRokt ()
811

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

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

30+
+ (NSDictionary *)getKitConfig;
31+
2732
+ (NSNumber *)getRoktHashedEmailUserIdentityType;
2833

2934
+ (RoktConfig *)convertMPRoktConfig:(MPRoktConfig *)mpRoktConfig;
@@ -677,4 +682,49 @@ - (void)testTransformValuesToString {
677682
XCTAssertTrue(finalAtt.allKeys.count == 4);
678683
}
679684

685+
- (void)testGetRoktHashedEmailUserIdentityTypeOther4 {
686+
// Test case 1: When kit configuration exists with hashed email identity type
687+
NSDictionary *roktKitConfig = @{
688+
@"id": @(kMPRoktKitCode),
689+
kMPHashedEmailUserIdentityType: @"other4"
690+
};
691+
692+
// Mock the MParticle shared instance and kit container
693+
id mockMPKitRoktClass = OCMClassMock([MPKitRokt class]);
694+
[[[mockMPKitRoktClass stub] andReturn:roktKitConfig] getKitConfig];
695+
696+
// Call the method and verify result
697+
NSNumber *result = [MPKitRokt getRoktHashedEmailUserIdentityType];
698+
XCTAssertEqualObjects(result, @(MPIdentityOther4), @"Should return MPIdentityOther4 when configured with 'other4'");
699+
700+
[mockMPKitRoktClass stopMocking];
701+
}
702+
703+
- (void)testGetRoktHashedEmailUserIdentityTypeConfigNil {
704+
// Test case 2: When kit config nil
705+
// Mock the MParticle shared instance and kit container
706+
id mockMPKitRoktClass = OCMClassMock([MPKitRokt class]);
707+
[[[mockMPKitRoktClass stub] andReturn:nil] getKitConfig];
708+
709+
NSNumber *defaultResult = [MPKitRokt getRoktHashedEmailUserIdentityType];
710+
XCTAssertNil(defaultResult, @"Should return nil when when no configuration exists");
711+
712+
[mockMPKitRoktClass stopMocking];
713+
}
714+
715+
- (void)testGetRoktHashedEmailUserIdentityTypeNil {
716+
// Mock the MParticle shared instance and kit container
717+
id mockMPKitRoktClass = OCMClassMock([MPKitRokt class]);
718+
// Test case 3: When kit config exists but no hashed email identity type specified
719+
NSDictionary *roktKitConfigNoHash = @{
720+
@"id": @(kMPRoktKitCode)
721+
};
722+
[[[mockMPKitRoktClass stub] andReturn:roktKitConfigNoHash] getKitConfig];
723+
724+
NSNumber *noHashResult = [MPKitRokt getRoktHashedEmailUserIdentityType];
725+
XCTAssertNil(noHashResult, @"Should return nil when hashed email identity type not specified");
726+
727+
[mockMPKitRoktClass stopMocking];
728+
}
729+
680730
@end

0 commit comments

Comments
 (0)