Files
purchases-ios/Tests/StoreKitUnitTests/ManageSubscriptionsHelperTests.swift
T
NachoSoto dab5035a19 visionOS: support for Xcode 15 beta 6 (#2989)
### Context:

`#if os(iOS)` no longer evaluates to `true` when compiling for
`visionOS`
Which means we need `|| os(xrOS)`.
But to support older Xcode we need `#if swift(>=5.9) && os(xrOS)`.
But, fun fact, short-circuiting doesn’t work in `Xcode 13`.
And we still need that to run iOS <15 tests (`FB12223404` /
`FB12805891`)

💩 

This works around that by defining our own `VISION_OS` flag.

### Changes:
- Added `VISION_OS` compile time flag to determine SDK
- Replaced `#if os(xrOS)` with `#if VISION_OS`
- Added flag to `Package.swift` (thanks @neonichu for helping with this)
2023-08-09 11:19:40 -07:00

108 lines
3.8 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//
// Copyright RevenueCat Inc. All Rights Reserved.
//
// Licensed under the MIT License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/MIT
//
// ManageSubscriptionsHelperTests.swift
//
// Created by Andrés Boedo on 8/20/21.
import Foundation
import Nimble
import XCTest
@testable import RevenueCat
#if os(macOS) || os(iOS) || VISION_OS
class ManageSubscriptionsHelperTests: TestCase {
private var systemInfo: MockSystemInfo!
private var customerInfoManager: MockCustomerInfoManager!
private var currentUserProvider: CurrentUserProvider!
private var helper: ManageSubscriptionsHelper!
private let mockCustomerInfoData: [String: Any] = [
"request_date": "2018-12-21T02:40:36Z",
"subscriber": [
"original_app_user_id": "app_user_id",
"first_seen": "2019-06-17T16:05:33Z",
"subscriptions": [:] as [String: Any],
"other_purchases": [:] as [String: Any],
"original_application_version": NSNull()
] as [String: Any],
"managementURL": NSNull()
]
override func setUpWithError() throws {
try super.setUpWithError()
self.systemInfo = MockSystemInfo(finishTransactions: true)
self.customerInfoManager = MockCustomerInfoManager(
offlineEntitlementsManager: MockOfflineEntitlementsManager(),
operationDispatcher: MockOperationDispatcher(),
deviceCache: MockDeviceCache(sandboxEnvironmentDetector: self.systemInfo),
backend: MockBackend(),
transactionFetcher: MockStoreKit2TransactionFetcher(),
transactionPoster: MockTransactionPoster(),
systemInfo: self.systemInfo
)
self.currentUserProvider = MockCurrentUserProvider(mockAppUserID: "appUserID")
self.helper = ManageSubscriptionsHelper(systemInfo: self.systemInfo,
customerInfoManager: self.customerInfoManager,
currentUserProvider: self.currentUserProvider)
}
func testShowManageSubscriptions() throws {
// given
var receivedResult: Result<Void, PurchasesError>?
customerInfoManager.stubbedCustomerInfoResult = .success(try CustomerInfo(data: mockCustomerInfoData))
// when
helper.showManageSubscriptions { result in
receivedResult = result
}
// then
expect(receivedResult).toEventuallyNot(beNil())
expect(receivedResult).to(beSuccess())
}
func testShowManageSubscriptionsFailsIfCouldntGetCustomerInfo() throws {
let error: BackendError = .networkError(.errorResponse(
.init(code: .badRequest,
originalCode: BackendErrorCode.badRequest.rawValue,
message: nil,
attributeErrors: [:]),
400)
)
// given
var receivedResult: Result<Void, PurchasesError>?
customerInfoManager.stubbedCustomerInfoResult = .failure(error)
// when
helper.showManageSubscriptions { result in
receivedResult = result
}
// then
expect(receivedResult).toEventuallyNot(beNil())
let nonNilReceivedResult = try XCTUnwrap(receivedResult)
let expectedErrorMessage = "Failed to get managementURL from CustomerInfo. " +
"Details: The operation couldn’t be completed"
let expectedError = ErrorUtils.customerInfoError(withMessage: expectedErrorMessage,
error: error)
expect(nonNilReceivedResult).to(beFailure { error in
expect(error).to(matchError(expectedError))
})
}
}
#endif