generated from StanfordSpezi/SpeziTemplateApplication
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix account required sheet and make test environment more robust
- Loading branch information
Showing
3 changed files
with
33 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,16 +76,14 @@ class InvitationCodeModule: Module, EnvironmentAccessible { | |
} | ||
} | ||
|
||
func setupTestEnvironment(account: Account, invitationCode: String) async throws { | ||
try await verifyOnboardingCode(invitationCode) | ||
try await setupTestAccount(account: account) | ||
} | ||
|
||
@MainActor | ||
private func setupTestAccount(account: Account) async throws { | ||
func setupTestEnvironment(account: Account, invitationCode: String) async throws { | ||
let email = "[email protected]" | ||
let password = "123456789" | ||
|
||
// let the initial stateChangeDelegate of FirebaseAuth get called. Otherwise, we will interfere with that. | ||
try await Task.sleep(for: .milliseconds(500)) | ||
|
||
if let details = account.details, | ||
details.email == email { | ||
return | ||
|
@@ -95,25 +93,25 @@ class InvitationCodeModule: Module, EnvironmentAccessible { | |
preconditionFailure("Failed to retrieve a user-id-password based account service for test account setup!") | ||
} | ||
|
||
do { | ||
try await service.login(userId: email, password: password) | ||
return // account was already established previously | ||
} catch { | ||
// probably doesn't exists. We try to create a new one below | ||
} | ||
|
||
try await verifyOnboardingCode(invitationCode) | ||
try await setupTestAccount(service: service, email: email, password: password) | ||
} | ||
|
||
private func setupTestAccount(service: any UserIdPasswordAccountService, email: String, password: String) async throws { | ||
do { | ||
// let the initial stateChangeDelegate of FirebaseAuth get called. Otherwise, we will interfere with that. | ||
try await Task.sleep(for: .milliseconds(500)) | ||
|
||
do { | ||
let details = SignupDetails.Builder() | ||
.set(\.userId, value: email) | ||
.set(\.name, value: PersonNameComponents(givenName: "Leland", familyName: "Stanford")) | ||
.set(\.password, value: password) | ||
.build() | ||
try await service.signUp(signupDetails: details) | ||
} catch { | ||
if "\(error)".contains("accountAlreadyInUse") { | ||
try await service.login(userId: email, password: password) | ||
} else { | ||
throw error | ||
} | ||
} | ||
let details = SignupDetails.Builder() | ||
.set(\.userId, value: email) | ||
.set(\.name, value: PersonNameComponents(givenName: "Leland", familyName: "Stanford")) | ||
.set(\.password, value: password) | ||
.build() | ||
try await service.signUp(signupDetails: details) | ||
} catch { | ||
logger.error("Failed setting up test account : \(error)") | ||
throw error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters