Skip to content

Commit

Permalink
chore: Using the new sendVerificationCode API (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruisebas authored Feb 14, 2024
1 parent 1f9514e commit 3d6a757
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 22 deletions.
38 changes: 19 additions & 19 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,53 +5,53 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/aws-amplify/amplify-swift",
"state" : {
"revision" : "76ba8f1ead1cac4d53f313fb8d214c7bc5000551",
"version" : "2.17.1"
"revision" : "3cc17d2635f743d32c68f4309836d30b49e970cf",
"version" : "2.26.1"
}
},
{
"identity" : "amplify-swift-utils-notifications",
"kind" : "remoteSourceControl",
"location" : "https://github.com/aws-amplify/amplify-swift-utils-notifications.git",
"state" : {
"revision" : "f970384ad1035732f99259255cd2f97564807e41",
"version" : "1.1.0"
"revision" : "959eec669ba97c7d923b963c3e66ca8a0b2737f6",
"version" : "1.1.1"
}
},
{
"identity" : "aws-appsync-realtime-client-ios",
"kind" : "remoteSourceControl",
"location" : "https://github.com/aws-amplify/aws-appsync-realtime-client-ios.git",
"state" : {
"revision" : "c7ec93dcbbcd8abc90c74203937f207a7fcaa611",
"version" : "3.1.1"
"revision" : "a08684c5004e2049c29f57a5938beae9695a1ef7",
"version" : "3.1.2"
}
},
{
"identity" : "aws-crt-swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/awslabs/aws-crt-swift",
"state" : {
"revision" : "6feec6c3787877807aa9a00fad09591b96752376",
"version" : "0.6.1"
"revision" : "fd1756b6e5c9fd1a906edfb743f7cb64c2c98639",
"version" : "0.17.0"
}
},
{
"identity" : "aws-sdk-swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/awslabs/aws-sdk-swift.git",
"state" : {
"revision" : "24bae88a2391fe75da8a940a544d1ef6441f5321",
"version" : "0.13.0"
"revision" : "387016f3e62119e9962da4357c63671c694554e6",
"version" : "0.31.0"
}
},
{
"identity" : "smithy-swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/awslabs/smithy-swift",
"location" : "https://github.com/smithy-lang/smithy-swift",
"state" : {
"revision" : "7b28da158d92cd06a3549140d43b8fbcf64a94a6",
"version" : "0.15.0"
"revision" : "ab999a9f0c972adcb350beda3c630a35697f7e8e",
"version" : "0.35.0"
}
},
{
Expand All @@ -77,26 +77,26 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections",
"state" : {
"revision" : "937e904258d22af6e447a0b72c0bc67583ef64a2",
"version" : "1.0.4"
"revision" : "94cf62b3ba8d4bed62680a282d4c25f9c63c2efb",
"version" : "1.1.0"
}
},
{
"identity" : "swift-log",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-log.git",
"state" : {
"revision" : "532d8b529501fb73a2455b179e0bbb6d49b652ed",
"version" : "1.5.3"
"revision" : "e97a6fcb1ab07462881ac165fdbb37f067e205d5",
"version" : "1.5.4"
}
},
{
"identity" : "xmlcoder",
"kind" : "remoteSourceControl",
"location" : "https://github.com/MaxDesiatov/XMLCoder.git",
"state" : {
"revision" : "b1e944cbd0ef33787b13f639a5418d55b3bed501",
"version" : "0.17.1"
"revision" : "80b4a1646399b8e4e0ce80711653476a85bd5e37",
"version" : "0.17.0"
}
}
],
Expand Down
2 changes: 1 addition & 1 deletion Sources/Authenticator/States/VerifyUserState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class VerifyUserState: AuthenticatorBaseState {

do {
log.verbose("Attempting to verify user attribute \(key)")
let result = try await authenticationService.resendConfirmationCode(
let result = try await authenticationService.sendVerificationCode(
forUserAttributeKey: key,
options: nil
)
Expand Down
11 changes: 11 additions & 0 deletions Tests/AuthenticatorTests/Mocks/MockAuthenticationService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,17 @@ class MockAuthenticationService: AuthenticationService {
throw AuthenticatorError.error(message: "Unable to resend confirmation code for attribute")
}

var sendVerificationCodeForAttributeCount = 0
var mockedSendVerificationCodeForAttributeResult: AuthCodeDeliveryDetails?
func sendVerificationCode(forUserAttributeKey userAttributeKey: AuthUserAttributeKey, options: AuthSendUserAttributeVerificationCodeRequest.Options?) async throws -> AuthCodeDeliveryDetails {
sendVerificationCodeForAttributeCount += 1
if let mockedSendVerificationCodeForAttributeResult = mockedSendVerificationCodeForAttributeResult {
return mockedSendVerificationCodeForAttributeResult
}

throw AuthenticatorError.error(message: "Unable to send verification code for attribute")
}

var confirmUserAttributeCount = 0
var mockedConfirmUserAttributeError: AuthenticatorError?
func confirm(userAttribute: AuthUserAttributeKey, confirmationCode: String, options: AuthConfirmUserAttributeRequest.Options?) async throws {
Expand Down
4 changes: 2 additions & 2 deletions Tests/AuthenticatorTests/States/VerifyUserStateTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ class VerifyUserStateTests: XCTestCase {

func testVerifyUser_withSuccess_shouldSetNextStep() async throws {
let destination = DeliveryDestination.email("[email protected]")
authenticationService.mockedResendConfirmationCodeForAttributeResult = .init(destination: destination)
authenticationService.mockedSendVerificationCodeForAttributeResult = .init(destination: destination)
let task = Task { @MainActor in
state.selectedField = .email
}
await task.value
try await state.verifyUser()
XCTAssertEqual(authenticationService.resendConfirmationCodeForAttributeCount, 1)
XCTAssertEqual(authenticationService.sendVerificationCodeForAttributeCount, 1)
XCTAssertEqual(authenticatorState.setCurrentStepCount, 1)
let currentStep = try XCTUnwrap(authenticatorState.setCurrentStepValue)
guard case .confirmVerifyUser(let attribute, let deliveryDetails) = currentStep else {
Expand Down

0 comments on commit 3d6a757

Please sign in to comment.