forked from delannoyk/apollo-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add execution tests for ApolloClient clearCache callback queue (apoll…
…ographql#1901) * Add ApolloClient execution tests for callback queue * Clean up headerdoc to remove Promise reference
- Loading branch information
1 parent
3225406
commit b6bfea0
Showing
3 changed files
with
66 additions
and
7 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import XCTest | ||
@testable import Apollo | ||
import ApolloTestSupport | ||
|
||
class ExecutionTests: XCTestCase { | ||
static let defaultWaitTimeout = 0.5 | ||
|
||
var store: ApolloStore! | ||
var server: MockGraphQLServer! | ||
var transport: NetworkTransport! | ||
var client: ApolloClient! | ||
|
||
override func setUp() { | ||
store = ApolloStore() | ||
server = MockGraphQLServer() | ||
transport = MockNetworkTransport(server: server, store: store) | ||
client = ApolloClient(networkTransport: transport, store: store) | ||
} | ||
|
||
override func tearDown() { | ||
client = nil | ||
transport = nil | ||
server = nil | ||
store = nil | ||
} | ||
|
||
func testClearCacheCompletion_givenNoCallbackQueue_shouldCallbackOnMainQueue() throws { | ||
let completionCallbackExpectation = expectation(description: "clearCache completion callback on main queue") | ||
client.clearCache() { result in | ||
XCTAssertTrue(Thread.isMainThread) | ||
|
||
completionCallbackExpectation.fulfill() | ||
} | ||
|
||
wait(for: [completionCallbackExpectation], timeout: Self.defaultWaitTimeout) | ||
} | ||
|
||
func testCacheClearCompletion_givenCustomCallbackQueue_shouldCallbackOnCustomQueue() throws { | ||
let label = "CustomQueue" | ||
let queue = DispatchQueue(label: label) | ||
let key = DispatchSpecificKey<String>() | ||
queue.setSpecific(key: key, value: label) | ||
|
||
let completionCallbackExpectation = expectation(description: "clearCache completion callback on custom queue") | ||
client.clearCache(callbackQueue: queue) { result in | ||
XCTAssertEqual(DispatchQueue.getSpecific(key: key), label) | ||
|
||
completionCallbackExpectation.fulfill() | ||
} | ||
|
||
wait(for: [completionCallbackExpectation], timeout: Self.defaultWaitTimeout) | ||
} | ||
} |