in AppSyncRealTimeClientTests/Connection/AppSyncSubscriptionConnectionTests.swift [116:144]
func testInvalidConnection() {
let connectionProvider = MockConnectionProvider(validConnection: false)
let connection = AppSyncSubscriptionConnection(provider: connectionProvider)
let connectingMessageExpectation = expectation(description: "Connecting event should be fired")
let errorEventExpectation = expectation(description: "Error event should be fired")
let item = connection.subscribe(
requestString: mockRequestString,
variables: variables
) { event, _ in
switch event {
case .connection(let status):
if status == .connected {
XCTFail("Error should not be thrown")
}
if status == .connecting {
connectingMessageExpectation.fulfill()
}
case .data:
XCTFail("Error should not be thrown")
case .failed:
errorEventExpectation.fulfill()
}
}
XCTAssertNotNil(item, "Subscription item should not be nil")
wait(for: [connectingMessageExpectation, errorEventExpectation], timeout: 5, enforceOrder: true)
}