|
4 | 4 | //
|
5 | 5 | // Created by Russell Wheatley on 18/02/2025.
|
6 | 6 | //
|
7 |
| - |
| 7 | +import FirebaseAuth |
| 8 | +import FirebaseAuthSwiftUI |
| 9 | +import FirebaseCore |
8 | 10 | @testable import FirebaseSwiftUIExample
|
9 | 11 | import Testing
|
10 | 12 |
|
| 13 | +let kEmailAddress = "[email protected]" |
| 14 | +let kPassword = "123456" |
| 15 | + |
11 | 16 | struct FirebaseSwiftUIExampleTests {
|
12 |
| - @Test func example() async throws { |
13 |
| - // Write your test here and use APIs like `#expect(...)` to check expected conditions. |
| 17 | + @MainActor |
| 18 | + func prepareFreshAuthService() async throws -> AuthService { |
| 19 | + configureFirebaseIfNeeded() |
| 20 | + try await clearAuthEmulatorState() |
| 21 | + |
| 22 | + let auth = Auth.auth() |
| 23 | + return AuthService(auth: auth) |
| 24 | + } |
| 25 | + |
| 26 | + @Test |
| 27 | + @MainActor |
| 28 | + func testCreateEmailPasswordUser() async throws { |
| 29 | + let service = try await prepareFreshAuthService() |
| 30 | + |
| 31 | + #expect(service.authenticationState == .unauthenticated) |
| 32 | + #expect(service.authView == .authPicker) |
| 33 | + #expect(service.errorMessage.isEmpty) |
| 34 | + #expect(service.signedInCredential == nil) |
| 35 | + try await service.createUser(withEmail: kEmailAddress, password: kPassword) |
| 36 | + |
| 37 | + #expect(service.authenticationState == .authenticated) |
| 38 | + #expect(service.authView == .authPicker) |
| 39 | + #expect(service.errorMessage.isEmpty) |
| 40 | + // TODO: - reinstate once this PR is merged: https://github.com/firebase/FirebaseUI-iOS/pull/1256 |
| 41 | +// #expect(service.signedInCredential is AuthCredential) |
| 42 | + } |
| 43 | + |
| 44 | + @Test |
| 45 | + @MainActor |
| 46 | + func testSignInUser() async throws { |
| 47 | + let service = try await prepareFreshAuthService() |
| 48 | + // TODO: - it clears emulator data but seems like it is still there? |
| 49 | +// try await service.createUser(withEmail: kEmailAddress, password: kPassword) |
| 50 | +// try await service.signOut() |
| 51 | +// #expect(service.authenticationState == .unauthenticated) |
| 52 | +// #expect(service.authView == .authPicker) |
| 53 | +// #expect(service.errorMessage.isEmpty) |
| 54 | +// #expect(service.signedInCredential == nil) |
| 55 | + |
| 56 | + try await service.signIn(withEmail: kEmailAddress, password: kPassword) |
| 57 | + |
| 58 | + #expect(service.authenticationState == .authenticated) |
| 59 | + #expect(service.authView == .authPicker) |
| 60 | + #expect(service.errorMessage.isEmpty) |
| 61 | + // TODO: - reinstate once this PR is merged: https://github.com/firebase/FirebaseUI-iOS/pull/1256 |
| 62 | +// #expect(service.signedInCredential is AuthCredential) |
14 | 63 | }
|
15 | 64 | }
|
0 commit comments