Skip to content

Commit

Permalink
Include validation in tests that link maintains account id
Browse files Browse the repository at this point in the history
  • Loading branch information
Supereg committed Sep 1, 2024
1 parent b3a9a9f commit 24165a8
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Sources/SpeziFirebaseAccount/FirebaseAccountService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand All @@ -56,7 +42,11 @@ struct FirebaseAccountTestsView: View {
NavigationStack {
AccountSetup()
.toolbar {
toolbar(closing: $showSetup)
ToolbarItem(placement: .cancellationAction) {
Button("Close") {
showSetup = false
}
}
}
}
}
Expand All @@ -68,12 +58,41 @@ struct FirebaseAccountTestsView: View {
}


@ToolbarContentBuilder
func toolbar(closing flag: Binding<Bool>) -> 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()
}
}
}
6 changes: 5 additions & 1 deletion Tests/UITests/TestAppUITests/FirebaseAccountTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: "[email protected]", password: "TestPassword2", givenName: "Leland", familyName: "Stanford", biography: "Bio")

XCTAssertTrue(app.staticTexts["[email protected]"].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)
Expand Down Expand Up @@ -502,3 +503,6 @@ extension XCUIApplication {
buttons["Close"].tap()
}
}


// swiftlint:disable:this file_length

0 comments on commit 24165a8

Please sign in to comment.