Skip to content

Instantly share code, notes, and snippets.

@thexande
Created December 20, 2018 05:03
Show Gist options
  • Save thexande/a062d1208d2e5aaf6db63bc08bfd0e58 to your computer and use it in GitHub Desktop.
Save thexande/a062d1208d2e5aaf6db63bc08bfd0e58 to your computer and use it in GitHub Desktop.
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