Skip to content

Commit

Permalink
fix: prevent mpid with value 0 to forward to Braze (#99)
Browse files Browse the repository at this point in the history
* fix: prevent 0 mpid to forward to Braze

* remove old appboy ABKIDFADelegateKey in unit test
  • Loading branch information
mmustafa-tse authored Nov 4, 2024
1 parent 5f84a82 commit 69255c2
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Sources/mParticle-Appboy/MPKitAppboy.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
89 changes: 88 additions & 1 deletion mParticle_AppboyTests/mParticle_AppboyTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ - (void)setAppboyInstance:(Braze *)instance;
- (void)setEnableTypeDetection:(BOOL)enableTypeDetection;
+ (BOOL)shouldDisableNotificationHandling;
+ (Braze *)brazeInstance;
+ (MPKitExecStatus *)updateUser:(FilteredMParticleUser *)user request:(NSDictionary<NSNumber *,NSString *> *)userIdentities;

@end

Expand Down Expand Up @@ -73,7 +74,6 @@ - (void)testStartwithAdvancedConfig {

NSDictionary *testOptionsDictionary = @{ABKEnableAutomaticLocationCollectionKey:@(YES),
ABKSDKFlavorKey:@7,
ABKIDFADelegateKey: appBoy,
@"ABKRquestProcessingPolicy": @(1),
@"ABKFlushInterval":@(2),
@"ABKSessionTimeout":@(3),
Expand All @@ -84,6 +84,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];
//
Expand Down

0 comments on commit 69255c2

Please sign in to comment.