Skip to content

Commit

Permalink
fix broken unit test cases of API and DataStore
Browse files Browse the repository at this point in the history
  • Loading branch information
5d committed Apr 26, 2024
1 parent 1a20c33 commit acbb4e8
Show file tree
Hide file tree
Showing 11 changed files with 147 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class AWSAPICategoryPluginReachabilityTests: XCTestCase {
XCTAssertEqual(reachability.key, graphQLAPI)
}

func testReachabilityConcurrentPerform() throws {
func testReachabilityConcurrentPerform() async throws {
let graphQLAPI = "graphQLAPI"
let restAPI = "restAPI"
do {
Expand Down Expand Up @@ -114,7 +114,7 @@ class AWSAPICategoryPluginReachabilityTests: XCTestCase {
concurrentPerformCompleted.fulfill()

}
wait(for: [concurrentPerformCompleted], timeout: 1)
await fulfillment(of: [concurrentPerformCompleted], timeout: 1)
XCTAssertEqual(apiPlugin.reachabilityMap.count, 2)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import AWSPluginsCore
class AWSGraphQLOperationTests: AWSAPICategoryPluginTestBase {

/// Tests that upon completion, the operation is removed from the task mapper.
func testOperationCleanup() {
func testOperationCleanup() async {
let request = GraphQLRequest(apiName: apiName,
document: testDocument,
variables: nil,
Expand All @@ -34,7 +34,7 @@ class AWSGraphQLOperationTests: AWSAPICategoryPluginTestBase {
} receiveValue: { _ in }
defer { sink.cancel() }

wait(for: [receivedCompletion], timeout: 1)
await fulfillment(of: [receivedCompletion], timeout: 1)
let task = operation.mapper.task(for: operation)
XCTAssertNil(task)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class AWSRESTOperationTests: OperationTestBase {
await fulfillment(of: [listenerWasInvoked], timeout: 3)
}

func testGetFailsWithBadAPIName() throws {
func testGetFailsWithBadAPIName() async throws {
let sentData = Data([0x00, 0x01, 0x02, 0x03])
try setUpPluginForSingleResponse(sending: sentData, for: .rest)

Expand All @@ -69,14 +69,13 @@ class AWSRESTOperationTests: OperationTestBase {
receivedFailure.fulfill()
}
}

waitForExpectations(timeout: 1.00)
await fulfillment(of: [receivedSuccess, receivedFailure], timeout: 1)
}

/// - Given: A configured plugin
/// - When: I invoke `APICategory.get(apiName:path:listener:)`
/// - Then: The listener is invoked with the successful value
func testGetReturnsValue() throws {
func testGetReturnsValue() async throws {
let sentData = Data([0x00, 0x01, 0x02, 0x03])
try setUpPluginForSingleResponse(sending: sentData, for: .rest)

Expand All @@ -92,10 +91,10 @@ class AWSRESTOperationTests: OperationTestBase {
callbackInvoked.fulfill()
}

wait(for: [callbackInvoked], timeout: 1.0)
await fulfillment(of: [callbackInvoked], timeout: 1.0)
}

func testRESTOperation_withCustomHeader_shouldOverrideDefaultAmplifyHeaders() throws {
func testRESTOperation_withCustomHeader_shouldOverrideDefaultAmplifyHeaders() async throws {
let expectedHeaderValue = "text/plain"
let sentData = Data([0x00, 0x01, 0x02, 0x03])
try setUpPluginForSingleResponse(sending: sentData, for: .rest)
Expand All @@ -117,7 +116,7 @@ class AWSRESTOperationTests: OperationTestBase {
}
callbackInvoked.fulfill()
}
wait(for: [callbackInvoked, validated], timeout: 1.0)
await fulfillment(of: [callbackInvoked, validated], timeout: 1.0)
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class NetworkReachabilityNotifierTests: XCTestCase {
cancellable.cancel()
}

func testWifiConnectivity_publisherGoesOutOfScope() {
func testWifiConnectivity_publisherGoesOutOfScope() async {
MockReachability.iConnection = .wifi
let defaultValueExpect = expectation(description: ".sink receives default value")
let completeExpect = expectation(description: ".sink receives completion")
Expand All @@ -104,12 +104,12 @@ class NetworkReachabilityNotifierTests: XCTestCase {
defaultValueExpect.fulfill()
})

wait(for: [defaultValueExpect], timeout: 1.0)
await fulfillment(of: [defaultValueExpect], timeout: 1.0)
notifier = nil
notification = Notification.init(name: .reachabilityChanged)
NotificationCenter.default.post(notification)

wait(for: [completeExpect], timeout: 1.0)
await fulfillment(of: [completeExpect], timeout: 1.0)
cancellable.cancel()
}
}
Loading

0 comments on commit acbb4e8

Please sign in to comment.