Commit 50e22424 by Shailesh Aher

[IOS-127]: Tercept SDK unit tests added

parent 3d527ae8
......@@ -255,6 +255,8 @@
F2D8A708269D88D10060F36A /* TerceptSDK.podspec in Resources */ = {isa = PBXBuildFile; fileRef = F2D8A6E1269D88D10060F36A /* TerceptSDK.podspec */; };
F2D8A70D269D93210060F36A /* TerceptSDKManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = F2D8A70C269D93210060F36A /* TerceptSDKManager.swift */; };
F2D8A722269F05200060F36A /* Dependency.swift in Sources */ = {isa = PBXBuildFile; fileRef = F2D8A721269F05200060F36A /* Dependency.swift */; };
F2D8A74E269FFDF10060F36A /* TerceptSDKManagerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F2D8A74D269FFDF10060F36A /* TerceptSDKManagerTests.swift */; };
F2D8A7C9269FFFD50060F36A /* StubTerceptOptimizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = F2D8A7C8269FFFD50060F36A /* StubTerceptOptimizer.swift */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
......@@ -265,6 +267,13 @@
remoteGlobalIDString = CE849DB42638C33600DEFFBD;
remoteInfo = OneWeatherNotificationServiceExtension;
};
F2D8A748269FFDC60060F36A /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = CD1237B7255D5C5900C98139 /* Project object */;
proxyType = 1;
remoteGlobalIDString = CD1237BE255D5C5900C98139;
remoteInfo = 1Weather;
};
/* End PBXContainerItemProxy section */
/* Begin PBXCopyFilesBuildPhase section */
......@@ -553,6 +562,10 @@
F2D8A6E1269D88D10060F36A /* TerceptSDK.podspec */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = TerceptSDK.podspec; sourceTree = "<group>"; };
F2D8A70C269D93210060F36A /* TerceptSDKManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TerceptSDKManager.swift; sourceTree = "<group>"; };
F2D8A721269F05200060F36A /* Dependency.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Dependency.swift; sourceTree = "<group>"; };
F2D8A743269FFDC60060F36A /* 1WeatherTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = 1WeatherTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
F2D8A747269FFDC60060F36A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
F2D8A74D269FFDF10060F36A /* TerceptSDKManagerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TerceptSDKManagerTests.swift; sourceTree = "<group>"; };
F2D8A7C8269FFFD50060F36A /* StubTerceptOptimizer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StubTerceptOptimizer.swift; sourceTree = "<group>"; };
FD761FE0D947B3A79121A941 /* Pods-OneWeatherNotificationServiceExtension.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-OneWeatherNotificationServiceExtension.release.xcconfig"; path = "Target Support Files/Pods-OneWeatherNotificationServiceExtension/Pods-OneWeatherNotificationServiceExtension.release.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */
......@@ -585,6 +598,13 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
F2D8A740269FFDC60060F36A /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
......@@ -625,6 +645,7 @@
children = (
CD1237C1255D5C5900C98139 /* 1Weather */,
CE849DB62638C33600DEFFBD /* OneWeatherNotificationServiceExtension */,
F2D8A744269FFDC60060F36A /* 1WeatherTests */,
CD1237C0255D5C5900C98139 /* Products */,
5A59BA825D452B7FC9288086 /* Pods */,
DBFD169AA2AA6A3CB5B68BB5 /* Frameworks */,
......@@ -637,6 +658,7 @@
children = (
CD1237BF255D5C5900C98139 /* 1Weather.app */,
CE849DB52638C33600DEFFBD /* OneWeatherNotificationServiceExtension.appex */,
F2D8A743269FFDC60060F36A /* 1WeatherTests.xctest */,
);
name = Products;
sourceTree = "<group>";
......@@ -1455,6 +1477,24 @@
path = Dependency;
sourceTree = "<group>";
};
F2D8A744269FFDC60060F36A /* 1WeatherTests */ = {
isa = PBXGroup;
children = (
F2D8A7C7269FFFC20060F36A /* TerceptSDK */,
F2D8A747269FFDC60060F36A /* Info.plist */,
);
path = 1WeatherTests;
sourceTree = "<group>";
};
F2D8A7C7269FFFC20060F36A /* TerceptSDK */ = {
isa = PBXGroup;
children = (
F2D8A7C8269FFFD50060F36A /* StubTerceptOptimizer.swift */,
F2D8A74D269FFDF10060F36A /* TerceptSDKManagerTests.swift */,
);
path = TerceptSDK;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
......@@ -1503,6 +1543,24 @@
productReference = CE849DB52638C33600DEFFBD /* OneWeatherNotificationServiceExtension.appex */;
productType = "com.apple.product-type.app-extension";
};
F2D8A742269FFDC60060F36A /* 1WeatherTests */ = {
isa = PBXNativeTarget;
buildConfigurationList = F2D8A74C269FFDC60060F36A /* Build configuration list for PBXNativeTarget "1WeatherTests" */;
buildPhases = (
F2D8A73F269FFDC60060F36A /* Sources */,
F2D8A740269FFDC60060F36A /* Frameworks */,
F2D8A741269FFDC60060F36A /* Resources */,
);
buildRules = (
);
dependencies = (
F2D8A749269FFDC60060F36A /* PBXTargetDependency */,
);
name = 1WeatherTests;
productName = 1WeatherTests;
productReference = F2D8A743269FFDC60060F36A /* 1WeatherTests.xctest */;
productType = "com.apple.product-type.bundle.unit-test";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
......@@ -1518,6 +1576,11 @@
CE849DB42638C33600DEFFBD = {
CreatedOnToolsVersion = 12.4;
};
F2D8A742269FFDC60060F36A = {
CreatedOnToolsVersion = 12.5.1;
LastSwiftMigration = 1250;
TestTargetID = CD1237BE255D5C5900C98139;
};
};
};
buildConfigurationList = CD1237BA255D5C5900C98139 /* Build configuration list for PBXProject "1Weather" */;
......@@ -1535,6 +1598,7 @@
targets = (
CD1237BE255D5C5900C98139 /* 1Weather */,
CE849DB42638C33600DEFFBD /* OneWeatherNotificationServiceExtension */,
F2D8A742269FFDC60060F36A /* 1WeatherTests */,
);
};
/* End PBXProject section */
......@@ -1606,6 +1670,13 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
F2D8A741269FFDC60060F36A /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */
/* Begin PBXShellScriptBuildPhase section */
......@@ -1950,6 +2021,15 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
F2D8A73F269FFDC60060F36A /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
F2D8A74E269FFDF10060F36A /* TerceptSDKManagerTests.swift in Sources */,
F2D8A7C9269FFFD50060F36A /* StubTerceptOptimizer.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin PBXTargetDependency section */
......@@ -1958,6 +2038,11 @@
target = CE849DB42638C33600DEFFBD /* OneWeatherNotificationServiceExtension */;
targetProxy = CE849DBA2638C33600DEFFBD /* PBXContainerItemProxy */;
};
F2D8A749269FFDC60060F36A /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = CD1237BE255D5C5900C98139 /* 1Weather */;
targetProxy = F2D8A748269FFDC60060F36A /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */
/* Begin PBXVariantGroup section */
......@@ -2210,6 +2295,51 @@
};
name = Release;
};
F2D8A74A269FFDC60060F36A /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
HEADER_SEARCH_PATHS = "${SRCROOT}/Pods/Firebase/CoreOnly/Sources";
INFOPLIST_FILE = 1WeatherTests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 14.5;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = "com.shailesh.aher.-WeatherTests";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/1Weather.app/1Weather";
};
name = Debug;
};
F2D8A74B269FFDC60060F36A /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
HEADER_SEARCH_PATHS = "${SRCROOT}/Pods/Firebase/CoreOnly/Sources";
INFOPLIST_FILE = 1WeatherTests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 14.5;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = "com.shailesh.aher.-WeatherTests";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/1Weather.app/1Weather";
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
......@@ -2240,6 +2370,15 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
F2D8A74C269FFDC60060F36A /* Build configuration list for PBXNativeTarget "1WeatherTests" */ = {
isa = XCConfigurationList;
buildConfigurations = (
F2D8A74A269FFDC60060F36A /* Debug */,
F2D8A74B269FFDC60060F36A /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = CD1237B7255D5C5900C98139 /* Project object */;
......
......@@ -28,6 +28,16 @@
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "F2D8A742269FFDC60060F36A"
BuildableName = "1WeatherTests.xctest"
BlueprintName = "1WeatherTests"
ReferencedContainer = "container:1Weather.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
//
// StubTerceptOptimizer.swift
// 1WeatherTests
//
// Created by Shailesh on 15/07/21.
//
import Foundation
@testable import _Weather
class StubTerceptOptimizer: TerceptOpimizable {
private let customTargettingKeys: [String : String?]
private(set) var initParamsMethodParams: (String, String, [String: Any]?)? = nil
private(set) var fetchMethodParams: [String]?
private(set) var setCustomParametersMethodParams: [String: String]?
private(set) var sentEventDataCalled: Bool = false
private(set) var logEventMethodParams: (String?, String?, [String: Any])?
init(customTargettingKeys: [String : String?]) {
self.customTargettingKeys = customTargettingKeys
}
func initParams(_ IDFA: String, _ IDFV: String, _ params: [String : Any]?) {
self.initParamsMethodParams = (IDFA, IDFV, params)
}
func fetch(_ adunits: [String]?) {
self.fetchMethodParams = adunits
}
func setCustomParameters(_ params: [String : String]) {
self.setCustomParametersMethodParams = params
}
func sendEventsData() {
self.sentEventDataCalled = true
}
func getCustomTargetingKeys(_ adunit: String?) -> [String : String?] {
return customTargettingKeys
}
func logEvent(_ adunit: String?, _ event: String?, _ customParams: [String : Any]) -> Bool {
self.logEventMethodParams = (adunit, event, customParams)
return true
}
}
extension AdLifeCycleState: CaseIterable {
public static var allCases: [AdLifeCycleState] = [.adClicked, .adClosed, .adFailedToLoad, .adImpression, .adLeftApplication, .adLoaded, .adOpened]
}
//
// TerceptSDKManagerTests.swift
// 1WeatherTests
//
// Created by Shailesh on 15/07/21.
//
import XCTest
@testable import _Weather
class TerceptSDKManagerTests: XCTestCase {
private let adUnits = ["Test/Ad/1", "Test/Ad/2"]
func testInitParams() {
let stub = StubTerceptOptimizer(customTargettingKeys: [:])
XCTAssertNil(stub.initParamsMethodParams?.0)
XCTAssertNil(stub.initParamsMethodParams?.1)
XCTAssertNil(stub.initParamsMethodParams?.2)
_ = TerceptSDKManager(optimizable: stub, adUnitIDs: adUnits)
XCTAssertNotNil(stub.initParamsMethodParams?.0)
XCTAssertNotNil(stub.initParamsMethodParams?.1)
XCTAssertNotNil(stub.initParamsMethodParams?.2)
}
func testFetchAdUnitsKeys() {
let stub = StubTerceptOptimizer(customTargettingKeys: [:])
XCTAssertNil(stub.fetchMethodParams)
_ = TerceptSDKManager(optimizable: stub, adUnitIDs: adUnits)
XCTAssertEqual(adUnits, stub.fetchMethodParams)
}
func testFetchAdUnitsKeysCustomTargettingKeys() {
let customTargettingKeys = ["Custom Target Key": "Value"]
let stub = StubTerceptOptimizer(customTargettingKeys: customTargettingKeys)
let manager = TerceptSDKManager(optimizable: stub, adUnitIDs: adUnits)
let tracker = manager.getTracker(with: adUnits.first!)
XCTAssertEqual(customTargettingKeys, tracker.getCustomTrackableKeys())
}
func testSetCustomParameter() {
let customParam = ["Custom Param Key": "Custom Param Value"]
let stub = StubTerceptOptimizer(customTargettingKeys: [:])
XCTAssertNil(stub.setCustomParametersMethodParams)
let manager = TerceptSDKManager(optimizable: stub, adUnitIDs: adUnits)
manager.setCustomParameters(customParam)
XCTAssertEqual(customParam, stub.setCustomParametersMethodParams)
}
func testLogEvent() {
let stub = StubTerceptOptimizer(customTargettingKeys: [:])
XCTAssertNil(stub.logEventMethodParams)
let manager = TerceptSDKManager(optimizable: stub, adUnitIDs: adUnits)
let tracker = manager.getTracker(with: adUnits.first!)
for item in AdLifeCycleState.allCases {
tracker.recordAdState(item)
XCTAssertEqual(stub.logEventMethodParams?.0, adUnits.first!)
XCTAssertEqual(stub.logEventMethodParams?.1, item.rawValue)
XCTAssertTrue(stub.logEventMethodParams?.2.isEmpty == true)
}
}
func testSendEventData() {
let stub = StubTerceptOptimizer(customTargettingKeys: [:])
XCTAssertFalse(stub.sentEventDataCalled)
let manager = TerceptSDKManager(optimizable: stub, adUnitIDs: adUnits)
NotificationCenter.default.post(name: UIApplication.didEnterBackgroundNotification, object: nil)
XCTAssertTrue(stub.sentEventDataCalled)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment