Skip to content

Commit

Permalink
fix: unit test fulfillment
Browse files Browse the repository at this point in the history
  • Loading branch information
atierian committed Oct 12, 2023
1 parent 0143d2c commit 0295c08
Show file tree
Hide file tree
Showing 21 changed files with 345 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ class AWSGraphQLSubscriptionOperationCancelTests: XCTestCase {
valueListener: valueListener,
completionListener: completionListener
)
await waitForExpectations(timeout: 5)
await fulfillment(of: [receivedValueConnecting], timeout: 5)

let receivedCompletion = expectation(description: "Received completion")
let receivedFailure = expectation(description: "Received failure")
receivedFailure.isInverted = true
Expand Down Expand Up @@ -145,7 +145,11 @@ class AWSGraphQLSubscriptionOperationCancelTests: XCTestCase {

operation.cancel()
XCTAssert(operation.isCancelled)
await waitForExpectations(timeout: 5)

await fulfillment(
of: [receivedCompletion, receivedFailure, receivedValueDisconnected],
timeout: 5
)
}

func testFailureOnConnection() async {
Expand Down Expand Up @@ -184,7 +188,12 @@ class AWSGraphQLSubscriptionOperationCancelTests: XCTestCase {
valueListener: valueListener,
completionListener: completionListener
)
await waitForExpectations(timeout: 0.3)

await fulfillment(
of: [receivedCompletion, receivedFailure, receivedValue],
timeout: 0.3
)

XCTAssert(operation.isFinished)
}

Expand Down Expand Up @@ -221,7 +230,11 @@ class AWSGraphQLSubscriptionOperationCancelTests: XCTestCase {
valueListener: valueListener,
completionListener: nil
)
await waitForExpectations(timeout: 5)
await fulfillment(
of: [receivedValue],
timeout: 5
)

let receivedFailure = expectation(description: "Received failure")
receivedFailure.isInverted = true
let receivedCompletion = expectation(description: "Received completion")
Expand All @@ -237,6 +250,9 @@ class AWSGraphQLSubscriptionOperationCancelTests: XCTestCase {

operation.cancel()
XCTAssert(operation.isCancelled)
await waitForExpectations(timeout: 5)
await fulfillment(
of: [receivedCompletion, receivedFailure],
timeout: 5
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class AWSPinpointAnalyticsPluginIntergrationTests: XCTestCase {
properties: properties)
Amplify.Analytics.identifyUser(userId: userId, userProfile: userProfile)

await waitForExpectations(timeout: TestCommonConstants.networkTimeout)
await fulfillment(of: [identifyUserEvent], timeout: TestCommonConstants.networkTimeout)

// Remove userId from the current endpoint
let endpointClient = endpointClient()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ class ClearCredentialsTests: XCTestCase {
await action.execute(withDispatcher: MockDispatcher { _ in },
environment: environment)

await waitForExpectations(timeout: 0.1)
await fulfillment(
of: [expectation],
timeout: 0.1
)
}

/// Test is responsible to check if configuration error is correctly caught by the action
Expand Down Expand Up @@ -82,7 +85,10 @@ class ClearCredentialsTests: XCTestCase {
}
}, environment: environment)

await waitForExpectations(timeout: 0.1)
await fulfillment(
of: [expectation],
timeout: 0.1
)
}

/// Test is responsible to check if the clear credentials handle a known error
Expand Down Expand Up @@ -136,7 +142,10 @@ class ClearCredentialsTests: XCTestCase {
}
}, environment: environment)

await waitForExpectations(timeout: 0.1)
await fulfillment(
of: [expectation],
timeout: 0.1
)
}

/// Test is responsible to check if the clear credentials handle an unknown error
Expand Down Expand Up @@ -191,7 +200,10 @@ class ClearCredentialsTests: XCTestCase {
}
}, environment: environment)

await waitForExpectations(timeout: 0.1)
await fulfillment(
of: [expectation],
timeout: 0.1
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ class LoadCredentialsTests: XCTestCase {
}
}, environment: environment)

await waitForExpectations(timeout: 0.1)
await fulfillment(
of: [loadCredentialHandlerInvoked],
timeout: 0.1
)
}

/// Test is responsible to check if configuration error is correctly caught by the action
Expand Down Expand Up @@ -99,7 +102,10 @@ class LoadCredentialsTests: XCTestCase {
}
}, environment: environment)

await waitForExpectations(timeout: 0.1)
await fulfillment(
of: [expectation],
timeout: 0.1
)
}

/// Test is responsible to check if the load credentials handle a known error
Expand Down Expand Up @@ -153,7 +159,10 @@ class LoadCredentialsTests: XCTestCase {
}
}, environment: environment)

await waitForExpectations(timeout: 0.1)
await fulfillment(
of: [expectation],
timeout: 0.1
)
}

/// Test is responsible to check if the load credentials handle an unknown error
Expand Down Expand Up @@ -210,7 +219,10 @@ class LoadCredentialsTests: XCTestCase {
}
}, environment: environment)

await waitForExpectations(timeout: 0.1)
await fulfillment(
of: [expectation],
timeout: 0.1
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ class MigrateLegacyCredentialStoreTests: XCTestCase {
let action = MigrateLegacyCredentialStore()
await action.execute(withDispatcher: MockDispatcher { _ in }, environment: environment)

await waitForExpectations(timeout: 0.1)

await fulfillment(
of: [saveCredentialHandlerInvoked],
timeout: 0.1
)
}

/// Test is responsible for making sure that the legacy credential store clearing up is getting called for user pool and identity pool
Expand Down Expand Up @@ -115,8 +119,9 @@ class MigrateLegacyCredentialStoreTests: XCTestCase {
let action = MigrateLegacyCredentialStore()
await action.execute(withDispatcher: MockDispatcher { _ in }, environment: environment)

await waitForExpectations(timeout: 0.1)

await fulfillment(
of: [migrationCompletionInvoked],
timeout: 0.1
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ class FetchAuthAWSCredentialsTests: XCTestCase {
expectation.fulfill()
}
}, environment: MockInvalidEnvironment())
await waitForExpectations(timeout: 0.1)

await fulfillment(
of: [expectation],
timeout: 0.1
)
}

func testInvalidIdentitySuccessfullResponse() async {
Expand Down Expand Up @@ -60,7 +64,10 @@ class FetchAuthAWSCredentialsTests: XCTestCase {
}
}, environment: authEnvironment)

await waitForExpectations(timeout: 0.1)
await fulfillment(
of: [expectation],
timeout: 0.1
)
}

func testInvalidAWSCredentialSuccessfulResponse() async {
Expand Down Expand Up @@ -93,7 +100,10 @@ class FetchAuthAWSCredentialsTests: XCTestCase {
environment: authEnvironment
)

await waitForExpectations(timeout: 0.1)
await fulfillment(
of: [expectation],
timeout: 0.1
)
}

func testValidSuccessfulResponse() async {
Expand Down Expand Up @@ -134,7 +144,11 @@ class FetchAuthAWSCredentialsTests: XCTestCase {
},
environment: authEnvironment
)
await waitForExpectations(timeout: 0.1)

await fulfillment(
of: [credentialValidExpectation],
timeout: 0.1
)
}

func testFailureResponse() async {
Expand Down Expand Up @@ -166,7 +180,11 @@ class FetchAuthAWSCredentialsTests: XCTestCase {
},
environment: authEnvironment
)
await waitForExpectations(timeout: 0.1)

await fulfillment(
of: [expectation],
timeout: 0.1
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ class RefreshUserPoolTokensTests: XCTestCase {
}, environment: MockInvalidEnvironment()
)

await waitForExpectations(timeout: 0.1)
await fulfillment(
of: [expectation],
timeout: 0.1
)
}

func testInvalidSuccessfulResponse() async {
Expand Down Expand Up @@ -63,7 +66,10 @@ class RefreshUserPoolTokensTests: XCTestCase {
userPoolFactory: identityProviderFactory)
)

await waitForExpectations(timeout: 1)
await fulfillment(
of: [expectation],
timeout: 1
)
}

func testValidSuccessfulResponse() async {
Expand Down Expand Up @@ -93,7 +99,11 @@ class RefreshUserPoolTokensTests: XCTestCase {
}, environment: Defaults.makeDefaultAuthEnvironment(
userPoolFactory: identityProviderFactory)
)
await waitForExpectations(timeout: 0.1)

await fulfillment(
of: [expectation],
timeout: 0.1
)
}

func testFailureResponse() async {
Expand Down Expand Up @@ -128,7 +138,10 @@ class RefreshUserPoolTokensTests: XCTestCase {
}
}, environment: environment)

await waitForExpectations(timeout: 0.1)
await fulfillment(
of: [expectation],
timeout: 0.1
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ class InitializeFetchAuthSessionTests: XCTestCase {
environment: environment
)

await waitForExpectations(timeout: 0.1)
await fulfillment(
of: [expectation],
timeout: 0.1
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ class InitiateAuthSRPTests: XCTestCase {
environment: environment
)

await waitForExpectations(timeout: 0.1)
await fulfillment(
of: [initiateAuthInvoked],
timeout: 0.1
)
}

func testFailedInitiateAuthPropagatesError() async {
Expand Down Expand Up @@ -70,7 +73,10 @@ class InitiateAuthSRPTests: XCTestCase {
environment: environment
)

await waitForExpectations(timeout: 0.1)
await fulfillment(
of: [errorEventSent],
timeout: 0.1
)
}

func testSuccessfulInitiateAuthPropagatesSuccess() async {
Expand Down Expand Up @@ -106,7 +112,9 @@ class InitiateAuthSRPTests: XCTestCase {
environment: environment
)

await waitForExpectations(timeout: 0.1)
await fulfillment(
of: [successEventSent],
timeout: 0.1
)
}

}
Loading

0 comments on commit 0295c08

Please sign in to comment.