in ApolloTests/FetchQueryTestsComplex.swift [83:107]
func testReturnCacheDataAndFetchCacheHit() throws {
let query = TwoHeroesQuery()
withCache(initialRecords: InitialCacheRecords.cacheHit) { cache in
let store = ApolloStore(cache: cache)
let client = ApolloClient(networkTransport: mockNetworkTransport, store: store)
let cacheResultExpectation = self.expectation(description: "Query result from cache")
let serverResultExpectation = self.expectation(description: "Query result from server")
client.fetch(query: query, cachePolicy: .returnCacheDataAndFetch) { (result, error) in
switch (result?.data?.r2?.name, result?.data?.luke?.name) {
case ("R2-D2 Cache", "Luke Skywalker Cache"):
cacheResultExpectation.fulfill()
case ("R2-D2 Server", "Luke Skywalker Server"):
serverResultExpectation.fulfill()
default:
XCTFail("Unexpected or nil result: \(String(describing: result))")
}
}
self.waitForExpectations(timeout: 5, handler: nil)
}
}