From 80112840ce9fab812543f828b645e4ca58fcdeec Mon Sep 17 00:00:00 2001 From: Enricoza Date: Wed, 22 Feb 2023 13:32:01 +0100 Subject: [PATCH] [MT-1204] Remove arm64 architecture exclusion for simulators (#10) * Remove arm64 architecture exclusion for simulators * Remove duplicated tests --- Cartfile.resolved | 4 +- Sources/AppsFlyerConstants.swift | 2 +- TealiumAppsFlyer.podspec | 6 +- TealiumAppsFlyer.xcodeproj/project.pbxproj | 26 +- TealiumAppsFlyerExample/Podfile.lock | 4 +- Tests/AppsFlyerInstanceTests.swift | 538 ++------------------- Tests/HttpTestHelpers.swift | 74 --- 7 files changed, 54 insertions(+), 600 deletions(-) delete mode 100644 Tests/HttpTestHelpers.swift diff --git a/Cartfile.resolved b/Cartfile.resolved index 3c48c23..bd90458 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,2 +1,2 @@ -binary "https://raw.githubusercontent.com/AppsFlyerSDK/AppsFlyerFramework/6.5.0/Carthage/appsflyer-ios.json" "6.4.4" -github "tealium/tealium-swift" "2.5.1" +binary "https://raw.githubusercontent.com/AppsFlyerSDK/AppsFlyerFramework/master/Carthage/appsflyer-ios.json" "6.10.0" +github "tealium/tealium-swift" "2.9.1" diff --git a/Sources/AppsFlyerConstants.swift b/Sources/AppsFlyerConstants.swift index 1e43568..c957385 100644 --- a/Sources/AppsFlyerConstants.swift +++ b/Sources/AppsFlyerConstants.swift @@ -16,7 +16,7 @@ public enum AppsFlyerConstants { static let description = "AppsFlyer Remote Command" static let errorPrefix = "AppsFlyer Error: " static let attributionLog = "AppsFlyer Attribution: " - static let version = "2.1.0" + static let version = "2.1.2" /// Standard AppsFlyer events: https://support.appsflyer.com/hc/en-us/articles/115005544169#Event-Types public enum EventCommandNames: String, CaseIterable { diff --git a/TealiumAppsFlyer.podspec b/TealiumAppsFlyer.podspec index 9744d37..cbc0c21 100644 --- a/TealiumAppsFlyer.podspec +++ b/TealiumAppsFlyer.podspec @@ -3,7 +3,7 @@ Pod::Spec.new do |s| # ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # s.name = "TealiumAppsFlyer" s.module_name = "TealiumAppsFlyer" - s.version = "2.1.1" + s.version = "2.1.2" s.summary = "Tealium Swift and AppsFlyer integration" s.description = <<-DESC Tealium's integration with AppsFlyer for iOS. @@ -22,10 +22,6 @@ Pod::Spec.new do |s| s.swift_version = "5.0" s.platform = :ios, "11.0" - # ――― Excluded Archs ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # - s.user_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' } - s.pod_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' } - # ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # s.source = { :git => "https://github.com/Tealium/tealium-ios-appsflyer-remote-command.git", :tag => "#{s.version}" } diff --git a/TealiumAppsFlyer.xcodeproj/project.pbxproj b/TealiumAppsFlyer.xcodeproj/project.pbxproj index fb5350b..bab433b 100644 --- a/TealiumAppsFlyer.xcodeproj/project.pbxproj +++ b/TealiumAppsFlyer.xcodeproj/project.pbxproj @@ -7,9 +7,9 @@ objects = { /* Begin PBXBuildFile section */ + 1589AC022995554400736C6B /* AppsFlyerLib.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 15914AD6277A12F50051BCB2 /* AppsFlyerLib.xcframework */; }; 15914AD7277A12F50051BCB2 /* TealiumCore.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 15914AD4277A12F50051BCB2 /* TealiumCore.xcframework */; }; 15914AD8277A12F50051BCB2 /* TealiumRemoteCommands.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 15914AD5277A12F50051BCB2 /* TealiumRemoteCommands.xcframework */; }; - 15914AD9277A12F50051BCB2 /* AppsFlyerLib.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 15914AD6277A12F50051BCB2 /* AppsFlyerLib.xcframework */; }; CF0D01FC232AB7CB005BFE15 /* TealiumAppsFlyer.h in Headers */ = {isa = PBXBuildFile; fileRef = CF0D01EE232AB7CB005BFE15 /* TealiumAppsFlyer.h */; settings = {ATTRIBUTES = (Public, ); }; }; CF0D0208232AB81A005BFE15 /* AppsFlyerRemoteCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = CF0D0205232AB81A005BFE15 /* AppsFlyerRemoteCommand.swift */; }; CF0D0209232AB81A005BFE15 /* AppsFlyerConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = CF0D0206232AB81A005BFE15 /* AppsFlyerConstants.swift */; }; @@ -20,7 +20,6 @@ CF3277EE2522B69F00696BB4 /* AppsFlyerRemoteCommand.swift in Headers */ = {isa = PBXBuildFile; fileRef = CF0D0205232AB81A005BFE15 /* AppsFlyerRemoteCommand.swift */; settings = {ATTRIBUTES = (Public, ); }; }; CF3277EF2522B69F00696BB4 /* AppsFlyerInstance.swift in Headers */ = {isa = PBXBuildFile; fileRef = CF3F5C1123E258D10007C9B1 /* AppsFlyerInstance.swift */; settings = {ATTRIBUTES = (Public, ); }; }; CF3F5C1223E258D10007C9B1 /* AppsFlyerInstance.swift in Sources */ = {isa = PBXBuildFile; fileRef = CF3F5C1123E258D10007C9B1 /* AppsFlyerInstance.swift */; }; - CF9B51B8232AF23C003019F9 /* HttpTestHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = CF0D020F232AB847005BFE15 /* HttpTestHelpers.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -33,19 +32,6 @@ }; /* End PBXContainerItemProxy section */ -/* Begin PBXCopyFilesBuildPhase section */ - CFB6B58A26796CBB00D62D87 /* Embed Frameworks */ = { - isa = PBXCopyFilesBuildPhase; - buildActionMask = 2147483647; - dstPath = ""; - dstSubfolderSpec = 10; - files = ( - ); - name = "Embed Frameworks"; - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXCopyFilesBuildPhase section */ - /* Begin PBXFileReference section */ 15914AD4277A12F50051BCB2 /* TealiumCore.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = TealiumCore.xcframework; path = Carthage/Build/TealiumCore.xcframework; sourceTree = ""; }; 15914AD5277A12F50051BCB2 /* TealiumRemoteCommands.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = TealiumRemoteCommands.xcframework; path = Carthage/Build/TealiumRemoteCommands.xcframework; sourceTree = ""; }; @@ -59,7 +45,6 @@ CF0D0206232AB81A005BFE15 /* AppsFlyerConstants.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppsFlyerConstants.swift; sourceTree = ""; }; CF0D020B232AB841005BFE15 /* MockAppsFlyerInstance.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MockAppsFlyerInstance.swift; sourceTree = ""; }; CF0D020C232AB841005BFE15 /* AppsFlyerInstanceTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppsFlyerInstanceTests.swift; sourceTree = ""; }; - CF0D020F232AB847005BFE15 /* HttpTestHelpers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HttpTestHelpers.swift; sourceTree = ""; }; CF3F5C1123E258D10007C9B1 /* AppsFlyerInstance.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppsFlyerInstance.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -69,7 +54,7 @@ buildActionMask = 2147483647; files = ( 15914AD7277A12F50051BCB2 /* TealiumCore.xcframework in Frameworks */, - 15914AD9277A12F50051BCB2 /* AppsFlyerLib.xcframework in Frameworks */, + 1589AC022995554400736C6B /* AppsFlyerLib.xcframework in Frameworks */, 15914AD8277A12F50051BCB2 /* TealiumRemoteCommands.xcframework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -138,7 +123,6 @@ 15914AE0277A28250051BCB2 /* Support */, CF0D020C232AB841005BFE15 /* AppsFlyerInstanceTests.swift */, CF0D020B232AB841005BFE15 /* MockAppsFlyerInstance.swift */, - CF0D020F232AB847005BFE15 /* HttpTestHelpers.swift */, ); path = Tests; sourceTree = ""; @@ -177,7 +161,6 @@ CF0D01E6232AB7CB005BFE15 /* Headers */, CF0D01E7232AB7CB005BFE15 /* Sources */, CF0D01E8232AB7CB005BFE15 /* Frameworks */, - CFB6B58A26796CBB00D62D87 /* Embed Frameworks */, ); buildRules = ( ); @@ -268,7 +251,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - CF9B51B8232AF23C003019F9 /* HttpTestHelpers.swift in Sources */, CF0D0212232AB84B005BFE15 /* MockAppsFlyerInstance.swift in Sources */, CF0D0211232AB848005BFE15 /* AppsFlyerInstanceTests.swift in Sources */, ); @@ -419,8 +401,6 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - EXCLUDED_ARCHS = ""; - "EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)/Carthage/Build/iOS", @@ -454,8 +434,6 @@ DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; ENABLE_TESTABILITY = YES; - EXCLUDED_ARCHS = ""; - "EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)/Carthage/Build/iOS", diff --git a/TealiumAppsFlyerExample/Podfile.lock b/TealiumAppsFlyerExample/Podfile.lock index d299987..a962c49 100644 --- a/TealiumAppsFlyerExample/Podfile.lock +++ b/TealiumAppsFlyerExample/Podfile.lock @@ -9,7 +9,7 @@ PODS: - tealium-swift/Core - tealium-swift/TagManagement (2.9.0): - tealium-swift/Core - - TealiumAppsFlyer (2.1.1): + - TealiumAppsFlyer (2.1.2): - AppsFlyerFramework (~> 6.9) - tealium-swift/Core (~> 2.9) - tealium-swift/RemoteCommands (~> 2.9) @@ -33,7 +33,7 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: AppsFlyerFramework: 75e2e46970e520c88b0456dc6fae98c51b36163a tealium-swift: e824eb16ebf859cb9af9aa4ecd24e8653ff561d4 - TealiumAppsFlyer: 226e88543a00ef1a73e541a19203dfb5cd15aa13 + TealiumAppsFlyer: 091f216de29ef5152a2a8575db82b3ea7e48d7c7 PODFILE CHECKSUM: 2f9c59c6d166b636a640fac15b785aa6bf64f560 diff --git a/Tests/AppsFlyerInstanceTests.swift b/Tests/AppsFlyerInstanceTests.swift index b7369b9..e4a1073 100644 --- a/Tests/AppsFlyerInstanceTests.swift +++ b/Tests/AppsFlyerInstanceTests.swift @@ -26,599 +26,153 @@ class AppsFlyerInstanceTests: XCTestCase { // MARK: Webview Remote Command Tests func testInitWithoutConfig() { - let expect = expectation(description: "AppsFlyerRunner initialize(appId:appDevKey:) method run") let payload: [String: Any] = ["command_name": "initialize", "app_id": "test", "app_dev_key": "test"] - - if let response = HttpTestHelpers.createRemoteCommandResponse(type: .webview, commandId: "appsflyer", payload: payload) { - appsFlyerCommand.completion(response) - expect.fulfill() - XCTAssertEqual(1, self.appsFlyerInstance.initWithoutConfigCount) - } - - wait(for: [expect], timeout: 2.0) + appsFlyerCommand.processRemoteCommand(with: payload) + XCTAssertEqual(1, self.appsFlyerInstance.initWithoutConfigCount) } func testInitWithoutConfigNotRun() { - let expect = expectation(description: "AppsFlyerRunner initialize(appId:appDevKey:) method does not run") let payload: [String: Any] = ["command_name": "initialize"] - - if let response = HttpTestHelpers.createRemoteCommandResponse(type: .webview, commandId: "appsflyer", payload: payload) { - appsFlyerCommand.completion(response) - expect.fulfill() - XCTAssertEqual(0, self.appsFlyerInstance.initWithoutConfigCount) - XCTAssertEqual(0, self.appsFlyerInstance.initWithConfigCount) - } - - wait(for: [expect], timeout: 2.0) + appsFlyerCommand.processRemoteCommand(with: payload) + XCTAssertEqual(0, self.appsFlyerInstance.initWithoutConfigCount) + XCTAssertEqual(0, self.appsFlyerInstance.initWithConfigCount) } func testInitWithConfig() { - let expect = expectation(description: "AppsFlyerRunner initialize(appId:appDevKey:settings:) method run") let payload: [String: Any] = ["command_name": "initialize", "app_id": "test", "app_dev_key": "test", "settings": ["test": "test"]] - - if let response = HttpTestHelpers.createRemoteCommandResponse(type: .webview, commandId: "appsflyer", payload: payload) { - appsFlyerCommand.completion(response) - expect.fulfill() - XCTAssertEqual(1, self.appsFlyerInstance.initWithConfigCount) - } - - wait(for: [expect], timeout: 2.0) + appsFlyerCommand.processRemoteCommand(with: payload) + XCTAssertEqual(1, self.appsFlyerInstance.initWithConfigCount) } func testInitWithConfigNotRun() { - let expect = expectation(description: "AppsFlyerRunner initialize(appId:appDevKey:settings:) method does not run") let payload: [String: Any] = ["command_name": "initialize", "settings": ["test": "test"]] - if let response = HttpTestHelpers.createRemoteCommandResponse(type: .webview, commandId: "appsflyer", payload: payload) { - appsFlyerCommand.completion(response) - expect.fulfill() - XCTAssertEqual(0, self.appsFlyerInstance.initWithConfigCount) - XCTAssertEqual(0, self.appsFlyerInstance.initWithConfigCount) - } - - wait(for: [expect], timeout: 2.0) + appsFlyerCommand.processRemoteCommand(with: payload) + XCTAssertEqual(0, self.appsFlyerInstance.initWithConfigCount) + XCTAssertEqual(0, self.appsFlyerInstance.initWithConfigCount) } func testTrackEvent() { - let expect = expectation(description: "AppsFlyerRunner trackEvent(eventName:values:) method run") let payload: [String: Any] = ["command_name": "viewedcontent,rate,login"] - - if let response = HttpTestHelpers.createRemoteCommandResponse(type: .webview, commandId: "appsflyer", payload: payload) { - appsFlyerCommand.completion(response) - expect.fulfill() - XCTAssertEqual(3, self.appsFlyerInstance.logEventCount) - } - - wait(for: [expect], timeout: 2.0) + appsFlyerCommand.processRemoteCommand(with: payload) + XCTAssertEqual(3, self.appsFlyerInstance.logEventCount) } func testTrackCustomEvent() { - let expect = expectation(description: "AppsFlyerRunner trackEvent(eventName:values:) custom event runs") let payload: [String: Any] = ["command_name": "custom_command_name"] - - if let response = HttpTestHelpers.createRemoteCommandResponse(type: .webview, commandId: "appsflyer", payload: payload) { - appsFlyerCommand.completion(response) - expect.fulfill() - XCTAssertEqual(1, self.appsFlyerInstance.logEventCount) - } - - wait(for: [expect], timeout: 2.0) + appsFlyerCommand.processRemoteCommand(with: payload) + XCTAssertEqual(1, self.appsFlyerInstance.logEventCount) } func testTrackLocationWithLatLongInts() { - let expect = expectation(description: "AppsFlyerRunner trackLocation(longitude:latitude:) method run") let payload: [String: Any] = ["command_name": "tracklocation", "af_lat": 33, "af_long": 122] - - if let response = HttpTestHelpers.createRemoteCommandResponse(type: .webview, commandId: "appsflyer", payload: payload) { - appsFlyerCommand.completion(response) - expect.fulfill() - XCTAssertEqual(1, self.appsFlyerInstance.logLocationCount) - } - - wait(for: [expect], timeout: 2.0) + appsFlyerCommand.processRemoteCommand(with: payload) + XCTAssertEqual(1, self.appsFlyerInstance.logLocationCount) } func testTrackLocationWithLatLongDoubles() { - let expect = expectation(description: "AppsFlyerRunner trackLocation(longitude:latitude:) method run") let payload: [String: Any] = ["command_name": "tracklocation", "af_lat": 33.0, "af_long": -122.0] - - if let response = HttpTestHelpers.createRemoteCommandResponse(type: .webview, commandId: "appsflyer", payload: payload) { - appsFlyerCommand.completion(response) - expect.fulfill() - XCTAssertEqual(1, self.appsFlyerInstance.logLocationCount) - } - - wait(for: [expect], timeout: 2.0) + appsFlyerCommand.processRemoteCommand(with: payload) + XCTAssertEqual(1, self.appsFlyerInstance.logLocationCount) } func testTrackLocationNotRun() { - let expect = expectation(description: "AppsFlyerRunner trackLocation(longitude:latitude:) method has not run") let payload: [String: Any] = ["command_name": "tracklocation"] - - if let response = HttpTestHelpers.createRemoteCommandResponse(type: .webview, commandId: "appsflyer", payload: payload) { - appsFlyerCommand.completion(response) - expect.fulfill() - XCTAssertEqual(0, self.appsFlyerInstance.logLocationCount) - } - - wait(for: [expect], timeout: 2.0) + appsFlyerCommand.processRemoteCommand(with: payload) + XCTAssertEqual(0, self.appsFlyerInstance.logLocationCount) } func testSetHost() { - let expect = expectation(description: "AppsFlyerRunner setHost(_ host:with:) method run") let payload: [String: Any] = ["command_name": "sethost", "host": "test.com", "host_prefix": "test"] - - if let response = HttpTestHelpers.createRemoteCommandResponse(type: .webview, commandId: "appsflyer", payload: payload) { - appsFlyerCommand.completion(response) - expect.fulfill() - XCTAssertEqual(1, self.appsFlyerInstance.setHostCount) - } - - wait(for: [expect], timeout: 2.0) + appsFlyerCommand.processRemoteCommand(with: payload) + XCTAssertEqual(1, self.appsFlyerInstance.setHostCount) } func testSetHostNotRun() { - let expect = expectation(description: "AppsFlyerRunner setHost(_ host:with:) method has not run") let payload: [String: Any] = ["command_name": "sethost", "host_prefix": "test"] - - if let response = HttpTestHelpers.createRemoteCommandResponse(type: .webview, commandId: "appsflyer", payload: payload) { - appsFlyerCommand.completion(response) - expect.fulfill() - XCTAssertEqual(0, self.appsFlyerInstance.setHostCount) - } - - wait(for: [expect], timeout: 2.0) + appsFlyerCommand.processRemoteCommand(with: payload) + XCTAssertEqual(0, self.appsFlyerInstance.setHostCount) } func testSetUserEmails() { - let expect = expectation(description: "AppsFlyerRunner setUserEmails(emails:with:) method run") let payload: [String: Any] = ["command_name": "setuseremails", "customer_emails": ["blah", "blah2"], "email_hash_type": 1] - - if let response = HttpTestHelpers.createRemoteCommandResponse(type: .webview, commandId: "appsflyer", payload: payload) { - appsFlyerCommand.completion(response) - expect.fulfill() - XCTAssertEqual(1, self.appsFlyerInstance.setUserEmailsCount) - } - - wait(for: [expect], timeout: 2.0) + appsFlyerCommand.processRemoteCommand(with: payload) + XCTAssertEqual(1, self.appsFlyerInstance.setUserEmailsCount) } func testSetUserEmailsWNotRun() { - let expect = expectation(description: "AppsFlyerRunner setUserEmails(emails:with:) method has not run") let payload: [String: Any] = ["command_name": "setuseremails", "email_hash_type": 1] - - if let response = HttpTestHelpers.createRemoteCommandResponse(type: .webview, commandId: "appsflyer", payload: payload) { - appsFlyerCommand.completion(response) - expect.fulfill() - XCTAssertEqual(0, self.appsFlyerInstance.setUserEmailsCount) - } - - wait(for: [expect], timeout: 2.0) + appsFlyerCommand.processRemoteCommand(with: payload) + XCTAssertEqual(0, self.appsFlyerInstance.setUserEmailsCount) } func testSetCurrencyCode() { - let expect = expectation(description: "AppsFlyerRunner currencyCode(currency:) method run") let payload: [String: Any] = ["command_name": "setcurrencycode", "af_currency": "USD"] - - if let response = HttpTestHelpers.createRemoteCommandResponse(type: .webview, commandId: "appsflyer", payload: payload) { - appsFlyerCommand.completion(response) - expect.fulfill() - XCTAssertEqual(1, self.appsFlyerInstance.setCurrencyCodeCount) - } - - wait(for: [expect], timeout: 2.0) + appsFlyerCommand.processRemoteCommand(with: payload) + XCTAssertEqual(1, self.appsFlyerInstance.setCurrencyCodeCount) } func testSetCurrencyCodeNotRun() { - let expect = expectation(description: "AppsFlyerRunner currencyCode(currency:) method has not run") let payload: [String: Any] = ["command_name": "setcurrencycode"] - - if let response = HttpTestHelpers.createRemoteCommandResponse(type: .webview, commandId: "appsflyer", payload: payload) { - appsFlyerCommand.completion(response) - expect.fulfill() - XCTAssertEqual(0, self.appsFlyerInstance.setCurrencyCodeCount) - } - - wait(for: [expect], timeout: 2.0) + appsFlyerCommand.processRemoteCommand(with: payload) + XCTAssertEqual(0, self.appsFlyerInstance.setCurrencyCodeCount) } func testSetCustomerId() { - let expect = expectation(description: "AppsFlyerRunner customerId(id:) method run") let payload: [String: Any] = ["command_name": "setcustomerid", "af_customer_user_id": "ABC123"] - - if let response = HttpTestHelpers.createRemoteCommandResponse(type: .webview, commandId: "appsflyer", payload: payload) { - appsFlyerCommand.completion(response) - expect.fulfill() - XCTAssertEqual(1, self.appsFlyerInstance.setCustomerIdCount) - } - - wait(for: [expect], timeout: 2.0) + appsFlyerCommand.processRemoteCommand(with: payload) + XCTAssertEqual(1, self.appsFlyerInstance.setCustomerIdCount) } func testSetCustomerIdNotRun() { - let expect = expectation(description: "AppsFlyerRunner customerId(id:) method has not run") let payload: [String: Any] = ["command_name": "setcustomerid"] - - if let response = HttpTestHelpers.createRemoteCommandResponse(type: .webview, commandId: "appsflyer", payload: payload) { - appsFlyerCommand.completion(response) - expect.fulfill() - XCTAssertEqual(0, self.appsFlyerInstance.setCustomerIdCount) - } - - wait(for: [expect], timeout: 2.0) + appsFlyerCommand.processRemoteCommand(with: payload) + XCTAssertEqual(0, self.appsFlyerInstance.setCustomerIdCount) } func testDisableTrackingCommandName() { - let expect = expectation(description: "AppsFlyerRunner disableTracking(disable:) method run") let payload: [String: Any] = ["command_name": "disabletracking"] - - if let response = HttpTestHelpers.createRemoteCommandResponse(type: .webview, commandId: "appsflyer", payload: payload) { - appsFlyerCommand.completion(response) - expect.fulfill() - XCTAssertEqual(1, self.appsFlyerInstance.disableTrackingCount) - } - - wait(for: [expect], timeout: 2.0) + appsFlyerCommand.processRemoteCommand(with: payload) + XCTAssertEqual(1, self.appsFlyerInstance.disableTrackingCount) } func testDisableTrackingNotRun() { - let expect = expectation(description: "AppsFlyerRunner disableTracking(disable:) method has not run") let payload: [String: Any] = ["command_name": "disable"] - - if let response = HttpTestHelpers.createRemoteCommandResponse(type: .webview, commandId: "appsflyer", payload: payload) { - appsFlyerCommand.completion(response) - expect.fulfill() - XCTAssertEqual(0, self.appsFlyerInstance.disableTrackingCount) - } - - wait(for: [expect], timeout: 2.0) + appsFlyerCommand.processRemoteCommand(with: payload) + XCTAssertEqual(0, self.appsFlyerInstance.disableTrackingCount) } func testDisableTrackingVariable() { - let expect = expectation(description: "AppsFlyerRunner disableTracking(disable:) method run") let payload: [String: Any] = ["command_name": "disabletracking"] - - if let response = HttpTestHelpers.createRemoteCommandResponse(type: .webview, commandId: "appsflyer", payload: payload) { - appsFlyerCommand.completion(response) - expect.fulfill() - XCTAssertEqual(1, self.appsFlyerInstance.disableTrackingCount) - } - - wait(for: [expect], timeout: 2.0) + appsFlyerCommand.processRemoteCommand(with: payload) + XCTAssertEqual(1, self.appsFlyerInstance.disableTrackingCount) } func testResolveDeepLinkURLs() { - let expect = expectation(description: "AppsFlyerRunner resolveDeepLinkURLs(urls:) method run") let payload: [String: Any] = ["command_name": "resolvedeeplinkurls", "af_deep_link": ["app://test.com", "app://test?home=true"]] - - if let response = HttpTestHelpers.createRemoteCommandResponse(type: .webview, commandId: "appsflyer", payload: payload) { - appsFlyerCommand.completion(response) - expect.fulfill() - XCTAssertEqual(1, self.appsFlyerInstance.resolveDeepLinkURLsCount) - } - - wait(for: [expect], timeout: 2.0) + appsFlyerCommand.processRemoteCommand(with: payload) + XCTAssertEqual(1, self.appsFlyerInstance.resolveDeepLinkURLsCount) } func testResolveDeepLinkURLsNotRun() { - let expect = expectation(description: "AppsFlyerRunner resolveDeepLinkURLs(urls:) method has not run") let payload: [String: Any] = ["command_name": "resolvedeeplinkurls"] - - if let response = HttpTestHelpers.createRemoteCommandResponse(type: .webview, commandId: "appsflyer", payload: payload) { - appsFlyerCommand.completion(response) - expect.fulfill() - XCTAssertEqual(0, self.appsFlyerInstance.resolveDeepLinkURLsCount) - } - - wait(for: [expect], timeout: 2.0) - } - - // MARK: JSON Remote Command Tests - - func testInitWithoutConfigJSON() { - let expect = expectation(description: "AppsFlyerRunner initialize(appId:appDevKey:) method run") - let payload: [String: Any] = ["command_name": "initialize", - "app_id": "test", - "app_dev_key": "test"] - - if let response = HttpTestHelpers.createRemoteCommandResponse(type: .JSON, commandId: "appsflyer", payload: payload) { - appsFlyerCommand.completion(response) - expect.fulfill() - XCTAssertEqual(1, self.appsFlyerInstance.initWithoutConfigCount) - } - - wait(for: [expect], timeout: 2.0) - } - - func testInitWithoutConfigNotRunJSON() { - let expect = expectation(description: "AppsFlyerRunner initialize(appId:appDevKey:) method does not run") - let payload: [String: Any] = ["command_name": "initialize"] - - if let response = HttpTestHelpers.createRemoteCommandResponse(type: .JSON, commandId: "appsflyer", payload: payload) { - appsFlyerCommand.completion(response) - expect.fulfill() - XCTAssertEqual(0, self.appsFlyerInstance.initWithoutConfigCount) - XCTAssertEqual(0, self.appsFlyerInstance.initWithConfigCount) - } - - wait(for: [expect], timeout: 2.0) - } - - func testInitWithConfigJSON() { - let expect = expectation(description: "AppsFlyerRunner initialize(appId:appDevKey:settings:) method run") - let payload: [String: Any] = ["command_name": "initialize", - "app_id": "test", - "app_dev_key": "test", - "settings": ["test": "test"]] - - if let response = HttpTestHelpers.createRemoteCommandResponse(type: .JSON, commandId: "appsflyer", payload: payload) { - appsFlyerCommand.completion(response) - expect.fulfill() - XCTAssertEqual(1, self.appsFlyerInstance.initWithConfigCount) - } - - wait(for: [expect], timeout: 2.0) - } - - func testInitWithConfigNotRunJSON() { - let expect = expectation(description: "AppsFlyerRunner initialize(appId:appDevKey:settings:) method does not run") - let payload: [String: Any] = ["command_name": "initialize", - "settings": ["test": "test"]] - - if let response = HttpTestHelpers.createRemoteCommandResponse(type: .JSON, commandId: "appsflyer", payload: payload) { - appsFlyerCommand.completion(response) - expect.fulfill() - XCTAssertEqual(0, self.appsFlyerInstance.initWithConfigCount) - XCTAssertEqual(0, self.appsFlyerInstance.initWithConfigCount) - } - - wait(for: [expect], timeout: 2.0) - } - - func testTrackEventJSON() { - let expect = expectation(description: "AppsFlyerRunner trackEvent(eventName:values:) method run") - let payload: [String: Any] = ["command_name": "viewedcontent,rate,login"] - - if let response = HttpTestHelpers.createRemoteCommandResponse(type: .JSON, commandId: "appsflyer", payload: payload) { - appsFlyerCommand.completion(response) - expect.fulfill() - XCTAssertEqual(3, self.appsFlyerInstance.logEventCount) - } - - wait(for: [expect], timeout: 2.0) - } - - func testTrackLocationWithLatLongIntsJSON() { - let expect = expectation(description: "AppsFlyerRunner trackLocation(longitude:latitude:) method run") - let payload: [String: Any] = ["command_name": "tracklocation", - "af_lat": 33, - "af_long": 122] - - if let response = HttpTestHelpers.createRemoteCommandResponse(type: .JSON, commandId: "appsflyer", payload: payload) { - appsFlyerCommand.completion(response) - expect.fulfill() - XCTAssertEqual(1, self.appsFlyerInstance.logLocationCount) - } - - wait(for: [expect], timeout: 2.0) - } - - func testTrackLocationWithLatLongDoublesJSON() { - let expect = expectation(description: "AppsFlyerRunner trackLocation(longitude:latitude:) method run") - let payload: [String: Any] = ["command_name": "tracklocation", - "af_lat": 33.0, - "af_long": -122.0] - - if let response = HttpTestHelpers.createRemoteCommandResponse(type: .JSON, commandId: "appsflyer", payload: payload) { - appsFlyerCommand.completion(response) - expect.fulfill() - XCTAssertEqual(1, self.appsFlyerInstance.logLocationCount) - } - - wait(for: [expect], timeout: 2.0) - } - - func testTrackLocationNotRunJSON() { - let expect = expectation(description: "AppsFlyerRunner trackLocation(longitude:latitude:) method has not run") - let payload: [String: Any] = ["command_name": "tracklocation"] - - if let response = HttpTestHelpers.createRemoteCommandResponse(type: .JSON, commandId: "appsflyer", payload: payload) { - appsFlyerCommand.completion(response) - expect.fulfill() - XCTAssertEqual(0, self.appsFlyerInstance.logLocationCount) - } - - wait(for: [expect], timeout: 2.0) - } - - func testSetHostJSON() { - let expect = expectation(description: "AppsFlyerRunner setHost(_ host:with:) method run") - let payload: [String: Any] = ["command_name": "sethost", - "host": "test.com", - "host_prefix": "test"] - - if let response = HttpTestHelpers.createRemoteCommandResponse(type: .JSON, commandId: "appsflyer", payload: payload) { - appsFlyerCommand.completion(response) - expect.fulfill() - XCTAssertEqual(1, self.appsFlyerInstance.setHostCount) - } - - wait(for: [expect], timeout: 2.0) - } - - func testSetHostNotRunJSON() { - let expect = expectation(description: "AppsFlyerRunner setHost(_ host:with:) method has not run") - let payload: [String: Any] = ["command_name": "sethost", - "host_prefix": "test"] - - if let response = HttpTestHelpers.createRemoteCommandResponse(type: .JSON, commandId: "appsflyer", payload: payload) { - appsFlyerCommand.completion(response) - expect.fulfill() - XCTAssertEqual(0, self.appsFlyerInstance.setHostCount) - } - - wait(for: [expect], timeout: 2.0) - } - - func testSetUserEmailsJSON() { - let expect = expectation(description: "AppsFlyerRunner setUserEmails(emails:with:) method run") - let payload: [String: Any] = ["command_name": "setuseremails", - "customer_emails": ["blah", "blah2"], - "email_hash_type": 1] - - if let response = HttpTestHelpers.createRemoteCommandResponse(type: .JSON, commandId: "appsflyer", payload: payload) { - appsFlyerCommand.completion(response) - expect.fulfill() - XCTAssertEqual(1, self.appsFlyerInstance.setUserEmailsCount) - } - - wait(for: [expect], timeout: 2.0) - } - - func testSetUserEmailsWNotRunJSON() { - let expect = expectation(description: "AppsFlyerRunner setUserEmails(emails:with:) method has not run") - let payload: [String: Any] = ["command_name": "setuseremails", - "email_hash_type": 1] - - if let response = HttpTestHelpers.createRemoteCommandResponse(type: .JSON, commandId: "appsflyer", payload: payload) { - appsFlyerCommand.completion(response) - expect.fulfill() - XCTAssertEqual(0, self.appsFlyerInstance.setUserEmailsCount) - } - - wait(for: [expect], timeout: 2.0) - } - - func testSetCurrencyCodeJSON() { - let expect = expectation(description: "AppsFlyerRunner currencyCode(currency:) method run") - let payload: [String: Any] = ["command_name": "setcurrencycode", "af_currency": "USD"] - - if let response = HttpTestHelpers.createRemoteCommandResponse(type: .JSON, commandId: "appsflyer", payload: payload) { - appsFlyerCommand.completion(response) - expect.fulfill() - XCTAssertEqual(1, self.appsFlyerInstance.setCurrencyCodeCount) - } - - wait(for: [expect], timeout: 2.0) - } - - func testSetCurrencyCodeNotRunJSON() { - let expect = expectation(description: "AppsFlyerRunner currencyCode(currency:) method has not run") - let payload: [String: Any] = ["command_name": "setcurrencycode"] - - if let response = HttpTestHelpers.createRemoteCommandResponse(type: .JSON, commandId: "appsflyer", payload: payload) { - appsFlyerCommand.completion(response) - expect.fulfill() - XCTAssertEqual(0, self.appsFlyerInstance.setCurrencyCodeCount) - } - - wait(for: [expect], timeout: 2.0) - } - - func testSetCustomerIdJSON() { - let expect = expectation(description: "AppsFlyerRunner customerId(id:) method run") - let payload: [String: Any] = ["command_name": "setcustomerid", "af_customer_user_id": "ABC123"] - - if let response = HttpTestHelpers.createRemoteCommandResponse(type: .JSON, commandId: "appsflyer", payload: payload) { - appsFlyerCommand.completion(response) - expect.fulfill() - XCTAssertEqual(1, self.appsFlyerInstance.setCustomerIdCount) - } - - wait(for: [expect], timeout: 2.0) - } - - func testSetCustomerIdNotRunJSON() { - let expect = expectation(description: "AppsFlyerRunner customerId(id:) method has not run") - let payload: [String: Any] = ["command_name": "setcustomerid"] - - if let response = HttpTestHelpers.createRemoteCommandResponse(type: .JSON, commandId: "appsflyer", payload: payload) { - appsFlyerCommand.completion(response) - expect.fulfill() - XCTAssertEqual(0, self.appsFlyerInstance.setCustomerIdCount) - } - - wait(for: [expect], timeout: 2.0) - } - - func testDisableTrackingCommandNameJSON() { - let expect = expectation(description: "AppsFlyerRunner disableTracking(disable:) method run") - let payload: [String: Any] = ["command_name": "disabletracking"] - - if let response = HttpTestHelpers.createRemoteCommandResponse(type: .JSON, commandId: "appsflyer", payload: payload) { - appsFlyerCommand.completion(response) - expect.fulfill() - XCTAssertEqual(1, self.appsFlyerInstance.disableTrackingCount) - } - - wait(for: [expect], timeout: 2.0) - } - - func testDisableTrackingNotRunJSON() { - let expect = expectation(description: "AppsFlyerRunner disableTracking(disable:) method has not run") - let payload: [String: Any] = ["command_name": "disable"] - - if let response = HttpTestHelpers.createRemoteCommandResponse(type: .JSON, commandId: "appsflyer", payload: payload) { - appsFlyerCommand.completion(response) - expect.fulfill() - XCTAssertEqual(0, self.appsFlyerInstance.disableTrackingCount) - } - - wait(for: [expect], timeout: 2.0) - } - - func testDisableTrackingVariableJSON() { - let expect = expectation(description: "AppsFlyerRunner disableTracking(disable:) method run") - let payload: [String: Any] = ["command_name": "disabletracking"] - - if let response = HttpTestHelpers.createRemoteCommandResponse(type: .JSON, commandId: "appsflyer", payload: payload) { - appsFlyerCommand.completion(response) - expect.fulfill() - XCTAssertEqual(1, self.appsFlyerInstance.disableTrackingCount) - } - - wait(for: [expect], timeout: 2.0) - } - - func testResolveDeepLinkURLsJSON() { - let expect = expectation(description: "AppsFlyerRunner resolveDeepLinkURLs(urls:) method run") - let payload: [String: Any] = ["command_name": "resolvedeeplinkurls", "af_deep_link": ["app://test.com", "app://test?home=true"]] - - if let response = HttpTestHelpers.createRemoteCommandResponse(type: .JSON, commandId: "appsflyer", payload: payload) { - appsFlyerCommand.completion(response) - expect.fulfill() - XCTAssertEqual(1, self.appsFlyerInstance.resolveDeepLinkURLsCount) - } - - wait(for: [expect], timeout: 2.0) - } - - func testResolveDeepLinkURLsNotRunJSON() { - let expect = expectation(description: "AppsFlyerRunner resolveDeepLinkURLs(urls:) method has not run") - let payload: [String: Any] = ["command_name": "resolvedeeplinkurls"] - - if let response = HttpTestHelpers.createRemoteCommandResponse(type: .JSON, commandId: "appsflyer", payload: payload) { - appsFlyerCommand.completion(response) - expect.fulfill() - XCTAssertEqual(0, self.appsFlyerInstance.resolveDeepLinkURLsCount) - } - - wait(for: [expect], timeout: 2.0) + appsFlyerCommand.processRemoteCommand(with: payload) + XCTAssertEqual(0, self.appsFlyerInstance.resolveDeepLinkURLsCount) } } diff --git a/Tests/HttpTestHelpers.swift b/Tests/HttpTestHelpers.swift deleted file mode 100644 index f219d07..0000000 --- a/Tests/HttpTestHelpers.swift +++ /dev/null @@ -1,74 +0,0 @@ -// -// HttpTestHelpers.swift -// TealiumAppsFlyerTests -// -// Created by Jonathan Wong on 8/8/19. -// Copyright © 2019 Tealium. All rights reserved. -// - -import Foundation -#if COCOAPODS -#else - import TealiumRemoteCommands -#endif - -struct RemoteCommandResponsePayload: Codable { - var config: [String: String] - var payload: [String: String] -} - -class HttpTestHelpers { - class func httpRequest(commandId: String, payload: [String: String]) -> URLRequest? { - let url = "tealium://\(commandId)?request=" - - let response = RemoteCommandResponsePayload(config: ["response_id": "00000"], payload: payload) - - let encoder = JSONEncoder() - let json = try? encoder.encode(response) - - if let json = json, let encodedString = String(data: json, encoding: .utf8)?.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed), let url = URL(string: "\(url)\(encodedString)") { - return URLRequest(url: url) - } - - return nil - } - - class func httpRequest(commandId: String, config: [String: Any], payload: [String: Any]) -> URLRequest? { - let url = "tealium://\(commandId)?request=" - let remoteCommandrc = ["config": config, "payload": payload] as [String: Any] - let json = try! JSONSerialization.data(withJSONObject: remoteCommandrc, options: .prettyPrinted) - if let encodedString = String(data: json, encoding: .utf8)?.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed), let url = URL(string: "\(url)\(encodedString)") { - print(encodedString) - return URLRequest(url: url) - } - - return nil - } - - class func httpRequestDescription(commandId: String, config: [String: Any], payload: [String: Any]) -> String? { - let url = "tealium://\(commandId)?request=" - let remoteCommandrc = ["config": config, "payload": payload] as [String: Any] - let json = try! JSONSerialization.data(withJSONObject: remoteCommandrc, options: .prettyPrinted) - if let encodedString = String(data: json, encoding: .utf8)?.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed), let url = URL(string: "\(url)\(encodedString)") { - print(encodedString) - return URLRequest(url: url).description - } - - return nil - } - - class func createRemoteCommandResponse(type: SimpleCommandType, commandId: String, payload: [String: Any]) -> RemoteCommandResponseProtocol? { - switch type { - case .webview: - let responseDescription = HttpTestHelpers.httpRequestDescription(commandId: commandId, config: [:], payload: payload) - if let description = responseDescription { - return RemoteCommandResponse(urlString: description) - } - case .JSON: - return JSONRemoteCommandResponse(with: payload) - } - print("Could not create Remote Command Response description from stubs provided") - return nil - } - -}