mirror of
https://github.com/RevenueCat/purchases-ios
synced 2026-11-11 22:55:55 +05:45
### Depends on: - #1537 - #1540 - #1541 - #1543 - #1546 - #1547 - #1550 - #1551, - #1565 ### Changes - Removed all custom deserialization code thanks to #1537, #1541, and #1543. - The format of the customer info response is now very concise and only in one place (`CustomerInfoResponse`) instead of being passed through dictionaries and magic strings everywhere. - `CustomerInfo` was combining the dictionaries inside of `"subscriptions"` and `"non_subscriptions"`, despite them having different formats. This is now made explicit through type conversions between the two, (see `CustomerInfoResponse.allTransactionsByProductId`). - Removed all custom `CustomerInfo` errors since deserialization is automatic, and the underlying `Error` information will be provided thanks to `ErrorUtils.logDecodingError`. - `CustomerInfo` deserialization always wraps errors into `ErrorCode.customerInfoError`, which is now also covered in a new test. - Added a new snapshot test that covers `CustomerInfo` serialization by storing the result in a JSON file. ### Other changes: - `CustomerInfo` equality is now automatic through the `CustomerInfoResponse` `Equatable` conformance. - Simplified `schemaVersion` handling - All tests still use `CustomerInfo(data: [String: Any])`, but that method is only visible for tests now, and it uses the underlying `Decodable` implementation (see `CustomerInfo+TestExtensions.swift`). - Added extra tests for `CustomerInfoResponse` that use a fixture `CustomerInfo.json`, which is easier to maintain than having JSON in code. - `RawDataContainer` implementation is changed in #1565. ### TODO: - [x] Fix all tests - [x] Update `RawValueContainer` - [x] Consider recovering `CustomerInfoError` - [x] Look at all previously logged errors - [x] Finish `CustomerInfoResponseTests` - [x] Handle all TODOs - [x] Make `RawDataContainer` actually store all the original data: #1565
39 lines
1.1 KiB
Swift
39 lines
1.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
|
|
//
|
|
// BaseHTTPResponseTest.swift
|
|
//
|
|
// Created by Nacho Soto on 4/12/22.
|
|
|
|
@testable import RevenueCat
|
|
import XCTest
|
|
|
|
class BaseHTTPResponseTest: TestCase {
|
|
|
|
func decodeFixture<T: HTTPResponseBody>(
|
|
_ name: String,
|
|
file: StaticString = #filePath,
|
|
line: UInt = #line
|
|
) throws -> T {
|
|
let url = try XCTUnwrap(
|
|
Bundle(for: BundleToken.self).url(forResource: name,
|
|
withExtension: "json",
|
|
subdirectory: "Fixtures"),
|
|
"Could not find file with name: '\(name).json'",
|
|
file: file, line: line
|
|
)
|
|
let data = try XCTUnwrap(Data(contentsOf: url), file: file, line: line)
|
|
|
|
return try T.create(with: data)
|
|
}
|
|
|
|
}
|
|
|
|
private final class BundleToken: NSObject {}
|