mirror of
https://github.com/RevenueCat/purchases-ios
synced 2026-11-11 22:55:55 +05:45
When compiling with Xcode 16, we started throwing a bunch of new warnings. Here's a list and explanation of each: - The most common one was needing to explicitly restate the @unchecked Sendable conformance from a parent class. - There were a couple switches where a new entry was added in tvOS but only for iOS 18, and needed to add it to make it exhaustive. - There we a couple of places where we were adding a protocol conformance to a class from a different module e.g. extension DispatchTimeInterval: Comparable. This is considered unsafe now because the owners of the module could add the conformance later. Solved by removing the conformance which wasn't being used widely in the codebase, only in tests. - Finally there was a class where we were capturing SKRequest and SKProductsRequest instances in a sendable block, but only to either log something, or use them as dictionary key, so I just made the classes Sendable (with the new @retroactice attribute because they belong to a different module)
95 lines
5.1 KiB
Swift
95 lines
5.1 KiB
Swift
//
|
|
// 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
|
|
//
|
|
// MockOfferingsAPI.swift
|
|
//
|
|
// Created by Joshua Liebowitz on 6/17/22.
|
|
|
|
import Foundation
|
|
@testable import RevenueCat
|
|
|
|
// swiftlint:disable line_length large_tuple
|
|
class MockOfferingsAPI: OfferingsAPI {
|
|
|
|
var invokedGetIntroEligibility = false
|
|
var invokedGetIntroEligibilityCount = 0
|
|
var invokedGetIntroEligibilityParameters: (appUserID: String?, receiptData: Data?, productIdentifiers: Set<String>?, completion: OfferingsAPI.IntroEligibilityResponseHandler?)?
|
|
var invokedGetIntroEligibilityParametersList = [(appUserID: String?,
|
|
receiptData: Data?,
|
|
productIdentifiers: Set<String>?,
|
|
completion: OfferingsAPI.IntroEligibilityResponseHandler?)]()
|
|
var stubbedGetIntroEligibilityCompletionResult: (eligibilities: [String: IntroEligibility], error: BackendError?)?
|
|
|
|
override func getIntroEligibility(appUserID: String,
|
|
receiptData: Data,
|
|
productIdentifiers: Set<String>,
|
|
completion: @escaping IntroEligibilityResponseHandler) {
|
|
self.invokedGetIntroEligibility = true
|
|
self.invokedGetIntroEligibilityCount += 1
|
|
self.invokedGetIntroEligibilityParameters = (appUserID, receiptData, productIdentifiers, completion)
|
|
self.invokedGetIntroEligibilityParametersList.append((appUserID, receiptData, productIdentifiers, completion))
|
|
completion(self.stubbedGetIntroEligibilityCompletionResult?.eligibilities ?? [:], self.stubbedGetIntroEligibilityCompletionResult?.error)
|
|
}
|
|
|
|
var invokedGetOfferingsForAppUserID = false
|
|
var invokedGetOfferingsForAppUserIDCount = 0
|
|
var invokedGetOfferingsForAppUserIDParameters: (appUserID: String?, isAppBackgrounded: Bool, completion: OfferingsAPI.OfferingsResponseHandler?)?
|
|
var invokedGetOfferingsForAppUserIDParametersList = [(appUserID: String?, isAppBackgrounded: Bool, completion: OfferingsAPI.OfferingsResponseHandler?)]()
|
|
var stubbedGetOfferingsCompletionResult: Result<OfferingsResponse, BackendError>?
|
|
|
|
override func getOfferings(appUserID: String,
|
|
isAppBackgrounded: Bool,
|
|
completion: @escaping OfferingsResponseHandler) {
|
|
self.invokedGetOfferingsForAppUserID = true
|
|
self.invokedGetOfferingsForAppUserIDCount += 1
|
|
self.invokedGetOfferingsForAppUserIDParameters = (appUserID, isAppBackgrounded, completion)
|
|
self.invokedGetOfferingsForAppUserIDParametersList.append((appUserID, isAppBackgrounded, completion))
|
|
|
|
completion(self.stubbedGetOfferingsCompletionResult!)
|
|
}
|
|
|
|
var invokedPostOffer = false
|
|
var invokedPostOfferCount = 0
|
|
var invokedPostOfferParameters: (offerIdentifier: String?, productIdentifier: String?, subscriptionGroup: String?, data: EncodedAppleReceipt?, applicationUsername: String?, completion: OfferingsAPI.OfferSigningResponseHandler?)?
|
|
var invokedPostOfferParametersList = [(offerIdentifier: String?,
|
|
productIdentifier: String?,
|
|
subscriptionGroup: String?,
|
|
data: EncodedAppleReceipt?,
|
|
applicationUsername: String?,
|
|
completion: OfferingsAPI.OfferSigningResponseHandler?)]()
|
|
var stubbedPostOfferCompletionResult: Result<PostOfferForSigningOperation.SigningData, BackendError>?
|
|
|
|
override func post(offerIdForSigning offerIdentifier: String,
|
|
productIdentifier: String,
|
|
subscriptionGroup: String?,
|
|
receipt: EncodedAppleReceipt,
|
|
appUserID: String,
|
|
completion: @escaping OfferingsAPI.OfferSigningResponseHandler) {
|
|
self.invokedPostOffer = true
|
|
self.invokedPostOfferCount += 1
|
|
self.invokedPostOfferParameters = (offerIdentifier,
|
|
productIdentifier,
|
|
subscriptionGroup,
|
|
receipt,
|
|
appUserID,
|
|
completion)
|
|
self.invokedPostOfferParametersList.append((offerIdentifier,
|
|
productIdentifier,
|
|
subscriptionGroup,
|
|
receipt,
|
|
appUserID,
|
|
completion))
|
|
|
|
completion(self.stubbedPostOfferCompletionResult ?? .failure(.missingAppUserID()))
|
|
}
|
|
|
|
}
|
|
|
|
extension MockOfferingsAPI: @unchecked Sendable {}
|