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

[v5] Fix crash with direct influence but nil direct id #1327

Merged
merged 2 commits into from
Oct 30, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,13 @@ - (OSInfluence *)currentSessionInfluence {

if (_influenceType == DIRECT) {
if ([self isDirectSessionEnabled]) {
NSArray *ids = [NSArray arrayWithObject:_directId];
builder.ids = ids;
builder.influenceType = DIRECT;
if (_directId) {
NSArray *ids = [NSArray arrayWithObject:_directId];
builder.ids = ids;
builder.influenceType = DIRECT;
} else {
[OneSignalLog onesignalLog:ONE_S_LL_ERROR message:@"OSChannelTracker:currentSessionInfluence found a direct influence without a direct id."];
}
}
} else if (_influenceType == INDIRECT) {
if ([self isIndirectSessionEnabled]) {
Expand Down
16 changes: 16 additions & 0 deletions iOS_SDK/OneSignalSDK/UnitTests/ChannelTrackersTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#import "OneSignalHelper.h"

#import "UnitTestCommonMethods.h"
#import "OSNotificationTracker.h"
#import "CommonAsserts.h"

@interface ChannelTrackersTests : XCTestCase
Expand Down Expand Up @@ -167,4 +168,19 @@ - (void)testGetChannelToResetByEntryAction {
XCTAssertEqualObjects(@"iam_id", [[[trackerFactory channelsToResetByEntryAction:NOTIFICATION_CLICK] objectAtIndex:0] idTag]);
}

- (void)testDirectInfluenceWithNullId {
[self setOutcomesParamsEnabled];
OSNotificationTracker *channelTracker = [[OSNotificationTracker alloc] initWithRepository:[OSInfluenceDataRepository sharedInfluenceDataRepository]];
// Set the influence type to direct but do not set the direct id
channelTracker.influenceType = DIRECT;
OSInfluence *influence = [channelTracker currentSessionInfluence];
// The current influence was invalid so the type should be disabled
XCTAssertEqual(influence.influenceType, DISABLED);
// Set the directId
channelTracker.directId = @"testid";
influence = [channelTracker currentSessionInfluence];
// Now that the directId is set the influence should be valid.
XCTAssertEqual(influence.influenceType, DIRECT);
}

@end
Loading