-
-
Save thexande/e13a4e17841671aeec547306435bcbc4 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
extension WorldAPITests { | |
func test_CountryQuery() { | |
guard let results = MockGraphQLQuery.country.responseObject else { | |
XCTFail() | |
return | |
} | |
let query = CountryQuery() | |
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.fetchCountry(code: "AE") { result in | |
defer { | |
expectation.fulfill() | |
} | |
switch result { | |
case .failure: | |
XCTFail() | |
return | |
case let .success(worldCountry): | |
let country = World.CountryDetail(code: "AE", | |
name: "United Arab Emirates", | |
currency: "AED", | |
phone: "971", | |
emoji: "🇦🇪", | |
languages: [World.CountryDetail.Language(name: "Arabic")], | |
continent: World.CountryDetail.Continent(name: "Asia")) | |
XCTAssertEqual(country, worldCountry) | |
} | |
} | |
self.waitForExpectations(timeout: 5, handler: nil) | |
} | |
} | |
func test_CountryQueryParsingFailure() { | |
let results: JSONObject = ["🍔": 0xDEADBEEF] | |
let query = CountriesQuery() | |
withCache(initialRecords: [:]) { cache in | |
let store = ApolloStore(cache: cache) | |
let client = ApolloClient(networkTransport: MockNetworkTransport(body: results, | |
simulateNetworkFailure: false), | |
store: store) | |
let worldStore = World.Store(client: client) | |
let expectation = self.expectation(description: "Fetching query") | |
worldStore.fetchCountry(code: "USA") { result in | |
defer { | |
expectation.fulfill() | |
} | |
switch result { | |
case let .failure(error): | |
XCTAssertEqual(error, World.StoreError.parsing) | |
return | |
case .success: | |
XCTFail() | |
} | |
} | |
self.waitForExpectations(timeout: 5, handler: nil) | |
} | |
} | |
func test_CountryQueryNetworkFailure() { | |
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, | |
simulateNetworkFailure: true), | |
store: store) | |
let worldStore = World.Store(client: client) | |
let expectation = self.expectation(description: "Fetching query") | |
worldStore.fetchCountry(code: "USA") { result in | |
defer { | |
expectation.fulfill() | |
} | |
switch result { | |
case let .failure(error): | |
XCTAssertEqual(error, World.StoreError.network) | |
return | |
case .success: | |
XCTFail() | |
} | |
} | |
self.waitForExpectations(timeout: 5, handler: nil) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment