Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
5 changes: 5 additions & 0 deletions UnitTests/MParticle+PrivateMethods.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#import "SettingsProvider.h"
#import "MParticleSwift.h"
#import "MPDataPlanFilter.h"

@interface MParticle (Tests)
- (void)setOptOutCompletion:(MPExecStatus)execStatus optOut:(BOOL)optOut;
Expand All @@ -8,7 +9,11 @@
options:(MParticleOptions * _Nonnull)options;
- (void)configureWithOptions:(MParticleOptions * _Nonnull)options;
- (void)startWithKeyCallback:(BOOL)firstRun options:(MParticleOptions * _Nonnull)options userDefaults:(id<MPUserDefaultsProtocol>)userDefaults;
- (void)beginTimedEventCompletionHandler:(MPEvent *)event execStatus:(MPExecStatus)execStatus;
- (void)logEventCallback:(MPEvent *)event execStatus:(MPExecStatus)execStatus;

@property (nonatomic, strong, nonnull) MPBackendController_PRIVATE *backendController;
@property (nonatomic, strong) id<SettingsProviderProtocol> settingsProvider;
@property (nonatomic, strong, nullable) id<MPDataPlanFilterProtocol> dataPlanFilter;
@end

58 changes: 58 additions & 0 deletions UnitTests/MParticleTestsSwift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class MParticleTestsSwift: XCTestCase {
override func tearDown() {
super.tearDown()
receivedMessage = nil
mparticle.dataPlanFilter = nil
}

func testSetOptOutCompletionSuccess() {
Expand Down Expand Up @@ -140,4 +141,61 @@ class MParticleTestsSwift: XCTestCase {
XCTAssertFalse(userDefaults.setMPObjectCalled)
XCTAssertFalse(userDefaults.synchronizeCalled)
}

func testBeginTimedEventCompletionHandlerDataFilterNotSet() {
XCTAssertNil(mparticle.dataPlanFilter)

mparticle.beginTimedEventCompletionHandler(MPEvent(), execStatus: .success)
XCTAssertEqual(receivedMessage, """
mParticle -> Began timed event: Event:{
Name: <<Event With No Name>>
Type: Other
Duration: 0
}
"""
)
}

func testBeginTimedEventCompletionHandlerDataFilterSetDataFilterReturnNil() {
let dataPlanFilter = MPDataPlanFilterMock()
mparticle.dataPlanFilter = dataPlanFilter
let expectedEvent = MPEvent()

mparticle.beginTimedEventCompletionHandler(expectedEvent, execStatus: .success)
XCTAssert(dataPlanFilter.transformEventCalled)
XCTAssertTrue(dataPlanFilter.transformEventEventParam === expectedEvent)
XCTAssertEqual(receivedMessage, """
mParticle -> Blocked timed event begin from kits: Event:{
Name: <<Event With No Name>>
Type: Other\n Duration: 0
}
"""
)
}

func testLogEventCallbackDataFilterNotSet() {
XCTAssertNil(mparticle.dataPlanFilter)
mparticle.logEventCallback(MPEvent(), execStatus: .success)

XCTAssertNil(receivedMessage)
}

func testLogEventCallbackrDataFilterSetDataFilterReturnNil() {
let dataPlanFilter = MPDataPlanFilterMock()
mparticle.dataPlanFilter = dataPlanFilter
let expectedEvent = MPEvent()
mparticle.logEventCallback(expectedEvent, execStatus: .success)

XCTAssert(dataPlanFilter.transformEventCalled)
XCTAssertTrue(dataPlanFilter.transformEventEventParam === expectedEvent)

XCTAssertEqual(receivedMessage, """
mParticle -> Blocked timed event end from kits: Event:{
Name: <<Event With No Name>>
Type: Other
Duration: 0
}
"""
)
}
}
38 changes: 38 additions & 0 deletions UnitTests/Mocks/MPDataPlanFilterMock.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import XCTest
#if MPARTICLE_LOCATION_DISABLE
import mParticle_Apple_SDK_NoLocation
#else
import mParticle_Apple_SDK
#endif

class MPDataPlanFilterMock: NSObject, MPDataPlanFilterProtocol {
var isBlockedUserIdentityTypeCalled = false
var isBlockedUserIdentityTypeUserIdentityTypeParam: MPIdentity?
var isBlockedUserIdentityTypeReturnValue: Bool = false

func isBlockedUserIdentityType(_ userIdentityType: MPIdentity) -> Bool {
isBlockedUserIdentityTypeCalled = true
isBlockedUserIdentityTypeUserIdentityTypeParam = userIdentityType
return isBlockedUserIdentityTypeReturnValue
}

var isBlockedUserAttributeKeyCalled = false
var isBlockedUserAttributeKeyUserAttributeKeyParam: String?
var isBlockedUserAttributeKeyReturnValue: Bool = false

func isBlockedUserAttributeKey(_ userAttributeKey: String) -> Bool {
isBlockedUserAttributeKeyCalled = true
isBlockedUserAttributeKeyUserAttributeKeyParam = userAttributeKey
return isBlockedUserAttributeKeyReturnValue
}

var transformEventCalled = false
var transformEventEventParam: MPEvent?
var transformEventReturnValue: MPEvent?

func transformEvent(for event: MPEvent) -> MPEvent? {
transformEventCalled = true
transformEventEventParam = event
return transformEventReturnValue
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ class MPUserDefaultsMock: MPUserDefaultsProtocol {
synchronizeCalled = true
}
}


10 changes: 10 additions & 0 deletions UnitTests/Mocks/SettingsProviderMock.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import XCTest
#if MPARTICLE_LOCATION_DISABLE
import mParticle_Apple_SDK_NoLocation
#else
import mParticle_Apple_SDK
#endif

class SettingsProviderMock: NSObject, SettingsProviderProtocol {
var configSettings: NSMutableDictionary?
}
5 changes: 0 additions & 5 deletions UnitTests/SettingsProviderMock.h

This file was deleted.

4 changes: 0 additions & 4 deletions UnitTests/SettingsProviderMock.m

This file was deleted.

1 change: 0 additions & 1 deletion UnitTests/mParticle_iOS_SDKTests-Bridging-Header.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@
#import "MParticleOptions+MParticlePrivate.h"
#import "MParticle+PrivateMethods.h"
#import "SettingsProvider.h"
#import "SettingsProviderMock.h"
30 changes: 21 additions & 9 deletions mParticle-Apple-SDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
35329FF32E54CA78009AC4FD /* MParticleOptions+MParticlePrivate.m in Sources */ = {isa = PBXBuildFile; fileRef = 35329FF12E54CA78009AC4FD /* MParticleOptions+MParticlePrivate.m */; };
35329FF52E54CB8C009AC4FD /* MParticleOptions+MParticlePrivateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35329FF42E54CB84009AC4FD /* MParticleOptions+MParticlePrivateTests.swift */; };
35329FF62E54CB8C009AC4FD /* MParticleOptions+MParticlePrivateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35329FF42E54CB84009AC4FD /* MParticleOptions+MParticlePrivateTests.swift */; };
356D4A592E58B09D00CB69FE /* SettingsProviderMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 356D4A582E58B09D00CB69FE /* SettingsProviderMock.swift */; };
356D4A5A2E58B09D00CB69FE /* SettingsProviderMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 356D4A582E58B09D00CB69FE /* SettingsProviderMock.swift */; };
356D4A5C2E58B25900CB69FE /* MPDataPlanFilterMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 356D4A5B2E58B25500CB69FE /* MPDataPlanFilterMock.swift */; };
356D4A5D2E58B25900CB69FE /* MPDataPlanFilterMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 356D4A5B2E58B25500CB69FE /* MPDataPlanFilterMock.swift */; };
359BAFE82E55ED8900A8A704 /* MParticleTestsSwift.swift in Sources */ = {isa = PBXBuildFile; fileRef = 359BAFE72E55ED7D00A8A704 /* MParticleTestsSwift.swift */; };
359BAFE92E55ED8900A8A704 /* MParticleTestsSwift.swift in Sources */ = {isa = PBXBuildFile; fileRef = 359BAFE72E55ED7D00A8A704 /* MParticleTestsSwift.swift */; };
359BAFF92E56330200A8A704 /* SettingsProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 359BAFF82E56330200A8A704 /* SettingsProvider.h */; };
Expand All @@ -25,8 +29,6 @@
359BAFFD2E56335300A8A704 /* SettingsProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = 359BAFFB2E56335300A8A704 /* SettingsProvider.m */; };
359BAFFF2E575B0300A8A704 /* SettingsProviderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 359BAFFE2E575AF500A8A704 /* SettingsProviderTests.swift */; };
359BB0002E575B0300A8A704 /* SettingsProviderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 359BAFFE2E575AF500A8A704 /* SettingsProviderTests.swift */; };
359BB0032E57769E00A8A704 /* SettingsProviderMock.m in Sources */ = {isa = PBXBuildFile; fileRef = 359BB0022E57769E00A8A704 /* SettingsProviderMock.m */; };
359BB0042E57769E00A8A704 /* SettingsProviderMock.m in Sources */ = {isa = PBXBuildFile; fileRef = 359BB0022E57769E00A8A704 /* SettingsProviderMock.m */; };
359BB0062E57A56800A8A704 /* MPUserDefaultsMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 359BB0052E57A56300A8A704 /* MPUserDefaultsMock.swift */; };
359BB0072E57A56800A8A704 /* MPUserDefaultsMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 359BB0052E57A56300A8A704 /* MPUserDefaultsMock.swift */; };
35E3FCC02E53B55900DB5B18 /* MPAttributionResult+MParticlePrivate.m in Sources */ = {isa = PBXBuildFile; fileRef = 35E3FCBF2E53B55900DB5B18 /* MPAttributionResult+MParticlePrivate.m */; };
Expand Down Expand Up @@ -562,13 +564,13 @@
35329FEE2E54CA49009AC4FD /* MParticleOptions+MParticlePrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "MParticleOptions+MParticlePrivate.h"; sourceTree = "<group>"; };
35329FF12E54CA78009AC4FD /* MParticleOptions+MParticlePrivate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "MParticleOptions+MParticlePrivate.m"; sourceTree = "<group>"; };
35329FF42E54CB84009AC4FD /* MParticleOptions+MParticlePrivateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MParticleOptions+MParticlePrivateTests.swift"; sourceTree = "<group>"; };
356D4A582E58B09D00CB69FE /* SettingsProviderMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsProviderMock.swift; sourceTree = "<group>"; };
356D4A5B2E58B25500CB69FE /* MPDataPlanFilterMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MPDataPlanFilterMock.swift; sourceTree = "<group>"; };
359BAFE72E55ED7D00A8A704 /* MParticleTestsSwift.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MParticleTestsSwift.swift; sourceTree = "<group>"; };
359BAFEA2E55EE0C00A8A704 /* MParticle+PrivateMethods.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "MParticle+PrivateMethods.h"; sourceTree = "<group>"; };
359BAFF82E56330200A8A704 /* SettingsProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SettingsProvider.h; sourceTree = "<group>"; };
359BAFFB2E56335300A8A704 /* SettingsProvider.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SettingsProvider.m; sourceTree = "<group>"; };
359BAFFE2E575AF500A8A704 /* SettingsProviderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsProviderTests.swift; sourceTree = "<group>"; };
359BB0012E57769600A8A704 /* SettingsProviderMock.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SettingsProviderMock.h; sourceTree = "<group>"; };
359BB0022E57769E00A8A704 /* SettingsProviderMock.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SettingsProviderMock.m; sourceTree = "<group>"; };
359BB0052E57A56300A8A704 /* MPUserDefaultsMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MPUserDefaultsMock.swift; sourceTree = "<group>"; };
35E3FCBF2E53B55900DB5B18 /* MPAttributionResult+MParticlePrivate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "MPAttributionResult+MParticlePrivate.m"; sourceTree = "<group>"; };
35E3FCC22E53B5C200DB5B18 /* MPAttributionResult+MParticlePrivateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MPAttributionResult+MParticlePrivateTests.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -878,6 +880,16 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
356D4A572E58B01100CB69FE /* Mocks */ = {
isa = PBXGroup;
children = (
356D4A5B2E58B25500CB69FE /* MPDataPlanFilterMock.swift */,
359BB0052E57A56300A8A704 /* MPUserDefaultsMock.swift */,
356D4A582E58B09D00CB69FE /* SettingsProviderMock.swift */,
);
path = Mocks;
sourceTree = "<group>";
};
53A79A6F29CCCD6400E7489F = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1243,11 +1255,9 @@
53A79C6729CE019E00E7489F /* UnitTests */ = {
isa = PBXGroup;
children = (
359BB0052E57A56300A8A704 /* MPUserDefaultsMock.swift */,
356D4A572E58B01100CB69FE /* Mocks */,
359BAFFE2E575AF500A8A704 /* SettingsProviderTests.swift */,
359BAFEA2E55EE0C00A8A704 /* MParticle+PrivateMethods.h */,
359BB0022E57769E00A8A704 /* SettingsProviderMock.m */,
359BB0012E57769600A8A704 /* SettingsProviderMock.h */,
359BAFE72E55ED7D00A8A704 /* MParticleTestsSwift.swift */,
35329FF42E54CB84009AC4FD /* MParticleOptions+MParticlePrivateTests.swift */,
35329FEB2E54C480009AC4FD /* MPNetworkOptions+MParticlePrivateTests.swift */,
Expand Down Expand Up @@ -1710,12 +1720,13 @@
534CD26629CE2CE1008452B3 /* MPUserIdentityChangeTests.m in Sources */,
534CD26729CE2CE1008452B3 /* MPConsentKitFilterTests.m in Sources */,
359BAFFF2E575B0300A8A704 /* SettingsProviderTests.swift in Sources */,
356D4A5D2E58B25900CB69FE /* MPDataPlanFilterMock.swift in Sources */,
534CD26829CE2CE1008452B3 /* MPConnectorTests.m in Sources */,
534CD26929CE2CE1008452B3 /* MPSurrogateAppDelegateTests.m in Sources */,
534CD26A29CE2CE1008452B3 /* MPGDPRConsentTests.m in Sources */,
356D4A5A2E58B09D00CB69FE /* SettingsProviderMock.swift in Sources */,
534CD26B29CE2CE1008452B3 /* MPBackendControllerTests.m in Sources */,
534CD26C29CE2CE1008452B3 /* MPKitConfigurationTests.mm in Sources */,
359BB0042E57769E00A8A704 /* SettingsProviderMock.m in Sources */,
534CD26E29CE2CE1008452B3 /* MPNetworkCommunicationTests.m in Sources */,
534CD26F29CE2CE1008452B3 /* MPAliasRequestTests.m in Sources */,
534CD27029CE2CE1008452B3 /* MPAliasResponseTests.m in Sources */,
Expand Down Expand Up @@ -1896,12 +1907,13 @@
53A79CC229CE019F00E7489F /* MPUserIdentityChangeTests.m in Sources */,
53A79CC129CE019F00E7489F /* MPConsentKitFilterTests.m in Sources */,
359BB0002E575B0300A8A704 /* SettingsProviderTests.swift in Sources */,
356D4A5C2E58B25900CB69FE /* MPDataPlanFilterMock.swift in Sources */,
53A79CD029CE019F00E7489F /* MPConnectorTests.m in Sources */,
53A79CD129CE019F00E7489F /* MPSurrogateAppDelegateTests.m in Sources */,
53A79CE729CE019F00E7489F /* MPGDPRConsentTests.m in Sources */,
356D4A592E58B09D00CB69FE /* SettingsProviderMock.swift in Sources */,
53A79CD229CE019F00E7489F /* MPBackendControllerTests.m in Sources */,
53A79CF329CE019F00E7489F /* MPKitConfigurationTests.mm in Sources */,
359BB0032E57769E00A8A704 /* SettingsProviderMock.m in Sources */,
53A79CDC29CE019F00E7489F /* MPSwiftTests.swift in Sources */,
53A79CBE29CE019F00E7489F /* MPNetworkCommunicationTests.m in Sources */,
53A79CF429CE019F00E7489F /* MPAliasRequestTests.m in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
<Testables>
<TestableReference
skipped = "NO">
Expand Down
2 changes: 1 addition & 1 deletion mParticle-Apple-SDK/Identity/FilteredMParticleUser.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@interface MParticle ()

@property (nonatomic, strong) MPDataPlanFilter *dataPlanFilter;
@property (nonatomic, strong) id<MPDataPlanFilterProtocol> dataPlanFilter;

@end

Expand Down
10 changes: 9 additions & 1 deletion mParticle-Apple-SDK/Kits/MPDataPlanFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@

NS_ASSUME_NONNULL_BEGIN

@interface MPDataPlanFilter: NSObject
@protocol MPDataPlanFilterProtocol <NSObject>

- (BOOL)isBlockedUserIdentityType:(MPIdentity)userIdentityType;
- (BOOL)isBlockedUserAttributeKey:(NSString *)userAttributeKey;
- (MPEvent * _Nullable)transformEventForEvent:(MPEvent *)event;

@end

@interface MPDataPlanFilter: NSObject<MPDataPlanFilterProtocol>

- (NSMutableDictionary<NSString *, NSArray<NSString *> *> *)getPointInfo;

Expand Down
Loading