Skip to content

Commit 5e1008c

Browse files
feat: Migrate MPResponseConfigTests (#552)
* feat: Just move test file to swift target * Convert testIgnoresLegacyDirectRoutingConfig * Migrate testDeleteDueToMaxConfigAge * Migrate testShouldDeleteDueToMaxConfigAge * Migrate testShouldDeleteDueToMaxConfigAgeWhenNil * migrate testSaveRestore * Migrate testInvalidConfigurations and testUpdateCustomModuleSettingsOnRestore * Migrate testInstance * Address linter issues * Initialize connector in setup method * Update mParticle-Apple-SDK-Swift/Test/Mocks/MPUserDefaultsConnectorMock.swift Co-authored-by: Brandon Stalnaker <33703490+BrandonStalnaker@users.noreply.github.com> * Update mParticle-Apple-SDK-Swift/Test/Mocks/MPUserDefaultsConnectorMock.swift Co-authored-by: Brandon Stalnaker <33703490+BrandonStalnaker@users.noreply.github.com> * Update mParticle-Apple-SDK-Swift/Test/Utils/MPResponseConfigTests.swift Co-authored-by: Brandon Stalnaker <33703490+BrandonStalnaker@users.noreply.github.com> * Update mParticle-Apple-SDK-Swift/Test/Utils/MPResponseConfigTests.swift Co-authored-by: Brandon Stalnaker <33703490+BrandonStalnaker@users.noreply.github.com> * Update mParticle-Apple-SDK-Swift/Test/Utils/MPResponseConfigTests.swift Co-authored-by: Brandon Stalnaker <33703490+BrandonStalnaker@users.noreply.github.com> * Remove spaces --------- Co-authored-by: Brandon Stalnaker <33703490+BrandonStalnaker@users.noreply.github.com>
1 parent 7f48630 commit 5e1008c

File tree

5 files changed

+255
-213
lines changed

5 files changed

+255
-213
lines changed

UnitTests/ObjCTests/MPResponseConfigTests.m

Lines changed: 0 additions & 207 deletions
This file was deleted.

mParticle-Apple-SDK-Swift/Test/Mocks/MPUserDefaultsConnectorMock.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ class MPUserDefaultsConnectorMock: MPUserDefaultsConnectorProtocol {
88
func configureKits(_ kitConfigurations: [[AnyHashable: Any]]?) {
99
}
1010

11+
var configureCustomModulesCustomModuleSettingsParams: [[AnyHashable: Any]]?
1112
func configureCustomModules(_ customModuleSettings: [[AnyHashable: Any]]?) {
13+
configureCustomModulesCustomModuleSettingsParams = customModuleSettings
1214
}
1315

1416
func configureRampPercentage(_ rampPercentage: NSNumber?) {
@@ -55,15 +57,19 @@ class MPUserDefaultsConnectorMock: MPUserDefaultsConnectorProtocol {
5557
func unregisterForRemoteNotifications() {
5658
}
5759

60+
var canCreateConfigurationReturnValue = false
61+
5862
func canCreateConfiguration() -> Bool {
59-
return false
63+
return canCreateConfigurationReturnValue
6064
}
6165

6266
func mpId() -> NSNumber {
6367
1
6468
}
6569

70+
var configMaxAgeSecondsReturnValue: NSNumber?
71+
6672
func configMaxAgeSeconds() -> NSNumber? {
67-
1
73+
configMaxAgeSecondsReturnValue
6874
}
6975
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
import XCTest
2+
@testable import mParticle_Apple_SDK_Swift
3+
4+
class MPResponseConfigTests: XCTestCase {
5+
var connector: MPUserDefaultsConnectorMock!
6+
7+
override func setUp() {
8+
super.setUp()
9+
connector = MPUserDefaultsConnectorMock()
10+
}
11+
12+
func testIgnoresLegacyDirectRoutingConfig() {
13+
let configuration: [String: Any] = [
14+
RemoteConfig.kMPRemoteConfigKitsKey: NSNull(),
15+
RemoteConfig.kMPRemoteConfigCustomModuleSettingsKey: NSNull(),
16+
RemoteConfig.kMPRemoteConfigRampKey: 100,
17+
RemoteConfig.kMPRemoteConfigTriggerKey: NSNull(),
18+
RemoteConfig.kMPRemoteConfigExceptionHandlingModeKey: RemoteConfig.kMPRemoteConfigExceptionHandlingModeIgnore,
19+
RemoteConfig.kMPRemoteConfigSessionTimeoutKey: 112,
20+
"dur": false
21+
]
22+
let connector = MPUserDefaultsConnectorMock()
23+
let responseConfig = MPResponseConfig(configuration: configuration, connector: connector)
24+
25+
XCTAssertNotNil(responseConfig, "Config should parse successfully even with legacy dur key")
26+
}
27+
28+
func testUpdateCustomModuleSettingsOnRestore() {
29+
let cmsDictionary: [[String: Any]] = [
30+
[
31+
"id": 11,
32+
"pr": [
33+
[
34+
"f": "NSUserDefaults",
35+
"m": 0,
36+
"ps": [
37+
[
38+
"k": "APP_MEASUREMENT_VISITOR_ID",
39+
"d": "%gn%",
40+
"n": "vid",
41+
"t": 1
42+
],
43+
[
44+
"k": "ADOBEMOBILE_STOREDDEFAULTS_AID",
45+
"d": "%oaid%",
46+
"n": "aid",
47+
"t": 1
48+
],
49+
[
50+
"k": "ADB_LIFETIME_VALUE",
51+
"d": "0",
52+
"n": "ltv",
53+
"t": 1
54+
],
55+
[
56+
"k": "OMCK1",
57+
"d": "%dt%",
58+
"n": "id",
59+
"t": 1
60+
],
61+
[
62+
"k": "OMCK6",
63+
"d": "0",
64+
"n": "l",
65+
"t": 2
66+
],
67+
[
68+
"k": "OMCK5",
69+
"d": "%dt%",
70+
"n": "lud",
71+
"t": 1
72+
]
73+
]
74+
]
75+
]
76+
]
77+
]
78+
79+
let configuration: [String: Any] = [
80+
RemoteConfig.kMPRemoteConfigKitsKey: NSNull(),
81+
RemoteConfig.kMPRemoteConfigCustomModuleSettingsKey: cmsDictionary,
82+
RemoteConfig.kMPRemoteConfigRampKey: 100,
83+
RemoteConfig.kMPRemoteConfigTriggerKey: NSNull(),
84+
RemoteConfig.kMPRemoteConfigExceptionHandlingModeKey: RemoteConfig.kMPRemoteConfigExceptionHandlingModeForce,
85+
RemoteConfig.kMPRemoteConfigSessionTimeoutKey: 112
86+
]
87+
88+
let responseConfig = MPResponseConfig(configuration: configuration, connector: connector)
89+
XCTAssertNotNil(responseConfig)
90+
XCTAssertNotNil(connector.configureCustomModulesCustomModuleSettingsParams)
91+
XCTAssertEqual(1, connector.configureCustomModulesCustomModuleSettingsParams?.count)
92+
let customModules = connector.configureCustomModulesCustomModuleSettingsParams
93+
let customModule = customModules?[0] as? NSDictionary
94+
let prArray = customModule?["pr"] as! NSArray
95+
let psArray = (prArray[0] as! NSDictionary)["ps"] as! NSArray
96+
XCTAssertEqual((psArray[0] as! NSDictionary)["n"] as? String, "vid")
97+
XCTAssertEqual((psArray[1] as! NSDictionary)["n"] as? String, "aid")
98+
}
99+
100+
func testInvalidConfigurations() {
101+
let configuration = [String: Any]()
102+
let responseConfig = MPResponseConfig(configuration: configuration, connector: connector)
103+
XCTAssertNil(responseConfig, "Should have been nil.")
104+
}
105+
106+
func testInstance() {
107+
let configuration: [String: Any] = [
108+
RemoteConfig.kMPRemoteConfigKitsKey: NSNull(),
109+
RemoteConfig.kMPRemoteConfigCustomModuleSettingsKey: NSNull(),
110+
RemoteConfig.kMPRemoteConfigRampKey: 100,
111+
RemoteConfig.kMPRemoteConfigTriggerKey: NSNull(),
112+
RemoteConfig.kMPRemoteConfigExceptionHandlingModeKey: RemoteConfig.kMPRemoteConfigExceptionHandlingModeIgnore,
113+
RemoteConfig.kMPRemoteConfigSessionTimeoutKey: 112
114+
]
115+
let responseConfig = MPResponseConfig(configuration: configuration, connector: connector)
116+
117+
XCTAssertNotNil(responseConfig, "Should not have been nil.")
118+
}
119+
}

0 commit comments

Comments
 (0)