mirror of
https://github.com/RevenueCat/purchases-ios
synced 2026-11-11 22:55:55 +05:45
Example:
```diff
- var result: Result<Offerings, OfferingsManager.Error>?
- offeringsManager.offerings(appUserID: MockData.anyAppUserID) {
- result = $0
+ let result = waitUntilValue { completed in
+ self.offeringsManager.offerings(appUserID: MockData.anyAppUserID) {
+ completed($0)
+ }
}
- expect(result).toEventuallyNot(beNil())
```
This removes the need to _poll_ for when the value is returned, and
instead it gets detected immediately, potentially providing a
significant boost in test execution speed.
I've also used `Nimble`'s own `waitUntil` for cases where we don't need
to return a value.
#### `toEventually` usage:
- Before this PR: 353
- After: 229
There's still a lot of legitimate usage of `toEventually`, but I'm sure
I missed other places where this can also simplify the code. This is a
good start for now.
42 lines
1.0 KiB
Swift
42 lines
1.0 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
|
|
//
|
|
// BackendPostAdServicesTokenTests.swift
|
|
//
|
|
// Created by Madeline Beyl on 4/27/22.
|
|
|
|
import Foundation
|
|
|
|
import Nimble
|
|
import XCTest
|
|
|
|
@testable import RevenueCat
|
|
|
|
class BackendPostAdServicesTokenTests: BaseBackendTests {
|
|
|
|
override func createClient() -> MockHTTPClient {
|
|
super.createClient(#file)
|
|
}
|
|
|
|
func testPostAdServicesCallsHttpClient() throws {
|
|
self.httpClient.mock(
|
|
requestPath: .postAdServicesToken(appUserID: Self.userID),
|
|
response: .init(statusCode: .success)
|
|
)
|
|
|
|
waitUntil { completed in
|
|
self.backend.post(adServicesToken: "asdf", appUserID: "asdf") { _ in
|
|
completed()
|
|
}
|
|
}
|
|
expect(self.httpClient.calls).to(haveCount(1))
|
|
}
|
|
|
|
}
|