Skip to content

Commit daa25c2

Browse files
author
Di Wu
authored
chore: kickoff release
2 parents c295633 + ac1a266 commit daa25c2

File tree

6 files changed

+72
-6
lines changed

6 files changed

+72
-6
lines changed

Amplify/Categories/Auth/Result/AuthSignUpResult.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@ public struct AuthSignUpResult {
2323
///
2424
public let nextStep: AuthSignUpStep
2525

26-
public init(_ nextStep: AuthSignUpStep) {
26+
public let userID: String?
27+
28+
public init(
29+
_ nextStep: AuthSignUpStep,
30+
userID: String? = nil
31+
) {
2732
self.nextStep = nextStep
33+
self.userID = userID
2834
}
2935
}

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/Helpers/SignUpOutputResponse+Helper.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ extension SignUpOutputResponse {
1313

1414
var authResponse: AuthSignUpResult {
1515
if self.userConfirmed {
16-
return .init(.done)
16+
return .init(.done, userID: userSub)
1717
}
1818
return AuthSignUpResult(
1919
.confirmUser(
2020
codeDeliveryDetails?.toAuthCodeDeliveryDetails(),
2121
nil,
2222
userSub
23-
)
23+
),
24+
userID: userSub
2425
)
2526
}
2627
}

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthConfirmSignUpTask.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class AWSAuthConfirmSignUpTask: AuthConfirmSignUpTask, DefaultLogger {
4141
environment: userPoolEnvironment)
4242
_ = try await client.confirmSignUp(input: input)
4343
log.verbose("Received success")
44-
return AuthSignUpResult(.done)
44+
return AuthSignUpResult(.done, userID: nil)
4545
} catch let error as AuthError {
4646
throw error
4747
} catch let error as AuthErrorConvertible {

AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TaskTests/ClientBehaviorTests/SignUp/AWSAuthConfirmSignUpTaskTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class AWSAuthConfirmSignUpTaskTests: XCTestCase {
4545
let task = AWSAuthConfirmSignUpTask(request, authEnvironment: authEnvironment)
4646
let confirmSignUpResult = try await task.value
4747
print("Confirm Sign Up Result: \(confirmSignUpResult)")
48-
wait(for: [functionExpectation], timeout: 1)
48+
await fulfillment(of: [functionExpectation], timeout: 1)
4949
}
5050

5151
func testConfirmSignUpOperationFailure() async throws {

AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TaskTests/ClientBehaviorTests/SignUp/AWSAuthSignUpAPITests.swift

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,65 @@ class AWSAuthSignUpAPITests: BasePluginTest {
126126
XCTAssertFalse(result.isSignUpComplete, "Signin result should be complete")
127127
}
128128

129+
/// Given: A response from Cognito SignUp when `userConfirmed == true` and a present `userSub`
130+
/// When: Invoking `signUp(username:password:options:)`
131+
/// Then: The caller should receive an `AuthSignUpResult` where `nextStep == .done` and
132+
/// `userID` is the `userSub` returned by the service.
133+
func test_signUp_done_withUserSub() async throws {
134+
let sub = UUID().uuidString
135+
mockIdentityProvider = MockIdentityProvider(
136+
mockSignUpResponse: { _ in
137+
return .init(
138+
codeDeliveryDetails: nil,
139+
userConfirmed: true,
140+
userSub: sub
141+
)
142+
}
143+
)
144+
145+
let result = try await plugin.signUp(
146+
username: "foo",
147+
password: "bar",
148+
options: nil
149+
)
150+
151+
XCTAssertEqual(result.nextStep, .done)
152+
XCTAssertEqual(result.userID, sub)
153+
XCTAssertTrue(result.isSignUpComplete)
154+
}
155+
156+
/// Given: A response from Cognito SignUp that includes `codeDeliveryDetails` where `userConfirmed == false`
157+
/// When: Invoking `signUp(username:password:options:)`
158+
/// Then: The caller should receive an `AuthSignUpResult` where `nextStep == .confirmUser` and
159+
/// the applicable associated value of that case and the `userID` both equal the `userSub` returned by the service.
160+
func test_signUp_confirmUser_userIDsMatch() async throws {
161+
let sub = UUID().uuidString
162+
mockIdentityProvider = MockIdentityProvider(
163+
mockSignUpResponse: { _ in
164+
return .init(
165+
codeDeliveryDetails: .init(
166+
attributeName: "some attribute",
167+
deliveryMedium: .email,
168+
destination: ""
169+
),
170+
userConfirmed: false,
171+
userSub: sub
172+
)
173+
}
174+
)
175+
176+
let result = try await plugin.signUp(
177+
username: "foo",
178+
password: "bar",
179+
options: nil
180+
)
181+
182+
guard case .confirmUser(_, _, let userID) = result.nextStep else {
183+
return XCTFail("expected .confirmUser nextStep")
184+
}
185+
XCTAssertEqual(result.userID, userID)
186+
}
187+
129188
func testSignUpServiceError() async {
130189

131190
let errorsToTest: [(signUpOutputError: SignUpOutputError, cognitoError: AWSCognitoAuthError)] = [

AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TaskTests/ClientBehaviorTests/SignUp/AWSAuthSignUpTaskTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class AWSAuthSignUpTaskTests: XCTestCase {
4141
let task = AWSAuthSignUpTask(request, authEnvironment: authEnvironment)
4242
let signUpResult = try await task.value
4343
print("Sign Up Result: \(signUpResult)")
44-
wait(for: [functionExpectation], timeout: 1)
44+
await fulfillment(of: [functionExpectation], timeout: 1)
4545
}
4646

4747
/// Given: Configured AuthState machine

0 commit comments

Comments
 (0)