diff --git a/FirebaseVertexAI/Tests/TestApp/Tests/Integration/GenerateContentIntegrationTests.swift b/FirebaseVertexAI/Tests/TestApp/Tests/Integration/GenerateContentIntegrationTests.swift index 715be6e3e32..f1650f26471 100644 --- a/FirebaseVertexAI/Tests/TestApp/Tests/Integration/GenerateContentIntegrationTests.swift +++ b/FirebaseVertexAI/Tests/TestApp/Tests/Integration/GenerateContentIntegrationTests.swift @@ -43,12 +43,7 @@ struct GenerateContentIntegrationTests { let userID1: String init() async throws { - let authResult = try await Auth.auth().signIn( - withEmail: Credentials.emailAddress1, - password: Credentials.emailPassword1 - ) - userID1 = authResult.user.uid - + userID1 = try await TestHelpers.getUserID() storage = Storage.storage() } diff --git a/FirebaseVertexAI/Tests/TestApp/Tests/Integration/ImagenIntegrationTests.swift b/FirebaseVertexAI/Tests/TestApp/Tests/Integration/ImagenIntegrationTests.swift index 5b2587743d4..05317411704 100644 --- a/FirebaseVertexAI/Tests/TestApp/Tests/Integration/ImagenIntegrationTests.swift +++ b/FirebaseVertexAI/Tests/TestApp/Tests/Integration/ImagenIntegrationTests.swift @@ -39,12 +39,7 @@ struct ImagenIntegrationTests { var userID1: String init() async throws { - let authResult = try await Auth.auth().signIn( - withEmail: Credentials.emailAddress1, - password: Credentials.emailPassword1 - ) - userID1 = authResult.user.uid - + userID1 = try await TestHelpers.getUserID() vertex = VertexAI.vertexAI() storage = Storage.storage() } diff --git a/FirebaseVertexAI/Tests/TestApp/Tests/Integration/IntegrationTests.swift b/FirebaseVertexAI/Tests/TestApp/Tests/Integration/IntegrationTests.swift index 05cc71cde5b..af2c7c97d98 100644 --- a/FirebaseVertexAI/Tests/TestApp/Tests/Integration/IntegrationTests.swift +++ b/FirebaseVertexAI/Tests/TestApp/Tests/Integration/IntegrationTests.swift @@ -48,12 +48,7 @@ final class IntegrationTests: XCTestCase { var userID1 = "" override func setUp() async throws { - let authResult = try await Auth.auth().signIn( - withEmail: Credentials.emailAddress1, - password: Credentials.emailPassword1 - ) - userID1 = authResult.user.uid - + userID1 = try await TestHelpers.getUserID() vertex = VertexAI.vertexAI() model = vertex.generativeModel( modelName: "gemini-2.0-flash", diff --git a/FirebaseVertexAI/Tests/TestApp/Tests/Integration/TestHelpers.swift b/FirebaseVertexAI/Tests/TestApp/Tests/Integration/TestHelpers.swift new file mode 100644 index 00000000000..4dd4c11842d --- /dev/null +++ b/FirebaseVertexAI/Tests/TestApp/Tests/Integration/TestHelpers.swift @@ -0,0 +1,30 @@ +// Copyright 2025 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import FirebaseAuth +import FirebaseCore + +enum TestHelpers { + static func getUserID() async throws -> String { + if let user = Auth.auth().currentUser { + return user.uid + } else { + let authResult = try await Auth.auth().signIn( + withEmail: Credentials.emailAddress1, + password: Credentials.emailPassword1 + ) + return authResult.user.uid + } + } +} diff --git a/FirebaseVertexAI/Tests/TestApp/VertexAITestApp.xcodeproj/project.pbxproj b/FirebaseVertexAI/Tests/TestApp/VertexAITestApp.xcodeproj/project.pbxproj index 0012ad35261..a7d2bf023b2 100644 --- a/FirebaseVertexAI/Tests/TestApp/VertexAITestApp.xcodeproj/project.pbxproj +++ b/FirebaseVertexAI/Tests/TestApp/VertexAITestApp.xcodeproj/project.pbxproj @@ -27,6 +27,7 @@ 86D77DFE2D7B5C86003D155D /* GoogleService-Info-Spark.plist in Resources */ = {isa = PBXBuildFile; fileRef = 86D77DFD2D7B5C86003D155D /* GoogleService-Info-Spark.plist */; }; 86D77E022D7B63AF003D155D /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86D77E012D7B63AC003D155D /* Constants.swift */; }; 86D77E042D7B6C9D003D155D /* InstanceConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86D77E032D7B6C95003D155D /* InstanceConfig.swift */; }; + DEF0BB4F2DA74F680093E9F4 /* TestHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEF0BB4E2DA74F460093E9F4 /* TestHelpers.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -59,6 +60,7 @@ 86D77DFD2D7B5C86003D155D /* GoogleService-Info-Spark.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "GoogleService-Info-Spark.plist"; sourceTree = ""; }; 86D77E012D7B63AC003D155D /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = ""; }; 86D77E032D7B6C95003D155D /* InstanceConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceConfig.swift; sourceTree = ""; }; + DEF0BB4E2DA74F460093E9F4 /* TestHelpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestHelpers.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -137,6 +139,7 @@ 868A7C572CCC27AF00E449DD /* Integration */ = { isa = PBXGroup; children = ( + DEF0BB4E2DA74F460093E9F4 /* TestHelpers.swift */, 8689CDCB2D7F8BCF00BF426B /* CountTokensIntegrationTests.swift */, 868A7C4D2CCC1F4700E449DD /* Credentials.swift */, 8661386D2CC943DE00F4B78E /* IntegrationTests.swift */, @@ -289,6 +292,7 @@ files = ( 8689CDCC2D7F8BD700BF426B /* CountTokensIntegrationTests.swift in Sources */, 86D77E042D7B6C9D003D155D /* InstanceConfig.swift in Sources */, + DEF0BB4F2DA74F680093E9F4 /* TestHelpers.swift in Sources */, 868A7C4F2CCC229F00E449DD /* Credentials.swift in Sources */, 864F8F712D4980DD0002EA7E /* ImagenIntegrationTests.swift in Sources */, 862218812D04E098007ED2D4 /* IntegrationTestUtils.swift in Sources */,