From 3734496504f2d260758c24b483cedd87047b16de Mon Sep 17 00:00:00 2001 From: Mo Mustafa Date: Wed, 30 Oct 2024 14:44:17 -0700 Subject: [PATCH 1/2] fix: prevent 0 mpid to forward to Braze --- Sources/mParticle-Appboy/MPKitAppboy.m | 4 +- mParticle_AppboyTests/mParticle_AppboyTests.m | 88 +++++++++++++++++++ 2 files changed, 91 insertions(+), 1 deletion(-) 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]; // From ba23e805a081d2378ce9e8b9c6e2d0f42486c9d2 Mon Sep 17 00:00:00 2001 From: Mo Mustafa Date: Thu, 31 Oct 2024 10:47:22 -0700 Subject: [PATCH 2/2] remove old appboy ABKIDFADelegateKey in unit test --- mParticle_AppboyTests/mParticle_AppboyTests.m | 1 - 1 file changed, 1 deletion(-) diff --git a/mParticle_AppboyTests/mParticle_AppboyTests.m b/mParticle_AppboyTests/mParticle_AppboyTests.m index 77894e2..bc88ddc 100644 --- a/mParticle_AppboyTests/mParticle_AppboyTests.m +++ b/mParticle_AppboyTests/mParticle_AppboyTests.m @@ -74,7 +74,6 @@ - (void)testStartwithAdvancedConfig { NSDictionary *testOptionsDictionary = @{ABKEnableAutomaticLocationCollectionKey:@(YES), ABKSDKFlavorKey:@7, - ABKIDFADelegateKey: appBoy, @"ABKRquestProcessingPolicy": @(1), @"ABKFlushInterval":@(2), @"ABKSessionTimeout":@(3),