Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
setup for mock response e2e test
  • Loading branch information
cynthiajoan committed Feb 19, 2026
commit 11352e09366819b2ce99c5abd9a2394a95cfa7bf
3 changes: 3 additions & 0 deletions tests/integration_test/e2e_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import 'firebase_performance/firebase_performance_e2e_test.dart'
import 'firebase_remote_config/firebase_remote_config_e2e_test.dart'
as firebase_remote_config;
import 'firebase_storage/firebase_storage_e2e_test.dart' as firebase_storage;
import 'firebase_ai/firebase_ai_e2e_test.dart' as firebase_ai;

// Github Actions environment variable
// ignore: do_not_use_environment
Expand Down Expand Up @@ -62,6 +63,7 @@ void main() {
firebase_performance.main();
firebase_remote_config.main();
firebase_storage.main();
firebase_ai.main();
return;
}

Expand Down Expand Up @@ -98,5 +100,6 @@ void runAllTests() {
firebase_performance.main();
firebase_remote_config.main();
firebase_storage.main();
firebase_ai.main();
firebase_app_check.main();
}
100 changes: 100 additions & 0 deletions tests/integration_test/firebase_ai/firebase_ai_e2e_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// Copyright 2026 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 'dart:convert';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:http/http.dart' as http;
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_ai/src/api.dart';
import 'package:firebase_ai/src/developer/api.dart';
import 'package:firebase_ai/src/imagen/imagen_content.dart';
import 'package:tests/firebase_options.dart';

void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

group('firebase_ai e2e', () {
setUpAll(() async {
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
});

test('test against all json responses from vertexai-sdk-test-data',
() async {
final treeUrl = Uri.parse(
'https://api.github.com/repos/FirebaseExtended/vertexai-sdk-test-data/git/trees/main?recursive=1');
final treeResponse = await http.get(treeUrl);
if (treeResponse.statusCode != 200) {
fail('Failed to fetch tree: ${treeResponse.statusCode}');
}
final treeData = jsonDecode(treeResponse.body);
final tree = treeData['tree'] as List;

final jsonFiles = tree.where((item) {
final path = item['path'] as String;
return path.startsWith('mock-responses/') && path.endsWith('.json');
}).toList();

for (final file in jsonFiles) {
final path = file['path'] as String;
final rawUrl = Uri.parse(
'https://raw.githubusercontent.com/FirebaseExtended/vertexai-sdk-test-data/main/$path');
final response = await http.get(rawUrl);
if (response.statusCode != 200) {
continue;
}
Comment thread
cynthiajoan marked this conversation as resolved.
Outdated

final jsonData = jsonDecode(response.body);

final isVertex = path.contains('vertexai');
final serializer =
isVertex ? VertexSerialization() : DeveloperSerialization();

try {
if (path.contains('generate-images')) {
if (path.contains('gcs')) {
parseImagenGenerationResponse<ImagenGCSImage>(jsonData);
} else {
parseImagenGenerationResponse<ImagenInlineImage>(jsonData);
}
} else if (path.contains('total-tokens') || path.contains('token')) {
if (jsonData is Map &&
(jsonData.containsKey('totalTokens') ||
jsonData.containsKey('error'))) {
serializer.parseCountTokensResponse(jsonData);
} else {
serializer.parseGenerateContentResponse(jsonData);
}
} else {
serializer.parseGenerateContentResponse(jsonData);
}
Comment thread
cynthiajoan marked this conversation as resolved.
Outdated

if (path.contains('failure') && !path.contains('success')) {
fail('Expected parsing to fail for $path, but it succeeded.');
}
} catch (e) {
if (path.contains('failure') && !path.contains('success')) {
// Expected to fail
expect(e, isA<Exception>(),
reason: 'Expected an Exception but got $e for $path');
} else {
fail('Failed to parse success file $path: $e');
}
}
}
});
});
}
1 change: 1 addition & 0 deletions tests/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ environment:
flutter: '>=3.22.0'

dependencies:
firebase_ai: ^3.8.0
cloud_functions: ^6.0.6
cloud_functions_platform_interface: ^5.8.9
cloud_functions_web: ^5.1.2
Expand Down
Loading