2022-04-12 15:13:28 -07:00
|
|
|
//
|
|
|
|
|
// 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
|
|
|
|
|
//
|
|
|
|
|
// StoreKitErrorTests.swift
|
|
|
|
|
//
|
|
|
|
|
// Created by Nacho Soto on 4/8/22.
|
|
|
|
|
|
|
|
|
|
import Nimble
|
|
|
|
|
@testable import RevenueCat
|
|
|
|
|
import StoreKit
|
|
|
|
|
import XCTest
|
|
|
|
|
|
|
|
|
|
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *)
|
|
|
|
|
class StoreKitErrorTests: BaseErrorTests {
|
|
|
|
|
|
|
|
|
|
override func setUpWithError() throws {
|
|
|
|
|
try super.setUpWithError()
|
|
|
|
|
|
2024-07-01 12:37:21 -07:00
|
|
|
try AvailabilityChecks.iOS16APIAvailableOrSkipTest()
|
2022-04-12 15:13:28 -07:00
|
|
|
}
|
|
|
|
|
|
2023-06-22 06:54:02 -07:00
|
|
|
func testErrorUtilsCreation() {
|
|
|
|
|
let error: StoreKitError = .userCancelled
|
|
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
ErrorUtils.purchasesError(withStoreKitError: error).error
|
|
|
|
|
) == .purchaseCancelledError
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-12 15:13:28 -07:00
|
|
|
func testUserCancelledError() {
|
|
|
|
|
let error: StoreKitError = .userCancelled
|
|
|
|
|
|
|
|
|
|
verifyPurchasesError(error,
|
|
|
|
|
expectedCode: .purchaseCancelledError,
|
|
|
|
|
underlyingError: error)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func testNetworkError() {
|
|
|
|
|
let underlyingError: URLError = .init(.badServerResponse)
|
|
|
|
|
let error: StoreKitError = .networkError(underlyingError)
|
|
|
|
|
|
|
|
|
|
verifyPurchasesError(error,
|
|
|
|
|
expectedCode: .networkError,
|
|
|
|
|
underlyingError: underlyingError)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func testSystemError() {
|
|
|
|
|
let underlyingError: URLError = .init(.cannotCreateFile)
|
|
|
|
|
let error: StoreKitError = .systemError(underlyingError)
|
|
|
|
|
|
|
|
|
|
verifyPurchasesError(error,
|
|
|
|
|
expectedCode: .storeProblemError,
|
|
|
|
|
underlyingError: underlyingError)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func testNotAvailableInStorefrontError() {
|
|
|
|
|
let error: StoreKitError = .notAvailableInStorefront
|
|
|
|
|
|
|
|
|
|
verifyPurchasesError(error,
|
|
|
|
|
expectedCode: .productNotAvailableForPurchaseError,
|
|
|
|
|
underlyingError: error)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if swift(>=5.6)
|
|
|
|
|
func testNotEntitledError() throws {
|
2024-01-09 18:07:05 -08:00
|
|
|
guard #available(iOS 15.4, tvOS 15.4, watchOS 8.5, macOS 12.3, *) else {
|
2022-04-12 15:13:28 -07:00
|
|
|
throw XCTSkip("Required API is not available for this test.")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let error: StoreKitError = .notEntitled
|
|
|
|
|
|
|
|
|
|
verifyPurchasesError(error,
|
|
|
|
|
expectedCode: .storeProblemError,
|
|
|
|
|
underlyingError: error)
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
func testUnknownError() {
|
|
|
|
|
let error: StoreKitError = .unknown
|
|
|
|
|
|
|
|
|
|
verifyPurchasesError(error,
|
|
|
|
|
expectedCode: .storeProblemError,
|
|
|
|
|
underlyingError: error)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|