Files
purchases-ios/Tests/UnitTests/Networking/Backend/BackendPostAttributionDataTests.swift
T
NachoSoto dd60d6c012 Tests: replaced toEventually with new waitUntilValue to simplify tests (#2071)
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.
2022-11-28 08:47:08 -08:00

46 lines
1.2 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
//
// BackendPostAttributionDataTests.swift
//
// Created by Nacho Soto on 3/7/22.
import Foundation
import Nimble
import XCTest
@testable import RevenueCat
class BackendPostAttributionDataTests: BaseBackendTests {
override func createClient() -> MockHTTPClient {
super.createClient(#file)
}
func testPostAttributesPutsDataInDataKey() throws {
self.httpClient.mock(
requestPath: .postAttributionData(appUserID: Self.userID),
response: .init(statusCode: .success)
)
let data: [String: AnyObject] = ["a": "b" as NSString, "c": "d" as NSString]
waitUntil { completed in
self.backend.post(attributionData: data,
network: .adjust,
appUserID: Self.userID) { _ in
completed()
}
}
expect(self.httpClient.calls).to(haveCount(1))
}
}