Skip to content

Commit 5401eb0

Browse files
authored
Merge pull request #2263 from AzureAD/feature/sign-up-username-code-e2e-tests
Converted sign up + username with attributes tests to use labs tenant
2 parents 32c0f70 + 52e6d87 commit 5401eb0

File tree

1 file changed

+34
-24
lines changed

1 file changed

+34
-24
lines changed

MSAL/test/integration/native_auth/end_to_end/sign_up/MSALNativeAuthSignUpUsernameEndToEndTests.swift

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ import MSAL
2727

2828
final class MSALNativeAuthSignUpUsernameEndToEndTests: MSALNativeAuthEndToEndBaseTestCase {
2929

30-
private let attributes = ["age": 40]
31-
32-
// Hero Scenario 1.1.1. Sign up – with Email Verification (Email & Email OTP)
30+
// Hero Scenario 2.1.1. Sign up – with Email Verification (Email & Email OTP)
3331
func test_signUpWithCode_withEmailVerification_succeeds() async throws {
3432
guard let sut = initialisePublicClientApplication(clientIdType: .code) else {
3533
XCTFail("Missing information")
@@ -73,18 +71,17 @@ final class MSALNativeAuthSignUpUsernameEndToEndTests: MSALNativeAuthEndToEndBas
7371
checkSignInAfterSignUpDelegate(signInAfterSignUpDelegate, username: usernameOTP)
7472
}
7573

76-
// Hero Scenario 1.1.2. Sign up – with Email Verification as LAST step & Custom Attributes (Email & Email OTP)
74+
// Hero Scenario 2.1.2. Sign up – with Email Verification as LAST step & Custom Attributes (Email & Email OTP)
7775
func test_signUpWithCode_withEmailVerificationAsLastStepAndCustomAttributes_succeeds() async throws {
78-
throw XCTSkip("Skipping this test because application with custom attributes is missing")
79-
guard let sut = initialisePublicClientApplication(clientIdType: .code) else {
80-
XCTFail("Missing information")
76+
guard let sut = initialisePublicClientApplication(clientIdType: .codeAndAttributes) else {
77+
XCTFail("OTP code not retrieved from email")
8178
return
8279
}
8380
let codeRequiredExp = expectation(description: "code required")
8481
let signUpStartDelegate = SignUpStartDelegateSpy(expectation: codeRequiredExp)
8582
let usernameOTP = generateSignUpRandomEmail()
8683

87-
sut.signUp(username: usernameOTP, attributes: attributes, correlationId: correlationId, delegate: signUpStartDelegate)
84+
sut.signUp(username: usernameOTP, attributes: AttributesStub.allAttributes, correlationId: correlationId, delegate: signUpStartDelegate)
8885

8986
await fulfillment(of: [codeRequiredExp])
9087
checkSignUpStartDelegate(signUpStartDelegate)
@@ -93,8 +90,13 @@ final class MSALNativeAuthSignUpUsernameEndToEndTests: MSALNativeAuthEndToEndBas
9390

9491
let signUpCompleteExp = expectation(description: "sign-up complete")
9592
let signUpVerifyCodeDelegate = SignUpVerifyCodeDelegateSpy(expectation: signUpCompleteExp)
93+
94+
guard let code = await retrieveCodeFor(email: usernameOTP) else {
95+
XCTFail("OTP code not retrieved from email")
96+
return
97+
}
9698

97-
signUpStartDelegate.newState?.submitCode(code: "1234", delegate: signUpVerifyCodeDelegate)
99+
signUpStartDelegate.newState?.submitCode(code: code, delegate: signUpVerifyCodeDelegate)
98100

99101
await fulfillment(of: [signUpCompleteExp])
100102
XCTAssertTrue(signUpVerifyCodeDelegate.onSignUpCompletedCalled)
@@ -110,18 +112,17 @@ final class MSALNativeAuthSignUpUsernameEndToEndTests: MSALNativeAuthEndToEndBas
110112
checkSignInAfterSignUpDelegate(signInAfterSignUpDelegate, username: usernameOTP)
111113
}
112114

113-
// Hero Scenario 1.1.3. Sign up – with Email Verification as FIRST step & Custom Attributes (Email & Email OTP)
115+
// Hero Scenario 2.1.3. Sign up – with Email Verification as FIRST step & Custom Attributes (Email & Email OTP)
114116
func test_signUpWithCode_withEmailVerificationAsFirstStepAndCustomAttributes_succeeds() async throws {
115-
throw XCTSkip("Skipping this test because application with custom attributes is missing")
116-
guard let sut = initialisePublicClientApplication(clientIdType: .code) else {
117+
guard let sut = initialisePublicClientApplication(clientIdType: .codeAndAttributes) else {
117118
XCTFail("Missing information")
118119
return
119120
}
120121
let codeRequiredExp = expectation(description: "code required")
121122
let signUpStartDelegate = SignUpStartDelegateSpy(expectation: codeRequiredExp)
122123
let usernameOTP = generateSignUpRandomEmail()
123124

124-
sut.signUp(username: usernameOTP, attributes: attributes, correlationId: correlationId, delegate: signUpStartDelegate)
125+
sut.signUp(username: usernameOTP, correlationId: correlationId, delegate: signUpStartDelegate)
125126

126127
await fulfillment(of: [codeRequiredExp])
127128
checkSignUpStartDelegate(signUpStartDelegate)
@@ -131,7 +132,12 @@ final class MSALNativeAuthSignUpUsernameEndToEndTests: MSALNativeAuthEndToEndBas
131132
let submitCodeExp = expectation(description: "submit code")
132133
let signUpVerifyCodeDelegate = SignUpVerifyCodeDelegateSpy(expectation: submitCodeExp)
133134

134-
signUpStartDelegate.newState?.submitCode(code: "1234", delegate: signUpVerifyCodeDelegate)
135+
guard let code = await retrieveCodeFor(email: usernameOTP) else {
136+
XCTFail("OTP code not retrieved from email")
137+
return
138+
}
139+
140+
signUpStartDelegate.newState?.submitCode(code: code, delegate: signUpVerifyCodeDelegate)
135141

136142
await fulfillment(of: [submitCodeExp])
137143
XCTAssertTrue(signUpVerifyCodeDelegate.onSignUpAttributesRequiredCalled)
@@ -142,7 +148,7 @@ final class MSALNativeAuthSignUpUsernameEndToEndTests: MSALNativeAuthEndToEndBas
142148
let signUpAttributesRequiredDelegate = SignUpAttributesRequiredDelegateSpy(expectation: attributesExp)
143149

144150
signUpVerifyCodeDelegate.attributesRequiredNewState?.submitAttributes(
145-
attributes: attributes,
151+
attributes: AttributesStub.allAttributes,
146152
delegate: signUpAttributesRequiredDelegate
147153
)
148154

@@ -160,18 +166,17 @@ final class MSALNativeAuthSignUpUsernameEndToEndTests: MSALNativeAuthEndToEndBas
160166
checkSignInAfterSignUpDelegate(signInAfterSignUpDelegate, username: usernameOTP)
161167
}
162168

163-
// Hero Scenario 1.1.4. Sign up – with Email Verification as FIRST step & Custom Attributes over MULTIPLE screens (Email & Email OTP)
164-
func test_signUpWithCode_withEmailVerificationAsLastStepAndCustomAttributesOverMultipleScreens_succeeds() async throws {
165-
throw XCTSkip("Skipping this test because application with custom attributes is missing")
166-
guard let sut = initialisePublicClientApplication(clientIdType: .code) else {
169+
// Hero Scenario 2.1.4. Sign up – with Email Verification as FIRST step & Custom Attributes over MULTIPLE screens (Email & Email OTP)
170+
func test_signUpWithCode_withEmailVerificationAsFirstStepAndCustomAttributesOverMultipleScreens_succeeds() async throws {
171+
guard let sut = initialisePublicClientApplication(clientIdType: .codeAndAttributes) else {
167172
XCTFail("Missing information")
168173
return
169174
}
170175
let codeRequiredExp = expectation(description: "code required")
171176
let signUpStartDelegate = SignUpStartDelegateSpy(expectation: codeRequiredExp)
172177
let usernameOTP = generateSignUpRandomEmail()
173178

174-
sut.signUp(username: usernameOTP, attributes: attributes, correlationId: correlationId, delegate: signUpStartDelegate)
179+
sut.signUp(username: usernameOTP, correlationId: correlationId, delegate: signUpStartDelegate)
175180

176181
await fulfillment(of: [codeRequiredExp])
177182
guard signUpStartDelegate.onSignUpCodeRequiredCalled else {
@@ -184,8 +189,13 @@ final class MSALNativeAuthSignUpUsernameEndToEndTests: MSALNativeAuthEndToEndBas
184189

185190
let submitCodeExp = expectation(description: "submit code")
186191
let signUpVerifyCodeDelegate = SignUpVerifyCodeDelegateSpy(expectation: submitCodeExp)
192+
193+
guard let code = await retrieveCodeFor(email: usernameOTP) else {
194+
XCTFail("OTP code not retrieved from email")
195+
return
196+
}
187197

188-
signUpStartDelegate.newState?.submitCode(code: "1234", delegate: signUpVerifyCodeDelegate)
198+
signUpStartDelegate.newState?.submitCode(code: code, delegate: signUpVerifyCodeDelegate)
189199

190200
await fulfillment(of: [submitCodeExp])
191201
XCTAssertTrue(signUpVerifyCodeDelegate.onSignUpAttributesRequiredCalled)
@@ -196,7 +206,7 @@ final class MSALNativeAuthSignUpUsernameEndToEndTests: MSALNativeAuthEndToEndBas
196206
let signUpAttributesRequiredDelegate = SignUpAttributesRequiredDelegateSpy(expectation: submitAttributesExp1)
197207

198208
signUpVerifyCodeDelegate.attributesRequiredNewState?.submitAttributes(
199-
attributes: attributes,
209+
attributes: AttributesStub.attribute1,
200210
delegate: signUpAttributesRequiredDelegate
201211
)
202212

@@ -209,7 +219,7 @@ final class MSALNativeAuthSignUpUsernameEndToEndTests: MSALNativeAuthEndToEndBas
209219
signUpAttributesRequiredDelegate.expectation = submitAttributesExp2
210220

211221
signUpAttributesRequiredDelegate.attributesRequiredState?.submitAttributes(
212-
attributes: attributes,
222+
attributes: AttributesStub.attribute2,
213223
delegate: signUpAttributesRequiredDelegate
214224
)
215225

@@ -227,7 +237,7 @@ final class MSALNativeAuthSignUpUsernameEndToEndTests: MSALNativeAuthEndToEndBas
227237
checkSignInAfterSignUpDelegate(signInAfterSignUpDelegate, username: usernameOTP)
228238
}
229239

230-
// Hero Scenario 1.1.5. Sign up – without automatic sign in (Email & Email OTP)
240+
// Hero Scenario 2.1.9. Sign up – without automatic sign in (Email & Email OTP)
231241
func test_signUpWithoutAutomaticSignIn() async throws {
232242
guard let sut = initialisePublicClientApplication(clientIdType: .code) else {
233243
XCTFail("Missing information")

0 commit comments

Comments
 (0)