Skip to content
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
1 change: 1 addition & 0 deletions UnitTests/MParticle+PrivateMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@

@property (nonatomic, strong, nonnull) id<MPBackendControllerProtocol> backendController;
@property (nonatomic, strong) id<MPAppNotificationHandlerProtocol> appNotificationHandler;
@property (nonatomic, strong) SceneDelegateHandler *sceneDelegateHandler;
@property (nonatomic, strong) id<SettingsProviderProtocol> settingsProvider;
@property (nonatomic, strong, nullable) id<MPDataPlanFilterProtocol> dataPlanFilter;
@property (nonatomic, strong, nonnull) id<MPListenerControllerProtocol> listenerController;
Expand Down
31 changes: 31 additions & 0 deletions UnitTests/Mocks/SceneDelegateHandlerMock.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import XCTest
#if MPARTICLE_LOCATION_DISABLE
import mParticle_Apple_SDK_NoLocation
#else
import mParticle_Apple_SDK
#endif

class OpenURLHandlerProtocolMock: OpenURLHandlerProtocol {

var openURLWithOptionsCalled = false
var openURLWithOptionsURLParam: URL?
var openURLWithOptionsOptionsParam: [String : Any]?

func open(_ url: URL, options: [String : Any]?) {
openURLWithOptionsCalled = true
openURLWithOptionsURLParam = url
openURLWithOptionsOptionsParam = options
}

var continueUserActivityCalled = false
var continueUserActivityUserActivityParam: NSUserActivity?
var continueUserActivityRestorationHandlerParam: (([UIUserActivityRestoring]?) -> Void)?
var continueUserActivityReturnValue: Bool = false

func continueUserActivity(_ userActivity: NSUserActivity, restorationHandler: @escaping ([any UIUserActivityRestoring]?) -> Void) -> Bool {
continueUserActivityCalled = true
continueUserActivityUserActivityParam = userActivity
continueUserActivityRestorationHandlerParam = restorationHandler
return continueUserActivityReturnValue
}
}
6 changes: 1 addition & 5 deletions UnitTests/ObjCTests/MPCommerceEventTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -325,17 +325,13 @@ - (void)testCommerceEventProductDeprecated {
XCTAssertNotNil(commerceEvent, @"Commerce event should not have been nil.");
XCTAssertEqual(commerceEvent.products.count, 1, @"Incorrect product count.");

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
commerceEvent.checkoutOptions = @"option 1";
commerceEvent.screenName = @"Time Traveling";
commerceEvent.checkoutStep = 1;
commerceEvent[@"key_string"] = @"val_string";
commerceEvent[@"key_number"] = @"3.14";
commerceEvent.customAttributes = @{@"key_string": @"val_string", @"key_number": @"3.14"};
commerceEvent.currency = @"bitcoins";
commerceEvent.nonInteractive = YES;
commerceEvent.screenName = @"time machine screen";
#pragma clang diagnostic pop

product = [[MPProduct alloc] initWithName:@"Tardis" sku:@"trds" quantity:@1 price:@7.89];
product.brand = @"Gallifrey Tardis";
Expand Down
8 changes: 0 additions & 8 deletions UnitTests/ObjCTests/MPEventTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,12 @@ - (void)testInstance {
event.category = mock;

XCTAssertNil(event.category, @"Should have been nil.");

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
XCTAssertNotNil(event.customAttributes, @"Should not have been nil.");
XCTAssertNotNil(event.info, @"Should not have been nil.");

XCTAssertEqual(event.customAttributes.count, 3, @"Should have been three values in the customAttributes dictionary.");
XCTAssertEqual(event.info.count, 3, @"Should have been three values in the info dictionary.");

NSDictionary *copyEventInfo = [eventInfo copy];
event.customAttributes = copyEventInfo;
XCTAssertEqualObjects(event.customAttributes, eventInfo, @"Should have been equal.");
XCTAssertEqualObjects(event.info, eventInfo, @"Should have been equal.");
#pragma clang diagnostic pop

event = [[MPEvent alloc] init];
XCTAssertNotNil(event, @"Should not have been nil.");
Expand Down
4 changes: 2 additions & 2 deletions UnitTests/ObjCTests/MPKitConfigurationTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ - (void)tearDown {

- (void)testInstance {
XCTAssertNotNil(kitConfiguration);
XCTAssertEqualObjects(kitConfiguration.configurationHash, @(762651950));
XCTAssertEqualObjects(kitConfiguration.configurationHash, @(969680750));
XCTAssertEqualObjects(kitConfiguration.integrationId, @37);
XCTAssertEqualObjects(kitConfiguration.attributeValueFilteringHashedAttribute, @"12345");
XCTAssertEqualObjects(kitConfiguration.attributeValueFilteringHashedValue, @"54321");
Expand Down Expand Up @@ -183,7 +183,7 @@ - (void)testInvalidConfiguration {

kitConfig = [[MPKitConfiguration alloc] initWithDictionary:configuration];
XCTAssertNotNil(kitConfig);
XCTAssertEqualObjects(kitConfig.configurationHash, @(1495473349));
XCTAssertEqualObjects(kitConfig.configurationHash, @(-1872513399));
XCTAssertEqualObjects(kitConfig.integrationId, @80);

XCTAssertNil(kitConfig.filters);
Expand Down
14 changes: 0 additions & 14 deletions UnitTests/ObjCTests/MParticleTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -795,20 +795,6 @@ - (void)testLogNilScreenEvent {
XCTAssertNil(e);
}

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
- (void)testLogNilCommerceEvent {
MParticle *instance = [MParticle sharedInstance];
NSException *e = nil;
@try {
[instance logCommerceEvent:(id _Nonnull)nil];
} @catch (NSException *ex) {
e = ex;
}
XCTAssertNil(e);
}
#pragma clang diagnostic pop

- (void)testSetATTStatusNotDetermined {
MParticle *instance = [MParticle sharedInstance];
MParticleUser *currentUser = [[[MParticle sharedInstance] identity] currentUser];
Expand Down
7 changes: 0 additions & 7 deletions UnitTests/SwiftTests/MPEventTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class MPEventTests: XCTestCase {
XCTAssertNotNil(sut)
XCTAssertEqual(sut.name, "<<Event With No Name>>")
XCTAssertEqual(sut.duration, 0)
XCTAssertNil(sut.info)
XCTAssertNil(sut.category)
XCTAssertNil(sut.endTime)
XCTAssertNil(sut.startTime)
Expand Down Expand Up @@ -236,12 +235,6 @@ class MPEventTests: XCTestCase {
XCTAssertEqual(ts, expected)
}

func testInfoAndSetInfo_mapsToCustomAttributes() {
sut.info = ["a": "1"]
XCTAssertEqual(sut.info?["a"] as? String, "1")
XCTAssertEqual(sut.customAttributes?["a"] as? String, "1")
}

func testSetName_withEmptyName_discardsAndLogs() {
let logger = MParticle.sharedInstance().getLogger()!
logger.logLevel = .verbose
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@

#if MPARTICLE_LOCATION_DISABLE
import mParticle_Apple_SDK_NoLocation
#else
import mParticle_Apple_SDK
#endif
import XCTest

final class MParticleSceneDelegateTests: XCTestCase {

// MARK: - Properties
var mparticle: MParticle!
var sceneMock: OpenURLHandlerProtocolMock!
var testURL: URL!
var testUserActivity: NSUserActivity!

override func setUp() {
super.setUp()
mparticle = MParticle()
testURL = URL(string: "myapp://test/path?param=value")!
testUserActivity = NSUserActivity(activityType: "com.test.activity")
testUserActivity.title = "Test Activity"
testUserActivity.userInfo = ["key": "value"]

// The implementation calls [MParticle sharedInstance], so we need to set the mock on the shared instance
sceneMock = OpenURLHandlerProtocolMock()
let sceneHandler = SceneDelegateHandler(logger: MPLog(logLevel: .verbose), appNotificationHandler: sceneMock)
mparticle.sceneDelegateHandler = sceneHandler
}

// MARK: - handleUserActivity Tests
func test_handleUserActivity_invokesAppNotificationHandler() {
// Act
mparticle.handleUserActivity(testUserActivity)

// Assert - handleUserActivity directly calls the app notification handler
XCTAssertTrue(sceneMock.continueUserActivityCalled)
XCTAssertEqual(sceneMock.continueUserActivityUserActivityParam, testUserActivity)
XCTAssertNotNil(sceneMock.continueUserActivityRestorationHandlerParam)
}

func test_handleUserActivity_withWebBrowsingActivity() {
// Arrange
let webActivity = NSUserActivity(activityType: NSUserActivityTypeBrowsingWeb)
webActivity.title = "Web Page"
webActivity.webpageURL = URL(string: "https://example.com/page")

// Act
mparticle.handleUserActivity(webActivity)

// Assert - Direct call to app notification handler
XCTAssertTrue(sceneMock.continueUserActivityCalled)
XCTAssertEqual(sceneMock.continueUserActivityUserActivityParam, webActivity)
}

func test_handleUserActivity_restorationHandlerIsEmpty() {
// Act
mparticle.handleUserActivity(testUserActivity)

// Assert
XCTAssertTrue(sceneMock.continueUserActivityCalled)

// Verify the restoration handler is provided and safe to call
let restorationHandler = sceneMock.continueUserActivityRestorationHandlerParam
XCTAssertNotNil(restorationHandler)

// Test that calling the restoration handler doesn't crash
XCTAssertNoThrow(restorationHandler?(nil))
XCTAssertNoThrow(restorationHandler?([]))
}
}
4 changes: 2 additions & 2 deletions mParticle-Apple-SDK.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ Pod::Spec.new do |s|
s.requires_arc = true
s.default_subspec = 'mParticle'
s.module_name = 'mParticle_Apple_SDK'
s.ios.deployment_target = "9.0"
s.tvos.deployment_target = "9.0"
s.ios.deployment_target = "15.6"
s.tvos.deployment_target = "15.6"
s.swift_versions = ["5.0"]

s.subspec 'mParticle' do |ss|
Expand Down
Loading
Loading