-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SKError
, StoreKitError
, and Product.PurchaseError
conform to `E…
…rrorCodeConvertible` and added tests Follow up to #1437. Fixes [CF-323]
- Loading branch information
Showing
7 changed files
with
321 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
Tests/UnitTests/StoreKitExtensions/PurchaseErrorTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// | ||
// 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 | ||
// | ||
// PurchaseErrorTests.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 PurchaseErrorTests: BaseErrorTests { | ||
|
||
override func setUpWithError() throws { | ||
try super.setUpWithError() | ||
|
||
try AvailabilityChecks.iOS15APIAvailableOrSkipTest() | ||
} | ||
|
||
func testInvalidQuantityError() { | ||
let error: Product.PurchaseError = .invalidQuantity | ||
|
||
verifyPurchasesError(error, | ||
expectedCode: .storeProblemError, | ||
underlyingError: error) | ||
} | ||
|
||
func testProductUnavailableError() { | ||
let error: Product.PurchaseError = .productUnavailable | ||
|
||
verifyPurchasesError(error, | ||
expectedCode: .productNotAvailableForPurchaseError, | ||
underlyingError: error) | ||
} | ||
|
||
func testPurchaseNotAllowedError() { | ||
let error: Product.PurchaseError = .purchaseNotAllowed | ||
|
||
verifyPurchasesError(error, | ||
expectedCode: .purchaseNotAllowedError, | ||
underlyingError: error) | ||
} | ||
|
||
func testIneligibleForOfferError() { | ||
let error: Product.PurchaseError = .ineligibleForOffer | ||
|
||
verifyPurchasesError(error, | ||
expectedCode: .ineligibleError, | ||
underlyingError: error) | ||
} | ||
|
||
func testInvalidOfferError() { | ||
let error: Product.PurchaseError = .missingOfferParameters | ||
|
||
verifyPurchasesError(error, | ||
expectedCode: .invalidPromotionalOfferError, | ||
underlyingError: error) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
// | ||
// 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 | ||
// | ||
// SKErrorTests.swift | ||
// | ||
// Created by Nacho Soto on 4/8/22. | ||
|
||
import Nimble | ||
@testable import RevenueCat | ||
import StoreKit | ||
import XCTest | ||
|
||
class SKErrorTests: BaseErrorTests { | ||
|
||
func testStoreProblemError() { | ||
let error: SKError = .init(.cloudServiceNetworkConnectionFailed) | ||
|
||
verifyPurchasesError(error, | ||
expectedCode: .storeProblemError, | ||
underlyingError: error) | ||
} | ||
|
||
func testPurchaseNotAllowedError() { | ||
let error: SKError = .init(.paymentNotAllowed) | ||
|
||
verifyPurchasesError(error, | ||
expectedCode: .purchaseNotAllowedError, | ||
underlyingError: error) | ||
} | ||
|
||
func testPaymentCancelled() { | ||
let error: SKError = .init(.paymentCancelled) | ||
|
||
verifyPurchasesError(error, | ||
expectedCode: .purchaseCancelledError, | ||
underlyingError: error) | ||
} | ||
|
||
func testPaymentInvalid() { | ||
let error: SKError = .init(.paymentInvalid) | ||
|
||
verifyPurchasesError(error, | ||
expectedCode: .purchaseInvalidError, | ||
underlyingError: error) | ||
} | ||
|
||
func testProductNotAvailableError() { | ||
let error: SKError = .init(.storeProductNotAvailable) | ||
|
||
verifyPurchasesError(error, | ||
expectedCode: .productNotAvailableForPurchaseError, | ||
underlyingError: error) | ||
} | ||
|
||
@available(iOS 14.0, macOS 11.0, watchOS 6.2, *) | ||
@available(tvOS, unavailable) | ||
func testUnsupportedPlatformError() throws { | ||
try AvailabilityChecks.iOS14APIAvailableOrSkipTest() | ||
|
||
let error: SKError = .init(.unsupportedPlatform) | ||
|
||
verifyPurchasesError(error, | ||
expectedCode: .purchaseNotAllowedError, | ||
underlyingError: error) | ||
} | ||
|
||
@available(iOS 14.0, tvOS 14.0, macOS 11.0, watchOS 6.2, *) | ||
func testIneligibleForOfferError() throws { | ||
try AvailabilityChecks.iOS14APIAvailableOrSkipTest() | ||
|
||
let error: SKError = .init(.ineligibleForOffer) | ||
|
||
verifyPurchasesError(error, | ||
expectedCode: .ineligibleError, | ||
underlyingError: error) | ||
} | ||
|
||
@available(iOS 14.0, tvOS 14.0, macOS 11.0, watchOS 6.2, *) | ||
func testInvalidOfferError() throws { | ||
try AvailabilityChecks.iOS14APIAvailableOrSkipTest() | ||
|
||
let error: SKError = .init(.invalidOfferIdentifier) | ||
|
||
verifyPurchasesError(error, | ||
expectedCode: .invalidPromotionalOfferError, | ||
underlyingError: error) | ||
} | ||
|
||
func testCurrentlySubscribedError() throws { | ||
let error = try XCTUnwrap( | ||
NSError( | ||
domain: SKErrorDomain, | ||
code: SKError.unknown.rawValue, | ||
userInfo: [ | ||
NSUnderlyingErrorKey: NSError( | ||
domain: "ASDServerErrorDomain", | ||
code: 3532, | ||
userInfo: [:] | ||
) | ||
] | ||
) as? SKError | ||
) | ||
|
||
verifyPurchasesError(error, | ||
expectedCode: .productAlreadyPurchasedError, | ||
underlyingError: error) | ||
} | ||
|
||
func testPaymentSheetCancelledError() throws { | ||
let error = try XCTUnwrap( | ||
NSError( | ||
domain: SKErrorDomain, | ||
code: 907, | ||
userInfo: [ | ||
NSUnderlyingErrorKey: NSError( | ||
domain: "AMSErrorDomain", | ||
code: 6, | ||
userInfo: [:] | ||
) | ||
] | ||
) as? SKError | ||
) | ||
|
||
verifyPurchasesError(error, | ||
expectedCode: .purchaseCancelledError, | ||
underlyingError: error) | ||
} | ||
|
||
func testUnknownError() throws { | ||
let error = try XCTUnwrap( | ||
NSError( | ||
domain: SKErrorDomain, | ||
code: 100000 | ||
) as? SKError | ||
) | ||
|
||
verifyPurchasesError(error, | ||
expectedCode: .unknownError, | ||
underlyingError: error) | ||
} | ||
|
||
} |
Oops, something went wrong.