-
-
Save thexande/a062d1208d2e5aaf6db63bc08bfd0e58 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import XCTest | |
@testable import Apollo | |
final class WorldAPITests: XCTestCase { | |
func test_CountriesQuery() { | |
guard let results = MockGraphQLQuery.countries.responseObject else { | |
XCTFail() | |
return | |
} | |
let query = CountriesQuery() | |
withCache(initialRecords: [:]) { cache in | |
let store = ApolloStore(cache: cache) | |
let client = ApolloClient(networkTransport: MockNetworkTransport(body: results), | |
store: store) | |
let worldStore = World.Store(client: client) | |
let expectation = self.expectation(description: "Fetching query") | |
worldStore.fetchAllCountries { result in | |
defer { | |
expectation.fulfill() | |
} | |
switch result { | |
case .failure: | |
XCTFail() | |
return | |
case let .success(data): | |
guard let first = data.first else { | |
XCTFail() | |
return | |
} | |
let object = World.CountryLite(code: "USA", | |
name: "America", | |
emoji: "🇺🇸") | |
// `Equatable` conformance usage | |
XCTAssertEqual(object, first) | |
} | |
} | |
self.waitForExpectations(timeout: 5, handler: nil) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment