diff --git a/UnitTests/MPIdentityApiRequestTests.m b/UnitTests/MPIdentityApiRequestTests.m index 404766c4..5de91763 100644 --- a/UnitTests/MPIdentityApiRequestTests.m +++ b/UnitTests/MPIdentityApiRequestTests.m @@ -6,6 +6,10 @@ @interface MPIdentityApiRequestTests : MPBaseTestCase @end +@interface MPIdentityApiRequest () +@property (nonatomic) NSMutableDictionary *mutableIdentities; +@end + @implementation MPIdentityApiRequestTests - (void)testSetNilIdentity { @@ -24,7 +28,7 @@ - (void)testSetNullIdentity { XCTAssertEqualObjects([NSNull null], [request.identities objectForKey:@(MPIdentityOther)]); } -- (void)testsetIdentity { +- (void)testSetIdentity { MPIdentityApiRequest *request = [[MPIdentityApiRequest alloc] init]; [request setIdentity:@"foo" identityType:MPIdentityOther]; XCTAssertEqualObjects(@"foo", [request.identities objectForKey:@(MPIdentityOther)]); @@ -49,4 +53,28 @@ - (void)testIdentitiesAreNotNull { XCTAssertNotEqualObjects(request.customerId, [NSNull null]); } +- (void)testSetEmail { + MPIdentityApiRequest *request = [[MPIdentityApiRequest alloc] init]; + XCTAssertNil(request.email); + request.email = @"test@test.com"; + XCTAssertEqualObjects(@"test@test.com", request.email); + XCTAssertEqualObjects(@"test@test.com", request.mutableIdentities[@(MPIdentityEmail)]); + + request.email = nil; + XCTAssertNil(request.email); + XCTAssertEqualObjects(request.mutableIdentities[@(MPIdentityEmail)], [NSNull null]); +} + +- (void)testSetCustomerId { + MPIdentityApiRequest *request = [[MPIdentityApiRequest alloc] init]; + XCTAssertNil(request.customerId); + request.customerId = @"some id"; + XCTAssertEqualObjects(@"some id", request.customerId); + XCTAssertEqualObjects(@"some id", request.mutableIdentities[@(MPIdentityCustomerId)]); + + request.customerId = nil; + XCTAssertNil(request.customerId); + XCTAssertEqualObjects(request.mutableIdentities[@(MPIdentityCustomerId)], [NSNull null]); +} + @end diff --git a/UnitTests/MPSwiftTests.swift b/UnitTests/MPSwiftTests.swift index bf7df30d..b773d705 100644 --- a/UnitTests/MPSwiftTests.swift +++ b/UnitTests/MPSwiftTests.swift @@ -64,4 +64,19 @@ class mParticle_Swift_SDKTests: XCTestCase { XCTAssertNotNil(MPIdentityErrorResponseCode(rawValue: 500)) XCTAssertNotNil(MPIdentityErrorResponseCode(rawValue: 502)) } + + func testMPIdentityApiRequestIdentitiesInterop() { + let request = MPIdentityApiRequest() + request.setIdentity("test id", identityType: .customerId) + request.setIdentity("test@test.com", identityType: .email) + + var identities = [NSNumber: NSObject]() + identities[NSNumber(value: MPIdentity.customerId.rawValue)] = NSString(string: "test id") + identities[NSNumber(value: MPIdentity.email.rawValue)] = NSString(string: "test@test.com") + XCTAssertEqual(identities, request.identities); + + request.email = nil + identities[NSNumber(value: MPIdentity.email.rawValue)] = NSNull() + XCTAssertEqual(identities, request.identities); + } } diff --git a/mParticle-Apple-SDK/Identity/FilteredMPIdentityApiRequest.m b/mParticle-Apple-SDK/Identity/FilteredMPIdentityApiRequest.m index 69ca3da0..eef38c34 100644 --- a/mParticle-Apple-SDK/Identity/FilteredMPIdentityApiRequest.m +++ b/mParticle-Apple-SDK/Identity/FilteredMPIdentityApiRequest.m @@ -37,7 +37,7 @@ - (instancetype)initWithIdentityRequest:(MPIdentityApiRequest *)request kitConfi } - (NSDictionary *)userIdentities { - NSDictionary *unfilteredUserIdentities = self.request.identities; + NSDictionary *unfilteredUserIdentities = self.request.identities; NSMutableDictionary *filteredUserIdentities = [NSMutableDictionary dictionary]; for (NSNumber* key in unfilteredUserIdentities) { diff --git a/mParticle-Apple-SDK/Identity/MPIdentityApiRequest.m b/mParticle-Apple-SDK/Identity/MPIdentityApiRequest.m index 520653e1..55f8049d 100644 --- a/mParticle-Apple-SDK/Identity/MPIdentityApiRequest.m +++ b/mParticle-Apple-SDK/Identity/MPIdentityApiRequest.m @@ -11,7 +11,7 @@ #import "MPIdentityDTO.h" @interface MPIdentityApiRequest () -@property (nonatomic) NSMutableDictionary *mutableIdentities; +@property (nonatomic) NSMutableDictionary *mutableIdentities; @end @implementation MPIdentityApiRequest @@ -50,11 +50,11 @@ + (MPIdentityApiRequest *)requestWithUser:(MParticleUser *) user { } - (NSString *)email { - NSString *result = _mutableIdentities[@(MPIdentityEmail)]; - if ([result isEqual:[NSNull null]]) { - result = nil; + NSObject *result = _mutableIdentities[@(MPIdentityEmail)]; + if ([result isKindOfClass:[NSString class]]) { + return (NSString *)result; } - return result; + return nil; } - (void)setEmail:(NSString *)email { @@ -62,18 +62,18 @@ - (void)setEmail:(NSString *)email { } - (NSString *)customerId { - NSString *result = _mutableIdentities[@(MPIdentityCustomerId)]; - if ([result isEqual:[NSNull null]]) { - result = nil; + NSObject *result = _mutableIdentities[@(MPIdentityCustomerId)]; + if ([result isKindOfClass:[NSString class]]) { + return (NSString *)result; } - return result; + return nil; } - (void)setCustomerId:(NSString *)customerId { [self setIdentity:customerId identityType:MPIdentityCustomerId]; } -- (NSDictionary *)identities { +- (NSDictionary *)identities { return [_mutableIdentities copy]; } diff --git a/mParticle-Apple-SDK/Include/MPIdentityApiRequest.h b/mParticle-Apple-SDK/Include/MPIdentityApiRequest.h index d1578d45..3f571b9c 100644 --- a/mParticle-Apple-SDK/Include/MPIdentityApiRequest.h +++ b/mParticle-Apple-SDK/Include/MPIdentityApiRequest.h @@ -21,7 +21,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, strong, nullable) NSString *email; @property (nonatomic, strong, nullable) NSString *customerId; -@property (nonatomic, strong, nullable, readonly) NSDictionary *identities; +@property (nonatomic, strong, nullable, readonly) NSDictionary *identities; @end