Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerjroach committed Jul 2, 2024
1 parent a375ebb commit f7aa456
Showing 1 changed file with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import com.amplifyframework.auth.cognito.options.AWSCognitoAuthUpdateUserAttribu
import com.amplifyframework.auth.cognito.options.AWSCognitoAuthUpdateUserAttributesOptions
import com.amplifyframework.auth.cognito.options.AWSCognitoAuthVerifyTOTPSetupOptions
import com.amplifyframework.auth.cognito.options.AuthFlowType
import com.amplifyframework.auth.cognito.usecases.ResetPasswordUseCase
import com.amplifyframework.auth.exceptions.InvalidStateException
import com.amplifyframework.auth.exceptions.SignedOutException
import com.amplifyframework.auth.options.AuthConfirmResetPasswordOptions
Expand Down Expand Up @@ -95,11 +96,13 @@ import com.amplifyframework.statemachine.codegen.states.AuthenticationState
import com.amplifyframework.statemachine.codegen.states.AuthorizationState
import featureTest.utilities.APICaptorFactory.Companion.onError
import io.mockk.coEvery
import io.mockk.coJustRun
import io.mockk.coVerify
import io.mockk.every
import io.mockk.invoke
import io.mockk.justRun
import io.mockk.mockk
import io.mockk.mockkConstructor
import io.mockk.mockkObject
import io.mockk.mockkStatic
import io.mockk.slot
Expand Down Expand Up @@ -407,6 +410,47 @@ class RealAWSCognitoAuthPluginTest {
verify(exactly = 0) { onSuccess.accept(any()) }
assertEquals(expectedAuthError.toString(), errorCaptor.captured.toString())
}
@Test
fun `reset password executes ResetPasswordUseCase if required params are set`() {
// GIVEN
val onSuccess = mockk<Consumer<AuthResetPasswordResult>>()
val onError = mockk<Consumer<AuthException>>()
val options = mockk<AuthResetPasswordOptions>()
val username = "user"
val pinpointAppId = "abc"
val encodedData = "encodedData"

coEvery {
authEnvironment.getUserContextData(username)
} returns encodedData

every {
authEnvironment.getPinpointEndpointId()
} returns pinpointAppId

mockkConstructor(ResetPasswordUseCase::class)

every { authService.cognitoIdentityProviderClient } returns mockk()
every { authConfiguration.userPool } returns UserPoolConfiguration.invoke { appClientId = "app Client Id" }
coJustRun {
anyConstructed<ResetPasswordUseCase>().execute(
username,
options,
encodedData,
pinpointAppId,
onSuccess,
onError
)
}

// WHEN
plugin.resetPassword(username, options, onSuccess, onError)

// THEN
coVerify {
anyConstructed<ResetPasswordUseCase>().execute(username, options, any(), pinpointAppId, onSuccess, onError)
}
}

@Test
fun `fetch user attributes with success`() {
Expand Down

0 comments on commit f7aa456

Please sign in to comment.