Skip to content

Commit

Permalink
fix: prevent 0 mpid to forward to Braze
Browse files Browse the repository at this point in the history
  • Loading branch information
mmustafa-tse committed Oct 30, 2024
1 parent 5f84a82 commit 3734496
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 1 deletion.
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
88 changes: 88 additions & 0 deletions 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 @@ -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];
//
Expand Down

0 comments on commit 3734496

Please sign in to comment.