Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent mpid with value 0 to forward to Braze #99

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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