1212// See the License for the specific language governing permissions and
1313// limitations under the License.
1414
15+ import FirebaseAuth
1516import FirebaseCore
1617import FirebaseVertexAI
1718import XCTest
@@ -40,12 +41,27 @@ final class IntegrationTests: XCTestCase {
4041 var vertex : VertexAI !
4142 var model : GenerativeModel !
4243
44+ static let emailEnvVar = " VERTEXAI_INTEGRATION_AUTH_EMAIL_1 "
45+ static let passwordEnvVar = " VERTEXAI_INTEGRATION_AUTH_EMAIL_1_PW "
46+
4347 override func setUp( ) async throws {
44- try XCTSkipIf ( ProcessInfo . processInfo. environment [ " VertexAIRunIntegrationTests " ] == nil , """
48+ let environment = ProcessInfo . processInfo. environment
49+ try XCTSkipIf ( environment [ " VertexAIRunIntegrationTests " ] == nil , """
4550 Vertex AI integration tests skipped; to enable them, set the VertexAIRunIntegrationTests \
4651 environment variable in Xcode or CI jobs.
4752 """ )
4853
54+ let email = try XCTUnwrap (
55+ environment [ IntegrationTests . emailEnvVar] ,
56+ " No email address specified in environment variable \( IntegrationTests . emailEnvVar) . "
57+ )
58+ let password = try XCTUnwrap (
59+ environment [ IntegrationTests . passwordEnvVar] ,
60+ " No email address specified in environment variable \( IntegrationTests . passwordEnvVar) . "
61+ )
62+
63+ try await Auth . auth ( ) . signIn ( withEmail: email, password: password)
64+
4965 vertex = VertexAI . vertexAI ( )
5066 model = vertex. generativeModel (
5167 modelName: " gemini-1.5-flash " ,
@@ -57,10 +73,6 @@ final class IntegrationTests: XCTestCase {
5773 )
5874 }
5975
60- func testShouldFail( ) {
61- XCTFail ( " This should fail if the tests are being run. " )
62- }
63-
6476 // MARK: - Generate Content
6577
6678 func testGenerateContent( ) async throws {
@@ -122,6 +134,18 @@ final class IntegrationTests: XCTestCase {
122134 XCTAssertEqual ( response. totalBillableCharacters, 35 )
123135 }
124136
137+ func testCountTokens_userAuth_fileData( ) async throws {
138+ let fileData = FileDataPart (
139+ uri: " gs://ios-opensource-samples.appspot.com/vertexai/authenticated/user/6FwXhmYnM8VBr655PrQQiWfxqiS2/red.webp " ,
140+ mimeType: " image/jpeg "
141+ )
142+
143+ let response = try await model. countTokens ( fileData)
144+
145+ XCTAssertEqual ( response. totalTokens, 266 )
146+ XCTAssertEqual ( response. totalBillableCharacters, 35 )
147+ }
148+
125149 func testCountTokens_functionCalling( ) async throws {
126150 let sumDeclaration = FunctionDeclaration (
127151 name: " sum " ,
0 commit comments