mirror of
https://github.com/RevenueCat/purchases-ios
synced 2026-11-11 22:55:55 +05:45
## Motivation: There is no way to run code statically like in Obj-C using `+ [NSObject initialize]`, so this ensures (through a new `SwiftLint` rule) that all test classes inherit this common test class instead of `XCTestCase` directly. A future PR will make use of this new `CIRCLECI_TESTS_GENERATE_SNAPSHOTS` environment variable to allow regenerating snapshots in CI. I've also moved the duplicated `CurrentTestCaseTracker` usages to a single point.
61 lines
1.7 KiB
Swift
61 lines
1.7 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
|
|
//
|
|
// BaseErrorTests.swift
|
|
//
|
|
// Created by Nacho Soto on 4/7/22.
|
|
|
|
// swiftlint:disable multiline_parameters
|
|
|
|
import Nimble
|
|
@testable import RevenueCat
|
|
import XCTest
|
|
|
|
class BaseErrorTests: TestCase {
|
|
|
|
/// Compares the result of calling `asPurchasesError` on a `ErrorCodeConvertible`
|
|
/// against the expected `ErrorCode`.
|
|
func verifyPurchasesError(
|
|
_ error: ErrorCodeConvertible,
|
|
expectedCode: ErrorCode,
|
|
underlyingError: Error? = nil,
|
|
userInfoKeys: [NSError.UserInfoKey]? = nil,
|
|
file: FileString = #file, line: UInt = #line
|
|
) {
|
|
let nsError = error.asPurchasesError as NSError
|
|
|
|
expect(
|
|
file: file, line: line,
|
|
nsError.domain
|
|
) == RCPurchasesErrorCodeDomain
|
|
expect(
|
|
file: file, line: line,
|
|
nsError.code
|
|
) == expectedCode.rawValue
|
|
|
|
if let underlyingError = underlyingError {
|
|
expect(
|
|
file: file, line: line,
|
|
nsError.userInfo[NSUnderlyingErrorKey] as? NSError
|
|
).to(matchError(underlyingError),
|
|
description: "Invalid underlying error")
|
|
} else {
|
|
expect(
|
|
file: file, line: line,
|
|
nsError.userInfo[NSUnderlyingErrorKey]
|
|
).to(beNil(), description: "Expected no underlying error")
|
|
}
|
|
|
|
if let userInfoKeys = userInfoKeys {
|
|
expect(nsError.userInfo.keys).to(contain(userInfoKeys as [String]))
|
|
}
|
|
}
|
|
|
|
}
|