mirror of
https://github.com/RevenueCat/purchases-ios
synced 2026-11-11 22:55:55 +05:45
The new response is now represented by `GetIntroEligibilityResponse`, and has dedicated tests (`GetIntroEligibilityDecodingTests`) using a JSON fixture.
The operation becomes much simpler now, plus I've done a lot of code removing that was redundant.
The actual response handling is now 3 lines:
```swift
let result: [String: IntroEligibility] = Set(productIdentifiers)
.dictionaryWithValues { eligibilities?[$0] ?? .unknown }
.mapValues(IntroEligibility.init)
```
All the tests in `BackendGetIntroEligibilityTests` pass with no changes.
38 lines
963 B
Swift
38 lines
963 B
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
|
|
//
|
|
// GetIntroEligibilityDecodingTests.swift
|
|
//
|
|
// Created by Nacho Soto on 5/12/22.
|
|
|
|
import Nimble
|
|
@testable import RevenueCat
|
|
import XCTest
|
|
|
|
class GetIntroEligibilityDecodingTests: BaseHTTPResponseTest {
|
|
|
|
private var response: GetIntroEligibilityResponse!
|
|
|
|
override func setUpWithError() throws {
|
|
try super.setUpWithError()
|
|
|
|
self.response = try self.decodeFixture("GetIntroEligibility")
|
|
}
|
|
|
|
func testResponseDataIsCorrect() throws {
|
|
expect(self.response.eligibilityByProductIdentifier) == [
|
|
"producta": .eligible,
|
|
"productb": .ineligible,
|
|
"product_c": .unknown,
|
|
"productD": .eligible
|
|
]
|
|
}
|
|
|
|
}
|