diff --git a/Sources/SpeziFirebaseAccount/FirebaseAccountService.swift b/Sources/SpeziFirebaseAccount/FirebaseAccountService.swift index 5fcf358..ff69491 100644 --- a/Sources/SpeziFirebaseAccount/FirebaseAccountService.swift +++ b/Sources/SpeziFirebaseAccount/FirebaseAccountService.swift @@ -701,7 +701,7 @@ extension FirebaseAccountService { logger.info("onAppleSignInCompletion creating firebase apple credential from authorization credential") - try await signUp(with: credential) // TODO: pass in if we have a full name? + try await signUp(with: credential) case let .failure(error): guard let authorizationError = error as? ASAuthorizationError else { logger.error("onAppleSignInCompletion received unknown error: \(error)") diff --git a/Tests/UITests/TestApp/FirebaseAccountTests/FirebaseAccountTestsView.swift b/Tests/UITests/TestApp/FirebaseAccountTests/FirebaseAccountTestsView.swift index 4733458..53e9102 100644 --- a/Tests/UITests/TestApp/FirebaseAccountTests/FirebaseAccountTestsView.swift +++ b/Tests/UITests/TestApp/FirebaseAccountTests/FirebaseAccountTestsView.swift @@ -22,27 +22,13 @@ struct FirebaseAccountTestsView: View { @State var showSetup = false @State var showOverview = false + @State private var accountIdFromAnonymousUser: String? var body: some View { List { if let details = account.details { - HStack { - UserProfileView(name: details.name ?? .init(givenName: "NOT FOUND")) - .frame(height: 30) - Text(details.userId) - } - if details.isAnonymous { - ListRow("User") { - Text("Anonymous") - } - } - - ListRow("New User") { - Text(details.isNewUser ? "Yes" : "No") - } - - AsyncButton("Logout", role: .destructive, state: $viewState) { - try await account.accountService.logout() + Section { + accountHeader(for: details) } } Button("Account Setup") { @@ -56,7 +42,11 @@ struct FirebaseAccountTestsView: View { NavigationStack { AccountSetup() .toolbar { - toolbar(closing: $showSetup) + ToolbarItem(placement: .cancellationAction) { + Button("Close") { + showSetup = false + } + } } } } @@ -68,12 +58,41 @@ struct FirebaseAccountTestsView: View { } - @ToolbarContentBuilder - func toolbar(closing flag: Binding) -> some ToolbarContent { - ToolbarItemGroup(placement: .cancellationAction) { - Button("Close") { - flag.wrappedValue = false + @ViewBuilder + @MainActor + private func accountHeader(for details: AccountDetails) -> some View { + HStack { + UserProfileView(name: details.name ?? .init(givenName: "NOT FOUND")) + .frame(height: 30) + Text(details.userId) + } + if details.isAnonymous { + ListRow("User") { + Text("Anonymous") } + .onAppear { + accountIdFromAnonymousUser = details.accountId + } + } + + ListRow("New User") { + Text(details.isNewUser ? "Yes" : "No") + } + + if let accountIdFromAnonymousUser { + ListRow("Account Id") { + if details.accountId == accountIdFromAnonymousUser { + Text(verbatim: "Stable") + .foregroundStyle(.green) + } else { + Text(verbatim: "Changed") + .foregroundStyle(.red) + } + } + } + + AsyncButton("Logout", role: .destructive, state: $viewState) { + try await account.accountService.logout() } } } diff --git a/Tests/UITests/TestAppUITests/FirebaseAccountTests.swift b/Tests/UITests/TestAppUITests/FirebaseAccountTests.swift index 6a99efa..6936d9d 100644 --- a/Tests/UITests/TestAppUITests/FirebaseAccountTests.swift +++ b/Tests/UITests/TestAppUITests/FirebaseAccountTests.swift @@ -445,13 +445,14 @@ final class FirebaseAccountTests: XCTestCase { // swiftlint:disable:this type_bo XCTAssertTrue(app.staticTexts["User, Anonymous"].waitForExistence(timeout: 2.0)) XCTAssertTrue(app.staticTexts["New User, Yes"].exists) + XCTAssertTrue(app.staticTexts["Account Id, Stable"].exists) try app.signup(username: "test@username2.edu", password: "TestPassword2", givenName: "Leland", familyName: "Stanford", biography: "Bio") XCTAssertTrue(app.staticTexts["test@username2.edu"].waitForExistence(timeout: 2.0)) XCTAssertTrue(app.staticTexts["New User, Yes"].exists) // ensure new user flag persists + XCTAssertTrue(app.staticTexts["Account Id, Stable"].exists) // ensure we actually linked the account and not accidentally created a new one - // TODO: ensure account id is stable! app.buttons["Account Overview"].tap() XCTAssert(app.staticTexts["Leland Stanford"].waitForExistence(timeout: 2.0)) XCTAssert(app.staticTexts["Biography, Bio"].exists) @@ -502,3 +503,6 @@ extension XCUIApplication { buttons["Close"].tap() } } + + +// swiftlint:disable:this file_length