Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enableAdServicesAttributionTokenCollection: added integration test #2551

Merged
merged 2 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions Sources/Attribution/AttributionFetcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ class AttributionFetcher {
#if canImport(AdServices)
do {
#if targetEnvironment(simulator)
#if DEBUG
if let mockToken = ProcessInfo.mockAdServicesToken {
Logger.warn(Strings.attribution.adservices_mocking_token(mockToken))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this so it becomes obvious if we mess it up and mock it when we shouldn't.

return mockToken
}
#endif

// See https://github.com/RevenueCat/purchases-ios/issues/2121
Logger.appleWarning(Strings.attribution.adservices_token_unavailable_in_simulator)
return nil
Expand Down
9 changes: 7 additions & 2 deletions Sources/FoundationExtensions/ProcessInfo+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@

import Foundation

#if DEBUG
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's now impossible to read these on release builds.


enum EnvironmentKey: String {

case XCTestConfigurationFile = "XCTestConfigurationFilePath"
case RCRunningTests = "RCRunningTests"
case RCRunningIntegrationTests = "RCRunningIntegrationTests"
case RCMockAdServicesToken = "RCMockAdServicesToken"

}

Expand All @@ -29,8 +32,6 @@ extension ProcessInfo {

}

#if DEBUG

extension ProcessInfo {

static var isRunningUnitTests: Bool {
Expand All @@ -47,6 +48,10 @@ extension ProcessInfo {
return self[.RCRunningIntegrationTests] == "1"
}

static var mockAdServicesToken: String? {
return self[.RCMockAdServicesToken]?.notEmptyOrWhitespaces
}

}

#endif
4 changes: 4 additions & 0 deletions Sources/Logging/Strings/AttributionStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ enum AttributionStrings {
case attribute_set_locally(attribute: String)
case missing_advertiser_identifiers
case adservices_not_supported
case adservices_mocking_token(String)
case adservices_token_fetch_failed(error: Error)
case adservices_token_post_failed(error: BackendError)
case adservices_token_post_succeeded
Expand Down Expand Up @@ -125,6 +126,9 @@ extension AttributionStrings: CustomStringConvertible {
return "Tried to fetch AdServices attribution token on device without " +
"AdServices support."

case let .adservices_mocking_token(token):
return "AdServices: mocking token: \(token) for tests"

case .adservices_token_fetch_failed(let error):
return "Fetching AdServices attribution token failed with error: \(error.localizedDescription)"

Expand Down
14 changes: 14 additions & 0 deletions Tests/BackendIntegrationTests/OtherIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,18 @@ class OtherIntegrationTests: BaseBackendIntegrationTests {
expect(result.entitlementsByProduct["com.revenuecat.intro_test.monthly.1_week_intro"]).to(beEmpty())
}

@available(iOS 14.3, macOS 11.1, macCatalyst 14.3, *)
func testEnableAdServicesAttributionTokenCollection() async throws {
let logger = TestLogHandler()

Purchases.shared.attribution.enableAdServicesAttributionTokenCollection()

try await logger.verifyMessageIsEventuallyLogged(
Strings.attribution.adservices_token_post_succeeded.description,
level: .debug,
timeout: .seconds(3),
pollInterval: .milliseconds(200)
)
}

}
4 changes: 4 additions & 0 deletions Tests/TestPlans/BackendIntegrationTests.xctestplan
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
"key" : "RCRunningTests",
"value" : "1"
},
{
"key" : "RCMockAdServicesToken",
"value" : "G9i5hC8lQJeGOfmS+MFycll"
},
{
"key" : "RCRunningIntegrationTests",
"value" : "1"
Expand Down
4 changes: 4 additions & 0 deletions Tests/TestPlans/CI-BackendIntegration.xctestplan
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
"defaultOptions" : {
"codeCoverage" : false,
"environmentVariableEntries" : [
{
"key" : "RCMockAdServicesToken",
"value" : "G9i5hC8lQJeGOfmS+MFycll"
},
{
"key" : "RCRunningTests",
"value" : "1"
Expand Down