Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "feat(auth): add userID property to AuthSignUpResult" #3191

Merged
merged 1 commit into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions Amplify/Categories/Auth/Result/AuthSignUpResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,7 @@ public struct AuthSignUpResult {
///
public let nextStep: AuthSignUpStep

public let userID: String?

public init(
_ nextStep: AuthSignUpStep,
userID: String? = nil
) {
public init(_ nextStep: AuthSignUpStep) {
self.nextStep = nextStep
self.userID = userID
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ extension SignUpOutputResponse {

var authResponse: AuthSignUpResult {
if self.userConfirmed {
return .init(.done, userID: userSub)
return .init(.done)
}
return AuthSignUpResult(
.confirmUser(
codeDeliveryDetails?.toAuthCodeDeliveryDetails(),
nil,
userSub
),
userID: userSub
)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class AWSAuthConfirmSignUpTask: AuthConfirmSignUpTask, DefaultLogger {
environment: userPoolEnvironment)
_ = try await client.confirmSignUp(input: input)
log.verbose("Received success")
return AuthSignUpResult(.done, userID: nil)
return AuthSignUpResult(.done)
} catch let error as AuthError {
throw error
} catch let error as AuthErrorConvertible {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class AWSAuthConfirmSignUpTaskTests: XCTestCase {
let task = AWSAuthConfirmSignUpTask(request, authEnvironment: authEnvironment)
let confirmSignUpResult = try await task.value
print("Confirm Sign Up Result: \(confirmSignUpResult)")
await fulfillment(of: [functionExpectation], timeout: 1)
wait(for: [functionExpectation], timeout: 1)
}

func testConfirmSignUpOperationFailure() async throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,65 +126,6 @@ class AWSAuthSignUpAPITests: BasePluginTest {
XCTAssertFalse(result.isSignUpComplete, "Signin result should be complete")
}

/// Given: A response from Cognito SignUp when `userConfirmed == true` and a present `userSub`
/// When: Invoking `signUp(username:password:options:)`
/// Then: The caller should receive an `AuthSignUpResult` where `nextStep == .done` and
/// `userID` is the `userSub` returned by the service.
func test_signUp_done_withUserSub() async throws {
let sub = UUID().uuidString
mockIdentityProvider = MockIdentityProvider(
mockSignUpResponse: { _ in
return .init(
codeDeliveryDetails: nil,
userConfirmed: true,
userSub: sub
)
}
)

let result = try await plugin.signUp(
username: "foo",
password: "bar",
options: nil
)

XCTAssertEqual(result.nextStep, .done)
XCTAssertEqual(result.userID, sub)
XCTAssertTrue(result.isSignUpComplete)
}

/// Given: A response from Cognito SignUp that includes `codeDeliveryDetails` where `userConfirmed == false`
/// When: Invoking `signUp(username:password:options:)`
/// Then: The caller should receive an `AuthSignUpResult` where `nextStep == .confirmUser` and
/// the applicable associated value of that case and the `userID` both equal the `userSub` returned by the service.
func test_signUp_confirmUser_userIDsMatch() async throws {
let sub = UUID().uuidString
mockIdentityProvider = MockIdentityProvider(
mockSignUpResponse: { _ in
return .init(
codeDeliveryDetails: .init(
attributeName: "some attribute",
deliveryMedium: .email,
destination: ""
),
userConfirmed: false,
userSub: sub
)
}
)

let result = try await plugin.signUp(
username: "foo",
password: "bar",
options: nil
)

guard case .confirmUser(_, _, let userID) = result.nextStep else {
return XCTFail("expected .confirmUser nextStep")
}
XCTAssertEqual(result.userID, userID)
}

func testSignUpServiceError() async {

let errorsToTest: [(signUpOutputError: SignUpOutputError, cognitoError: AWSCognitoAuthError)] = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class AWSAuthSignUpTaskTests: XCTestCase {
let task = AWSAuthSignUpTask(request, authEnvironment: authEnvironment)
let signUpResult = try await task.value
print("Sign Up Result: \(signUpResult)")
await fulfillment(of: [functionExpectation], timeout: 1)
wait(for: [functionExpectation], timeout: 1)
}

/// Given: Configured AuthState machine
Expand Down
Loading