in AppSyncRealTimeClientTests/Connection/AppSyncSubscriptionConnectionTests.swift [72:106]
func testUnSubscribeConnection() {
let connectionProvider = MockConnectionProvider()
let connection = AppSyncSubscriptionConnection(provider: connectionProvider)
let connectingMessageExpectation = expectation(description: "Connecting event should be fired")
let connectedMessageExpectation = expectation(description: "Connected event should be fired")
let unsubscribeAckExpectation = expectation(description: "Not connected event should be fired")
let item = connection.subscribe(
requestString: mockRequestString,
variables: variables
) { event, _ in
switch event {
case .connection(let status):
if status == .connected {
connectedMessageExpectation.fulfill()
}
if status == .connecting {
connectingMessageExpectation.fulfill()
}
if status == .disconnected {
unsubscribeAckExpectation.fulfill()
}
case .data:
XCTFail("Data event should not be published")
case .failed:
XCTFail("Error should not be thrown")
}
}
XCTAssertNotNil(item, "Subscription item should not be nil")
wait(for: [connectingMessageExpectation, connectedMessageExpectation], timeout: 5, enforceOrder: true)
connection.unsubscribe(item: item)
wait(for: [unsubscribeAckExpectation], timeout: 2)
}