diff --git a/Sources/mParticle-Appboy/MPKitAppboy.m b/Sources/mParticle-Appboy/MPKitAppboy.m index 8c0c0ac..23fec01 100644 --- a/Sources/mParticle-Appboy/MPKitAppboy.m +++ b/Sources/mParticle-Appboy/MPKitAppboy.m @@ -391,7 +391,9 @@ - (void)start { #endif FilteredMParticleUser *currentUser = [[self kitApi] getCurrentUserWithKit:self]; - [self updateUser:currentUser request:currentUser.userIdentities]; + if (currentUser.userId.integerValue != 0) { + [self updateUser:currentUser request:currentUser.userIdentities]; + } self->_started = YES; diff --git a/mParticle_AppboyTests/mParticle_AppboyTests.m b/mParticle_AppboyTests/mParticle_AppboyTests.m index 1553a9f..77894e2 100644 --- a/mParticle_AppboyTests/mParticle_AppboyTests.m +++ b/mParticle_AppboyTests/mParticle_AppboyTests.m @@ -18,6 +18,7 @@ - (void)setAppboyInstance:(Braze *)instance; - (void)setEnableTypeDetection:(BOOL)enableTypeDetection; + (BOOL)shouldDisableNotificationHandling; + (Braze *)brazeInstance; ++ (MPKitExecStatus *)updateUser:(FilteredMParticleUser *)user request:(NSDictionary *)userIdentities; @end @@ -84,6 +85,93 @@ - (void)testStartwithAdvancedConfig { XCTAssertEqualObjects(optionsDictionary, testOptionsDictionary); } +- (void)testMpidForwardingOnStartUserIdZero { + NSDictionary *kitConfiguration = @{@"apiKey":@"BrazeID", + @"id":@42, + @"ABKCollectIDFA":@"true", + @"ABKRequestProcessingPolicyOptionKey": @"1", + @"ABKFlushIntervalOptionKey":@"2", + @"ABKSessionTimeoutKey":@"3", + @"ABKMinimumTriggerTimeIntervalKey":@"4", + @"userIdentificationType":@"MPID" + }; + + MPKitAppboy *kitInstance = [[MPKitAppboy alloc] init]; + + [kitInstance didFinishLaunchingWithConfiguration:kitConfiguration]; + + MParticleUser *testUser = [[MParticleUser alloc] init]; + [testUser setValue:@(0) forKey:@"userId"]; + + FilteredMParticleUser *filteredUser = [[FilteredMParticleUser alloc] initWithMParticleUser:testUser kitConfiguration:kitConfiguration]; + id mockKitApi = OCMClassMock([MPKitAPI class]); + OCMStub([mockKitApi getCurrentUserWithKit:kitInstance]).andReturn(filteredUser); + kitInstance.kitApi = mockKitApi; + + id mockKitInstance = OCMPartialMock(kitInstance); + [[mockKitInstance reject] updateUser:[OCMArg any] request:[OCMArg any]]; + [kitInstance start]; + [mockKitInstance verify]; +} + +- (void)testMpidForwardingOnStartUserIdPositive { + NSDictionary *kitConfiguration = @{@"apiKey":@"BrazeID", + @"id":@42, + @"ABKCollectIDFA":@"true", + @"ABKRequestProcessingPolicyOptionKey": @"1", + @"ABKFlushIntervalOptionKey":@"2", + @"ABKSessionTimeoutKey":@"3", + @"ABKMinimumTriggerTimeIntervalKey":@"4", + @"userIdentificationType":@"MPID" + }; + + MPKitAppboy *kitInstance = [[MPKitAppboy alloc] init]; + + [kitInstance didFinishLaunchingWithConfiguration:kitConfiguration]; + + MParticleUser *testUser = [[MParticleUser alloc] init]; + [testUser setValue:@(1) forKey:@"userId"]; + + FilteredMParticleUser *filteredUser = [[FilteredMParticleUser alloc] initWithMParticleUser:testUser kitConfiguration:kitConfiguration]; + id mockKitApi = OCMClassMock([MPKitAPI class]); + OCMStub([mockKitApi getCurrentUserWithKit:kitInstance]).andReturn(filteredUser); + kitInstance.kitApi = mockKitApi; + + id mockKitInstance = OCMPartialMock(kitInstance); + [[mockKitInstance expect] updateUser:[OCMArg any] request:[OCMArg any]]; + [kitInstance start]; + [mockKitInstance verify]; +} + +- (void)testMpidForwardingOnStartUserIdNegative { + NSDictionary *kitConfiguration = @{@"apiKey":@"BrazeID", + @"id":@42, + @"ABKCollectIDFA":@"true", + @"ABKRequestProcessingPolicyOptionKey": @"1", + @"ABKFlushIntervalOptionKey":@"2", + @"ABKSessionTimeoutKey":@"3", + @"ABKMinimumTriggerTimeIntervalKey":@"4", + @"userIdentificationType":@"MPID" + }; + + MPKitAppboy *kitInstance = [[MPKitAppboy alloc] init]; + + [kitInstance didFinishLaunchingWithConfiguration:kitConfiguration]; + + MParticleUser *testUser = [[MParticleUser alloc] init]; + [testUser setValue:@(-1) forKey:@"userId"]; + + FilteredMParticleUser *filteredUser = [[FilteredMParticleUser alloc] initWithMParticleUser:testUser kitConfiguration:kitConfiguration]; + id mockKitApi = OCMClassMock([MPKitAPI class]); + OCMStub([mockKitApi getCurrentUserWithKit:kitInstance]).andReturn(filteredUser); + kitInstance.kitApi = mockKitApi; + + id mockKitInstance = OCMPartialMock(kitInstance); + [[mockKitInstance expect] updateUser:[OCMArg any] request:[OCMArg any]]; + [kitInstance start]; + [mockKitInstance verify]; +} + //- (void)testEndpointOverride { // MPKitAppboy *appBoy = [[MPKitAppboy alloc] init]; //