Skip to content

Commit

Permalink
Clean up API Testers (#4141)
Browse files Browse the repository at this point in the history
# API Testers cleanup

- Moves all API Testers into main RevenueCat workspace
- ensure that they all use the local build, not a hardcoded commit
- kill all the separate projects, create a single project with a
framework per test (objc api tests, swift api tests, etc, etc)
- creates a single scheme that builds all of those targets in one pass
- update relevant CI (to do)

Here's what this actually looks like: a single scheme in Xcode, which
you can test using command + U (or just build, since it effectively
works too)

<img width="515" alt="Screenshot 2024-07-31 at 6 09 33 PM"
src="https://github.com/user-attachments/assets/53882e38-f34b-4878-a11e-5d9c304e57ec">

<img width="278" alt="Screenshot 2024-07-31 at 6 09 44 PM"
src="https://github.com/user-attachments/assets/3a7a444c-36da-4c82-ab57-4aeab77adb5d">

*Note:*
Okay, I'd directly recommend _not_ reviewing the diff, since it's kind
of insane, and instead checking out the branch to see if things make
sense.
  • Loading branch information
aboedo authored and nyeu committed Oct 1, 2024
1 parent f409b31 commit a72bf3c
Show file tree
Hide file tree
Showing 148 changed files with 2,235 additions and 2,808 deletions.
18 changes: 4 additions & 14 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -469,19 +469,14 @@ jobs:
command: swift build -c release --target RevenueCatUI
no_output_timeout: 30m

spm-custom-entitlement-computation-build:
api-tests:
<<: *base-job
steps:
- checkout
- run:
name: SPM Custom Entitlement Computation Build
command: swift build --target RevenueCat_CustomEntitlementComputation
no_output_timeout: 30m
- install-dependencies
- update-spm-installation-commit
- run:
name: Custom Entitlement Computation API Tests
command: bundle exec fastlane build_custom_entitlement_computation_api_tester
name: API Tests
command: bundle exec fastlane run_api_tests

spm-receipt-parser:
<<: *base-job
Expand Down Expand Up @@ -563,11 +558,6 @@ jobs:
- store_artifacts:
path: fastlane/test_output
destination: scan-test-output
- run:
condition:
- not: << pipeline.parameters.generate_revenuecatui_snapshots >>
name: RevenueCatUI API Tests
command: bundle exec fastlane build_revenuecatui_api_tester

run-revenuecat-ui-ios-17:
<<: *base-job
Expand Down Expand Up @@ -1415,7 +1405,6 @@ workflows:
- run-test-macos
- run-test-tvos
- run-test-watchos
- spm-custom-entitlement-computation-build
- spm-receipt-parser
- spm-release-build
- spm-release-build-xcode-14
Expand All @@ -1431,3 +1420,4 @@ workflows:
- installation-tests-xcode-direct-integration
- installation-tests-receipt-parser
- deploy-purchase-tester-dry-run
- api-tests
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ Tests/purchases-ios-snapshots

Examples/**/Package.resolved

Tests/APITesters/RevenueCatUIAPITester/RevenueCatUISwiftAPITester.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
Tests/APITesters/CustomEntitlementComputationSwiftAPITester/CustomEntitlementComputationSwiftAPITester.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
Tests/InstallationTests/SPMInstallation/SPMInstallation.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
Tests/InstallationTests/ReceiptParserInstallation/ReceiptParserInstallation.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
Tests/InstallationTests/XcodeDirectInstallation/XcodeDirectInstallation.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
Expand Down
1 change: 1 addition & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ excluded:
- Examples
- Tests/InstallationTests
- Tests/TestingApps
- Tests/APITesters
- vendor
- scan_derived_data
- .git
Expand Down
212 changes: 131 additions & 81 deletions RevenueCat.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

1,864 changes: 1,864 additions & 0 deletions Tests/APITesters/AllAPITests/AllAPITests.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
version = "1.3">
LastUpgradeVersion = "1540"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
buildImplicitDependencies = "YES"
buildArchitectures = "Automatic">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
Expand All @@ -14,10 +15,10 @@
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "2DD778CF270E233F0079CBD4"
BuildableName = "SwiftAPITester.app"
BlueprintName = "SwiftAPITester"
ReferencedContainer = "container:SwiftAPITester.xcodeproj">
BlueprintIdentifier = "2D4C60D72C5AD1BC00A29FD2"
BuildableName = "AllAPITests.framework"
BlueprintName = "AllAPITests"
ReferencedContainer = "container:AllAPITests.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
Expand All @@ -26,8 +27,20 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
<Testables>
<TestableReference
skipped = "NO"
parallelizable = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "2D4C60DF2C5AD1BC00A29FD2"
BuildableName = "AllAPITestsTests.xctest"
BlueprintName = "AllAPITestsTests"
ReferencedContainer = "container:AllAPITests.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
Expand All @@ -50,10 +63,10 @@
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "2DD778CF270E233F0079CBD4"
BuildableName = "SwiftAPITester.app"
BlueprintName = "SwiftAPITester"
ReferencedContainer = "container:SwiftAPITester.xcodeproj">
BlueprintIdentifier = "2D4C60D72C5AD1BC00A29FD2"
BuildableName = "AllAPITests.framework"
BlueprintName = "AllAPITests"
ReferencedContainer = "container:AllAPITests.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
Expand Down
17 changes: 17 additions & 0 deletions Tests/APITesters/AllAPITests/AllAPITests/AllAPITests.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// AllAPITests.h
// AllAPITests
//
// Created by Andrés Boedo on 7/31/24.
//

#import <Foundation/Foundation.h>

//! Project version number for AllAPITests.
FOUNDATION_EXPORT double AllAPITestsVersionNumber;

//! Project version string for AllAPITests.
FOUNDATION_EXPORT const unsigned char AllAPITestsVersionString[];

// Note: this file is empty because we only want the ability to run tests, but API tests really run at
// the compilation step. I.e.: if the test compiles and can run, then it already passed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// AllAPITestsTests.swift
// AllAPITestsTests
//
// Created by Andrés Boedo on 7/31/24.
//

@testable import AllAPITests
import XCTest

class AllAPITestsTests: XCTestCase {

func testExample() throws {
// Note: this test is empty because we only want the ability to run tests, but API tests really run at
// the compilation step. I.e.: if the test compiles and can run, then it already passed.
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@ import RevenueCat_CustomEntitlementComputation
private var attribution: Attribution!

func checkAttributionAPI() {
attribution.enableAdServicesAttributionTokenCollection()
#if os(iOS) || os(macOS)
if #available(iOS 14.3, macOS 11.1, macCatalyst 14.3, *) {
attribution.enableAdServicesAttributionTokenCollection()
}
#endif
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// CustomEntitlementComputationSwiftAPITester.h
// CustomEntitlementComputationSwiftAPITester
//
// Created by Andrés Boedo on 7/31/24.
//

#import <Foundation/Foundation.h>

//! Project version number for CustomEntitlementComputationSwiftAPITester.
FOUNDATION_EXPORT double CustomEntitlementComputationSwiftAPITesterVersionNumber;

//! Project version string for CustomEntitlementComputationSwiftAPITester.
FOUNDATION_EXPORT const unsigned char CustomEntitlementComputationSwiftAPITesterVersionString[];

// In this header, you should import all the public headers of your framework using statements like #import <CustomEntitlementComputationSwiftAPITester/PublicHeader.h>


Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ var offer: PromotionalOffer!
func checkPromotionalOfferAPI() {
let discount: StoreProductDiscount = offer.discount
let sk1Discount = offer.discount.sk1Discount
let sk2Discount = offer.discount.sk2Discount
if #available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) {
let sk2Discount = offer.discount.sk2Discount
print(sk2Discount!)
}

let signedData = offer.signedData

Expand All @@ -23,5 +26,5 @@ func checkPromotionalOfferAPI() {
let _: String = signedData.signature
let _: Int = signedData.timestamp

print(discount, sk1Discount!, sk2Discount!)
print(discount, sk1Discount!)
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,11 @@ private func checkPurchasesPurchasingAPI(purchases: Purchases) {
purchases.restorePurchases()
purchases.restorePurchases { (_: CustomerInfo?, _: PublicError?) in }

if #available(iOS 14.0, *) {
#if os(iOS)
purchases.presentCodeRedemptionSheet()
purchases.presentCodeRedemptionSheet()
#endif
}

// PurchasesDelegate
let customerInfo: CustomerInfo? = nil
Expand All @@ -141,10 +143,12 @@ private func checkPurchasesSupportAPI(purchases: Purchases) {
#if os(iOS)
purchases.showManageSubscriptions { _ in }
#endif
#if os(iOS) || targetEnvironment(macCatalyst)
_ = purchases.showPriceConsentIfNeeded
_ = purchases.delegate?.shouldShowPriceConsent
#endif
if #available(iOS 13.4, *) {
#if os(iOS) || targetEnvironment(macCatalyst)
_ = purchases.showPriceConsentIfNeeded
_ = purchases.delegate?.shouldShowPriceConsent
#endif
}
}

private func checkAsyncMethods(purchases: Purchases) async {
Expand All @@ -162,21 +166,25 @@ private func checkAsyncMethods(purchases: Purchases) async {

let _: CustomerInfo = try await purchases.restorePurchases()

#if os(iOS)
try await purchases.showManageSubscriptions()
let _: RefundRequestStatus = try await purchases.beginRefundRequest(forProduct: "")
let _: RefundRequestStatus = try await purchases.beginRefundRequest(forEntitlement: "")
let _: RefundRequestStatus = try await purchases.beginRefundRequestForActiveEntitlement()
#endif
if #available(iOS 15.0, *) {
#if os(iOS)
try await purchases.showManageSubscriptions()
let _: RefundRequestStatus = try await purchases.beginRefundRequest(forProduct: "")
let _: RefundRequestStatus = try await purchases.beginRefundRequest(forEntitlement: "")
let _: RefundRequestStatus = try await purchases.beginRefundRequestForActiveEntitlement()
#endif
}
} catch {}
}

func checkNonAsyncMethods(_ purchases: Purchases) {
#if os(iOS)
purchases.beginRefundRequest(forProduct: "") { (_: Result<RefundRequestStatus, PublicError>) in }
purchases.beginRefundRequest(forEntitlement: "") { (_: Result<RefundRequestStatus, PublicError>) in }
purchases.beginRefundRequestForActiveEntitlement { (_: Result<RefundRequestStatus, PublicError>) in }
#endif
if #available(iOS 15.0, *) {
#if os(iOS)
purchases.beginRefundRequest(forProduct: "") { (_: Result<RefundRequestStatus, PublicError>) in }
purchases.beginRefundRequest(forEntitlement: "") { (_: Result<RefundRequestStatus, PublicError>) in }
purchases.beginRefundRequestForActiveEntitlement { (_: Result<RefundRequestStatus, PublicError>) in }
#endif
}
}

private func checkConfigure() -> Purchases! {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ func checkStoreProductAPI() {
let decimalPrice: NSDecimalNumber = product.priceDecimalNumber
let localizedPriceString: String = product.localizedPriceString
let productIdentifier: String = product.productIdentifier
let isFamilyShareable: Bool = product.isFamilyShareable
if #available(iOS 14.0, macOS 11.0, tvOS 14.0, watchOS 7.0, *) {
let isFamilyShareable: Bool = product.isFamilyShareable
print(isFamilyShareable)
}
let subscriptionGroupIdentifier: String? = product.subscriptionGroupIdentifier
let priceFormatter: NumberFormatter? = product.priceFormatter
let subscriptionPeriod: SubscriptionPeriod? = product.subscriptionPeriod
Expand All @@ -31,7 +34,10 @@ func checkStoreProductAPI() {
let pricePerMonth: NSDecimalNumber? = product.pricePerMonth
let localizedIntroductoryPriceString: String? = product.localizedIntroductoryPriceString
let sk1Product: SK1Product? = product.sk1Product
let sk2Product: SK2Product? = product.sk2Product
if #available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) {
let sk2Product: SK2Product? = product.sk2Product
print(sk2Product!)
}

print(
product!,
Expand All @@ -44,25 +50,25 @@ func checkStoreProductAPI() {
decimalPrice,
localizedPriceString,
productIdentifier,
isFamilyShareable,
subscriptionGroupIdentifier!,
priceFormatter!,
subscriptionPeriod!,
introductoryPrice!,
discounts,
pricePerMonth!,
localizedIntroductoryPriceString!,
sk1Product!,
sk2Product!
sk1Product!
)
}

func checkConstructors() {
let sk1Product: SK1Product! = nil
let sk2Product: SK2Product! = nil
if #available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) {
let sk2Product: SK2Product! = nil
_ = StoreProduct(sk2Product: sk2Product!)
}

_ = StoreProduct(sk1Product: sk1Product!)
_ = StoreProduct(sk2Product: sk2Product!)
}

func checkProductCategory(_ category: StoreProduct.ProductCategory) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ func checkStoreProductDiscountAPI() {
let subscriptionPeriod: SubscriptionPeriod = discount.subscriptionPeriod

let sk1Discount: SK1ProductDiscount = discount.sk1Discount!
let sk2Discount: SK2ProductDiscount = discount.sk2Discount!
if #available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) {
let sk2Discount: SK2ProductDiscount = discount.sk2Discount!
print(sk2Discount)
}

print(
offerIdentifier!,
Expand All @@ -33,8 +36,7 @@ func checkStoreProductDiscountAPI() {
paymentMode,
priceFormatter!,
subscriptionPeriod,
sk1Discount,
sk2Discount
sk1Discount
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ func checkStoreTransactionAPI() {
let quantity: Int = transaction.quantity

let sk1: SKPaymentTransaction? = transaction.sk1Transaction
let sk2: StoreKit.Transaction? = transaction.sk2Transaction
if #available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) {
let sk2: StoreKit.Transaction? = transaction.sk2Transaction
print(sk2!)
}

print(
productIdentifier,
purchaseDate,
transactionIdentifier,
quantity,
sk1!,
sk2!
sk1!
)
}
Loading

0 comments on commit a72bf3c

Please sign in to comment.