From eb2e57ac1b12f04c52960d20abf7578d7c434c5b Mon Sep 17 00:00:00 2001 From: Maddie Beyl Date: Wed, 27 Apr 2022 10:15:28 -0400 Subject: [PATCH 1/7] Move deprecated methods to Deprecations.swift, make some things internal --- Sources/Misc/Deprecations.swift | 58 ++++++++++++++++++++++++ Sources/Purchasing/Purchases.swift | 72 ++---------------------------- 2 files changed, 62 insertions(+), 68 deletions(-) diff --git a/Sources/Misc/Deprecations.swift b/Sources/Misc/Deprecations.swift index 6014cc6614..74979e3535 100644 --- a/Sources/Misc/Deprecations.swift +++ b/Sources/Misc/Deprecations.swift @@ -56,6 +56,64 @@ public extension Purchases { return await eligiblePromotionalOffers(forProduct: product) } + /** + * Enable debug logging. Useful for debugging issues with the lovely team @RevenueCat. + */ + @available(*, deprecated, message: "use Purchases.logLevel instead") + @objc static var debugLogsEnabled: Bool { + get { logLevel == .debug } + set { logLevel = newValue ? .debug : .info } + } + + /** + * Deprecated + */ + @available(*, deprecated, message: "Configure behavior through the RevenueCat dashboard instead") + @objc var allowSharingAppStoreAccount: Bool { + get { purchasesOrchestrator.allowSharingAppStoreAccount } + set { purchasesOrchestrator.allowSharingAppStoreAccount = newValue } + } + + /** + * Send your attribution data to RevenueCat so you can track the revenue generated by your different campaigns. + * + * - Parameter data: Dictionary provided by the network. + * - Parameter network: Enum for the network the data is coming from, see ``AttributionNetwork`` for supported + * networks. + * + * #### Related articles + * - [Attribution](https://docs.revenuecat.com/docs/attribution) + */ + @available(*, deprecated, message: "Use the set functions instead") + @objc static func addAttributionData(_ data: [String: Any], fromNetwork network: AttributionNetwork) { + addAttributionData(data, from: network, forNetworkUserId: nil) + } + + /** + * Send your attribution data to RevenueCat so you can track the revenue generated by your different campaigns. + * + * - Parameter data: Dictionary provided by the network. + * - Parameter network: Enum for the network the data is coming from, see ``AttributionNetwork`` for supported + * networks. + * - Parameter networkUserId: User Id that should be sent to the network. Default is the current App User Id. + * + * #### Related articles + * - [Attribution](https://docs.revenuecat.com/docs/attribution) + */ + @available(*, deprecated, message: "Use the set functions instead") + @objc(addAttributionData:fromNetwork:forNetworkUserId:) + static func addAttributionData(_ data: [String: Any], + from network: AttributionNetwork, + forNetworkUserId networkUserId: String?) { + if Self.isConfigured { + shared.post(attributionData: data, fromNetwork: network, forNetworkUserId: networkUserId) + } else { + AttributionPoster.store(postponedAttributionData: data, + fromNetwork: network, + forNetworkUserId: networkUserId) + } + } + } public extension StoreProduct { diff --git a/Sources/Purchasing/Purchases.swift b/Sources/Purchasing/Purchases.swift index d921d078b6..2530eabde0 100644 --- a/Sources/Purchasing/Purchases.swift +++ b/Sources/Purchasing/Purchases.swift @@ -226,7 +226,7 @@ public typealias StartPurchaseBlock = (@escaping PurchaseCompletedBlock) -> Void private let productsManager: ProductsManager private let customerInfoManager: CustomerInfoManager private let trialOrIntroPriceEligibilityChecker: TrialOrIntroPriceEligibilityChecker - private let purchasesOrchestrator: PurchasesOrchestrator + internal let purchasesOrchestrator: PurchasesOrchestrator private let receiptFetcher: ReceiptFetcher private let requestFetcher: StoreKitRequestFetcher private let storeKitWrapper: StoreKitWrapper @@ -739,9 +739,9 @@ extension Purchases { // MARK: Attribution. extension Purchases { - private func post(attributionData data: [String: Any], - fromNetwork network: AttributionNetwork, - forNetworkUserId networkUserId: String?) { + internal func post(attributionData data: [String: Any], + fromNetwork network: AttributionNetwork, + forNetworkUserId networkUserId: String?) { attributionPoster.post(attributionData: data, fromNetwork: network, networkUserId: networkUserId) } @@ -1878,70 +1878,6 @@ extension Purchases: PurchasesOrchestratorDelegate { } -// MARK: Deprecated - -public extension Purchases { - - /** - * Enable debug logging. Useful for debugging issues with the lovely team @RevenueCat. - */ - @available(*, deprecated, message: "use Purchases.logLevel instead") - @objc static var debugLogsEnabled: Bool { - get { logLevel == .debug } - set { logLevel = newValue ? .debug : .info } - } - - /** - * Deprecated - */ - @available(*, deprecated, message: "Configure behavior through the RevenueCat dashboard instead") - @objc var allowSharingAppStoreAccount: Bool { - get { purchasesOrchestrator.allowSharingAppStoreAccount } - set { purchasesOrchestrator.allowSharingAppStoreAccount = newValue } - } - - /** - * Send your attribution data to RevenueCat so you can track the revenue generated by your different campaigns. - * - * - Parameter data: Dictionary provided by the network. - * - Parameter network: Enum for the network the data is coming from, see ``AttributionNetwork`` for supported - * networks. - * - * #### Related articles - * - [Attribution](https://docs.revenuecat.com/docs/attribution) - */ - @available(*, deprecated, message: "Use the set functions instead") - @objc static func addAttributionData(_ data: [String: Any], fromNetwork network: AttributionNetwork) { - addAttributionData(data, from: network, forNetworkUserId: nil) - } - - /** - * Send your attribution data to RevenueCat so you can track the revenue generated by your different campaigns. - * - * - Parameter data: Dictionary provided by the network. - * - Parameter network: Enum for the network the data is coming from, see ``AttributionNetwork`` for supported - * networks. - * - Parameter networkUserId: User Id that should be sent to the network. Default is the current App User Id. - * - * #### Related articles - * - [Attribution](https://docs.revenuecat.com/docs/attribution) - */ - @available(*, deprecated, message: "Use the set functions instead") - @objc(addAttributionData:fromNetwork:forNetworkUserId:) - static func addAttributionData(_ data: [String: Any], - from network: AttributionNetwork, - forNetworkUserId networkUserId: String?) { - if Self.isConfigured { - shared.post(attributionData: data, fromNetwork: network, forNetworkUserId: networkUserId) - } else { - AttributionPoster.store(postponedAttributionData: data, - fromNetwork: network, - forNetworkUserId: networkUserId) - } - } - -} - // MARK: Internal internal extension Purchases { From e8a685870986dd26e5f37579998bcc73c5563080 Mon Sep 17 00:00:00 2001 From: Maddie Beyl Date: Wed, 27 Apr 2022 13:59:52 -0400 Subject: [PATCH 2/7] Revert "Move deprecated methods to Deprecations.swift, make some things internal" This reverts commit eb2e57ac1b12f04c52960d20abf7578d7c434c5b. --- Sources/Misc/Deprecations.swift | 58 ------------------------ Sources/Purchasing/Purchases.swift | 72 ++++++++++++++++++++++++++++-- 2 files changed, 68 insertions(+), 62 deletions(-) diff --git a/Sources/Misc/Deprecations.swift b/Sources/Misc/Deprecations.swift index 74979e3535..6014cc6614 100644 --- a/Sources/Misc/Deprecations.swift +++ b/Sources/Misc/Deprecations.swift @@ -56,64 +56,6 @@ public extension Purchases { return await eligiblePromotionalOffers(forProduct: product) } - /** - * Enable debug logging. Useful for debugging issues with the lovely team @RevenueCat. - */ - @available(*, deprecated, message: "use Purchases.logLevel instead") - @objc static var debugLogsEnabled: Bool { - get { logLevel == .debug } - set { logLevel = newValue ? .debug : .info } - } - - /** - * Deprecated - */ - @available(*, deprecated, message: "Configure behavior through the RevenueCat dashboard instead") - @objc var allowSharingAppStoreAccount: Bool { - get { purchasesOrchestrator.allowSharingAppStoreAccount } - set { purchasesOrchestrator.allowSharingAppStoreAccount = newValue } - } - - /** - * Send your attribution data to RevenueCat so you can track the revenue generated by your different campaigns. - * - * - Parameter data: Dictionary provided by the network. - * - Parameter network: Enum for the network the data is coming from, see ``AttributionNetwork`` for supported - * networks. - * - * #### Related articles - * - [Attribution](https://docs.revenuecat.com/docs/attribution) - */ - @available(*, deprecated, message: "Use the set functions instead") - @objc static func addAttributionData(_ data: [String: Any], fromNetwork network: AttributionNetwork) { - addAttributionData(data, from: network, forNetworkUserId: nil) - } - - /** - * Send your attribution data to RevenueCat so you can track the revenue generated by your different campaigns. - * - * - Parameter data: Dictionary provided by the network. - * - Parameter network: Enum for the network the data is coming from, see ``AttributionNetwork`` for supported - * networks. - * - Parameter networkUserId: User Id that should be sent to the network. Default is the current App User Id. - * - * #### Related articles - * - [Attribution](https://docs.revenuecat.com/docs/attribution) - */ - @available(*, deprecated, message: "Use the set functions instead") - @objc(addAttributionData:fromNetwork:forNetworkUserId:) - static func addAttributionData(_ data: [String: Any], - from network: AttributionNetwork, - forNetworkUserId networkUserId: String?) { - if Self.isConfigured { - shared.post(attributionData: data, fromNetwork: network, forNetworkUserId: networkUserId) - } else { - AttributionPoster.store(postponedAttributionData: data, - fromNetwork: network, - forNetworkUserId: networkUserId) - } - } - } public extension StoreProduct { diff --git a/Sources/Purchasing/Purchases.swift b/Sources/Purchasing/Purchases.swift index 2530eabde0..d921d078b6 100644 --- a/Sources/Purchasing/Purchases.swift +++ b/Sources/Purchasing/Purchases.swift @@ -226,7 +226,7 @@ public typealias StartPurchaseBlock = (@escaping PurchaseCompletedBlock) -> Void private let productsManager: ProductsManager private let customerInfoManager: CustomerInfoManager private let trialOrIntroPriceEligibilityChecker: TrialOrIntroPriceEligibilityChecker - internal let purchasesOrchestrator: PurchasesOrchestrator + private let purchasesOrchestrator: PurchasesOrchestrator private let receiptFetcher: ReceiptFetcher private let requestFetcher: StoreKitRequestFetcher private let storeKitWrapper: StoreKitWrapper @@ -739,9 +739,9 @@ extension Purchases { // MARK: Attribution. extension Purchases { - internal func post(attributionData data: [String: Any], - fromNetwork network: AttributionNetwork, - forNetworkUserId networkUserId: String?) { + private func post(attributionData data: [String: Any], + fromNetwork network: AttributionNetwork, + forNetworkUserId networkUserId: String?) { attributionPoster.post(attributionData: data, fromNetwork: network, networkUserId: networkUserId) } @@ -1878,6 +1878,70 @@ extension Purchases: PurchasesOrchestratorDelegate { } +// MARK: Deprecated + +public extension Purchases { + + /** + * Enable debug logging. Useful for debugging issues with the lovely team @RevenueCat. + */ + @available(*, deprecated, message: "use Purchases.logLevel instead") + @objc static var debugLogsEnabled: Bool { + get { logLevel == .debug } + set { logLevel = newValue ? .debug : .info } + } + + /** + * Deprecated + */ + @available(*, deprecated, message: "Configure behavior through the RevenueCat dashboard instead") + @objc var allowSharingAppStoreAccount: Bool { + get { purchasesOrchestrator.allowSharingAppStoreAccount } + set { purchasesOrchestrator.allowSharingAppStoreAccount = newValue } + } + + /** + * Send your attribution data to RevenueCat so you can track the revenue generated by your different campaigns. + * + * - Parameter data: Dictionary provided by the network. + * - Parameter network: Enum for the network the data is coming from, see ``AttributionNetwork`` for supported + * networks. + * + * #### Related articles + * - [Attribution](https://docs.revenuecat.com/docs/attribution) + */ + @available(*, deprecated, message: "Use the set functions instead") + @objc static func addAttributionData(_ data: [String: Any], fromNetwork network: AttributionNetwork) { + addAttributionData(data, from: network, forNetworkUserId: nil) + } + + /** + * Send your attribution data to RevenueCat so you can track the revenue generated by your different campaigns. + * + * - Parameter data: Dictionary provided by the network. + * - Parameter network: Enum for the network the data is coming from, see ``AttributionNetwork`` for supported + * networks. + * - Parameter networkUserId: User Id that should be sent to the network. Default is the current App User Id. + * + * #### Related articles + * - [Attribution](https://docs.revenuecat.com/docs/attribution) + */ + @available(*, deprecated, message: "Use the set functions instead") + @objc(addAttributionData:fromNetwork:forNetworkUserId:) + static func addAttributionData(_ data: [String: Any], + from network: AttributionNetwork, + forNetworkUserId networkUserId: String?) { + if Self.isConfigured { + shared.post(attributionData: data, fromNetwork: network, forNetworkUserId: networkUserId) + } else { + AttributionPoster.store(postponedAttributionData: data, + fromNetwork: network, + forNetworkUserId: networkUserId) + } + } + +} + // MARK: Internal internal extension Purchases { From 20c60bfdd5adaa7ab7be210e0daa9751101a3b98 Mon Sep 17 00:00:00 2001 From: Maddie Beyl Date: Wed, 27 Apr 2022 14:04:03 -0400 Subject: [PATCH 3/7] Add missing @objc to deprecated functions, add docs to allowSharingAppStoreAccount --- Sources/Misc/Deprecations.swift | 10 +++++----- Sources/Purchasing/Purchases.swift | 5 ++++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Sources/Misc/Deprecations.swift b/Sources/Misc/Deprecations.swift index 6014cc6614..95222aca02 100644 --- a/Sources/Misc/Deprecations.swift +++ b/Sources/Misc/Deprecations.swift @@ -23,7 +23,7 @@ public extension Purchases { @available(watchOS, deprecated: 1, renamed: "checkTrialOrIntroDiscountEligibility(productIdentifiers:)") @available(macOS, deprecated: 1, renamed: "checkTrialOrIntroDiscountEligibility(productIdentifiers:)") @available(macCatalyst, deprecated: 1, renamed: "checkTrialOrIntroDiscountEligibility(productIdentifiers:)") - func checkTrialOrIntroDiscountEligibility(_ productIdentifiers: [String], + @objc func checkTrialOrIntroDiscountEligibility(_ productIdentifiers: [String], completion: @escaping ([String: IntroEligibility]) -> Void) { self.checkTrialOrIntroDiscountEligibility(productIdentifiers: productIdentifiers, completion: completion) } @@ -33,7 +33,7 @@ public extension Purchases { @available(watchOS, introduced: 6.2, deprecated: 1, renamed: "checkTrialOrIntroDiscountEligibility(productIdentifiers:)") @available(macOS, introduced: 10.15, deprecated: 1, renamed: "checkTrialOrIntroDiscountEligibility(productIdentifiers:)") @available(macCatalyst, introduced: 13.0, deprecated: 1, renamed: "checkTrialOrIntroDiscountEligibility(productIdentifiers:)") - func checkTrialOrIntroDiscountEligibility(_ productIdentifiers: [String]) async -> [String: IntroEligibility] { + @objc func checkTrialOrIntroDiscountEligibility(_ productIdentifiers: [String]) async -> [String: IntroEligibility] { return await self.checkTrialOrIntroDiscountEligibility(productIdentifiers: productIdentifiers) } @@ -42,7 +42,7 @@ public extension Purchases { @available(watchOS, introduced: 6.2, deprecated, renamed: "promotionalOffer(forProductDiscount:product:)") @available(macOS, introduced: 10.15, deprecated, renamed: "promotionalOffer(forProductDiscount:product:)") @available(macCatalyst, introduced: 13.0, deprecated, renamed: "promotionalOffer(forProductDiscount:product:)") - func getPromotionalOffer(forProductDiscount discount: StoreProductDiscount, + @objc func getPromotionalOffer(forProductDiscount discount: StoreProductDiscount, product: StoreProduct) async throws -> PromotionalOffer { return try await self.promotionalOffer(forProductDiscount: discount, product: product) } @@ -52,7 +52,7 @@ public extension Purchases { @available(watchOS, introduced: 6.2, deprecated, renamed: "eligiblePromotionalOffers(forProduct:)") @available(macOS, introduced: 10.15, deprecated, renamed: "eligiblePromotionalOffers(forProduct:)") @available(macCatalyst, introduced: 13.0, deprecated, renamed: "eligiblePromotionalOffers(forProduct:)") - func getEligiblePromotionalOffers(forProduct product: StoreProduct) async -> [PromotionalOffer] { + @objc func getEligiblePromotionalOffers(forProduct product: StoreProduct) async -> [PromotionalOffer] { return await eligiblePromotionalOffers(forProduct: product) } @@ -64,7 +64,7 @@ public extension StoreProduct { @available(watchOS, introduced: 6.2, deprecated, renamed: "eligiblePromotionalOffers()") @available(macOS, introduced: 10.15, deprecated, renamed: "eligiblePromotionalOffers()") @available(macCatalyst, introduced: 13.0, deprecated, renamed: "eligiblePromotionalOffers()") - func getEligiblePromotionalOffers() async -> [PromotionalOffer] { + @objc func getEligiblePromotionalOffers() async -> [PromotionalOffer] { return await self.eligiblePromotionalOffers() } } diff --git a/Sources/Purchasing/Purchases.swift b/Sources/Purchasing/Purchases.swift index d921d078b6..cb9d7db917 100644 --- a/Sources/Purchasing/Purchases.swift +++ b/Sources/Purchasing/Purchases.swift @@ -1892,7 +1892,10 @@ public extension Purchases { } /** - * Deprecated + * Deprecated: Configure behavior through the RevenueCat dashboard instead. + * Determines whether or not users may reuse a subscription from an App or Play Store account that already has that subscription active. + * ### Related articles: + * - https://docs.revenuecat.com/docs/user-ids */ @available(*, deprecated, message: "Configure behavior through the RevenueCat dashboard instead") @objc var allowSharingAppStoreAccount: Bool { From cc22a0a2b5e282b4365cff20dc68c768f8230669 Mon Sep 17 00:00:00 2001 From: Maddie Beyl Date: Wed, 27 Apr 2022 14:06:33 -0400 Subject: [PATCH 4/7] fix lint --- Sources/Misc/Deprecations.swift | 4 ++-- Sources/Purchasing/Purchases.swift | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Sources/Misc/Deprecations.swift b/Sources/Misc/Deprecations.swift index 95222aca02..3e569ba6c4 100644 --- a/Sources/Misc/Deprecations.swift +++ b/Sources/Misc/Deprecations.swift @@ -24,7 +24,7 @@ public extension Purchases { @available(macOS, deprecated: 1, renamed: "checkTrialOrIntroDiscountEligibility(productIdentifiers:)") @available(macCatalyst, deprecated: 1, renamed: "checkTrialOrIntroDiscountEligibility(productIdentifiers:)") @objc func checkTrialOrIntroDiscountEligibility(_ productIdentifiers: [String], - completion: @escaping ([String: IntroEligibility]) -> Void) { + completion: @escaping ([String: IntroEligibility]) -> Void) { self.checkTrialOrIntroDiscountEligibility(productIdentifiers: productIdentifiers, completion: completion) } @@ -43,7 +43,7 @@ public extension Purchases { @available(macOS, introduced: 10.15, deprecated, renamed: "promotionalOffer(forProductDiscount:product:)") @available(macCatalyst, introduced: 13.0, deprecated, renamed: "promotionalOffer(forProductDiscount:product:)") @objc func getPromotionalOffer(forProductDiscount discount: StoreProductDiscount, - product: StoreProduct) async throws -> PromotionalOffer { + product: StoreProduct) async throws -> PromotionalOffer { return try await self.promotionalOffer(forProductDiscount: discount, product: product) } diff --git a/Sources/Purchasing/Purchases.swift b/Sources/Purchasing/Purchases.swift index cb9d7db917..4cff93ef7d 100644 --- a/Sources/Purchasing/Purchases.swift +++ b/Sources/Purchasing/Purchases.swift @@ -1893,7 +1893,8 @@ public extension Purchases { /** * Deprecated: Configure behavior through the RevenueCat dashboard instead. - * Determines whether or not users may reuse a subscription from an App or Play Store account that already has that subscription active. + * Determines whether or not users may reuse a subscription from an App or Play Store + * account that already has that subscription active. * ### Related articles: * - https://docs.revenuecat.com/docs/user-ids */ From f05ae668cbd6fd53b413f01524920e953e3d34ca Mon Sep 17 00:00:00 2001 From: Maddie Beyl Date: Wed, 27 Apr 2022 14:10:41 -0400 Subject: [PATCH 5/7] undo adding @objc to checktrial eligibility because of naming conflicts --- Sources/Misc/Deprecations.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Misc/Deprecations.swift b/Sources/Misc/Deprecations.swift index 3e569ba6c4..87b7763e07 100644 --- a/Sources/Misc/Deprecations.swift +++ b/Sources/Misc/Deprecations.swift @@ -23,8 +23,8 @@ public extension Purchases { @available(watchOS, deprecated: 1, renamed: "checkTrialOrIntroDiscountEligibility(productIdentifiers:)") @available(macOS, deprecated: 1, renamed: "checkTrialOrIntroDiscountEligibility(productIdentifiers:)") @available(macCatalyst, deprecated: 1, renamed: "checkTrialOrIntroDiscountEligibility(productIdentifiers:)") - @objc func checkTrialOrIntroDiscountEligibility(_ productIdentifiers: [String], - completion: @escaping ([String: IntroEligibility]) -> Void) { + func checkTrialOrIntroDiscountEligibility(_ productIdentifiers: [String], + completion: @escaping ([String: IntroEligibility]) -> Void) { self.checkTrialOrIntroDiscountEligibility(productIdentifiers: productIdentifiers, completion: completion) } From 68a680d1f7642fb7de6384428efa50fc968f1271 Mon Sep 17 00:00:00 2001 From: Maddie Beyl Date: Wed, 27 Apr 2022 14:11:30 -0400 Subject: [PATCH 6/7] fix more unit tests --- .../UnitTests/Purchasing/PurchasesTests.swift | 36 ------------------- 1 file changed, 36 deletions(-) diff --git a/Tests/UnitTests/Purchasing/PurchasesTests.swift b/Tests/UnitTests/Purchasing/PurchasesTests.swift index 61e409a031..9c598515e0 100644 --- a/Tests/UnitTests/Purchasing/PurchasesTests.swift +++ b/Tests/UnitTests/Purchasing/PurchasesTests.swift @@ -2182,42 +2182,6 @@ class PurchasesTests: XCTestCase { expect(invokedMethodParams.appUserID) == identityManager.currentAppUserID } - func testAttributionDataDontSendNetworkAppUserIdIfNotProvided() throws { - let data = ["yo": "dog", "what": 45, "is": ["up"]] as [String: Any] - - Purchases.deprecated.addAttributionData(data, fromNetwork: AttributionNetwork.appleSearchAds) - - setupPurchases() - - let invokedMethodParams = try XCTUnwrap(self.backend.invokedPostAttributionDataParameters) - for key in data.keys { - expect(invokedMethodParams.data?.keys.contains(key)) == true - } - - expect(invokedMethodParams.data?.keys.contains("rc_idfa")) == true - expect(invokedMethodParams.data?.keys.contains("rc_idfv")) == true - expect(invokedMethodParams.data?.keys.contains("rc_attribution_network_id")) == false - expect(invokedMethodParams.network) == AttributionNetwork.appleSearchAds - expect(invokedMethodParams.appUserID) == identityManager.currentAppUserID - } - - func testAdClientAttributionDataIsAutomaticallyCollected() throws { - setupPurchases(automaticCollection: true) - - let invokedMethodParams = try XCTUnwrap(self.backend.invokedPostAttributionDataParameters) - - expect(invokedMethodParams).toNot(beNil()) - expect(invokedMethodParams.network) == AttributionNetwork.appleSearchAds - - let obtainedVersionData = try XCTUnwrap(invokedMethodParams.data?["Version3.1"] as? NSDictionary) - expect(obtainedVersionData["iad-campaign-id"]).toNot(beNil()) - } - - func testAdClientAttributionDataIsNotAutomaticallyCollectedIfDisabled() { - setupPurchases(automaticCollection: false) - expect(self.backend.invokedPostAttributionDataParameters).to(beNil()) - } - func testAttributionDataPostponesMultiple() { let data = ["yo": "dog", "what": 45, "is": ["up"]] as [String: Any] From 8fda90378cb5c5f54fb8aef2df1b5b73ade4122f Mon Sep 17 00:00:00 2001 From: Maddie Beyl Date: Wed, 27 Apr 2022 14:17:45 -0400 Subject: [PATCH 7/7] Revert "fix more unit tests" This reverts commit 68a680d1f7642fb7de6384428efa50fc968f1271. --- .../UnitTests/Purchasing/PurchasesTests.swift | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/Tests/UnitTests/Purchasing/PurchasesTests.swift b/Tests/UnitTests/Purchasing/PurchasesTests.swift index 9c598515e0..61e409a031 100644 --- a/Tests/UnitTests/Purchasing/PurchasesTests.swift +++ b/Tests/UnitTests/Purchasing/PurchasesTests.swift @@ -2182,6 +2182,42 @@ class PurchasesTests: XCTestCase { expect(invokedMethodParams.appUserID) == identityManager.currentAppUserID } + func testAttributionDataDontSendNetworkAppUserIdIfNotProvided() throws { + let data = ["yo": "dog", "what": 45, "is": ["up"]] as [String: Any] + + Purchases.deprecated.addAttributionData(data, fromNetwork: AttributionNetwork.appleSearchAds) + + setupPurchases() + + let invokedMethodParams = try XCTUnwrap(self.backend.invokedPostAttributionDataParameters) + for key in data.keys { + expect(invokedMethodParams.data?.keys.contains(key)) == true + } + + expect(invokedMethodParams.data?.keys.contains("rc_idfa")) == true + expect(invokedMethodParams.data?.keys.contains("rc_idfv")) == true + expect(invokedMethodParams.data?.keys.contains("rc_attribution_network_id")) == false + expect(invokedMethodParams.network) == AttributionNetwork.appleSearchAds + expect(invokedMethodParams.appUserID) == identityManager.currentAppUserID + } + + func testAdClientAttributionDataIsAutomaticallyCollected() throws { + setupPurchases(automaticCollection: true) + + let invokedMethodParams = try XCTUnwrap(self.backend.invokedPostAttributionDataParameters) + + expect(invokedMethodParams).toNot(beNil()) + expect(invokedMethodParams.network) == AttributionNetwork.appleSearchAds + + let obtainedVersionData = try XCTUnwrap(invokedMethodParams.data?["Version3.1"] as? NSDictionary) + expect(obtainedVersionData["iad-campaign-id"]).toNot(beNil()) + } + + func testAdClientAttributionDataIsNotAutomaticallyCollectedIfDisabled() { + setupPurchases(automaticCollection: false) + expect(self.backend.invokedPostAttributionDataParameters).to(beNil()) + } + func testAttributionDataPostponesMultiple() { let data = ["yo": "dog", "what": 45, "is": ["up"]] as [String: Any]