diff --git a/packages/firebase_data_connect/firebase_data_connect/example/integration_test/query_e2e.dart b/packages/firebase_data_connect/firebase_data_connect/example/integration_test/query_e2e.dart index 8ad4b6ef9ce0..986c6f5c6533 100644 --- a/packages/firebase_data_connect/firebase_data_connect/example/integration_test/query_e2e.dart +++ b/packages/firebase_data_connect/firebase_data_connect/example/integration_test/query_e2e.dart @@ -6,6 +6,14 @@ import 'package:firebase_data_connect/firebase_data_connect.dart'; import 'package:firebase_data_connect_example/generated/movies.dart'; import 'package:flutter_test/flutter_test.dart'; +Future deleteAllMovies() async { + final value = await MoviesConnector.instance.listMovies.ref().execute(); + final result = value.data; + for (var movie in result.movies) { + await MoviesConnector.instance.deleteMovie.ref(id: movie.id).execute(); + } +} + void runQueryTests() { group( '$FirebaseDataConnect.instance query', @@ -19,6 +27,10 @@ void runQueryTests() { ); }); + setUp(() async { + await deleteAllMovies(); + }); + testWidgets('can query', (WidgetTester tester) async { final value = await MoviesConnector.instance.listMovies.ref().execute(); @@ -56,6 +68,97 @@ void runQueryTests() { final result = value.data; expect(result.movies.length, 1); }); + + testWidgets('can add a director to a movie', (WidgetTester tester) async { + MutationRef ref = MoviesConnector.instance.addPerson.ref( + name: 'Keanu Reeves', + addPersonVariables: AddPersonVariables( + name: 'Keanu Reeves', + ), + ); + + await ref.execute(); + + final value = await MoviesConnector.instance.listMovies.ref().execute(); + final result = value.data; + expect(result.movies.length, 1); + + final movieId = result.movies[0].id; + + ref = MoviesConnector.instance.addDirectorToMovie.ref( + movieId: movieId, + addDirectorToMovieVariables: AddDirectorToMovieVariables( + personId: AddDirectorToMovieVariablesPersonId(id: 'personId'), + ), + ); + + await ref.execute(); + + final value2 = + await MoviesConnector.instance.listMovies.ref().execute(); + final result2 = value2.data; + expect(result2.movies.length, 1); + expect(result2.movies[0].directed_by.length, 1); + }); + + testWidgets('can add a director to a movie using id', + (WidgetTester tester) async { + MutationRef ref = MoviesConnector.instance.addPerson.ref( + name: 'Keanu Reeves', + addPersonVariables: AddPersonVariables( + name: 'Keanu Reeves', + ), + ); + + await ref.execute(); + + final value = await MoviesConnector.instance.listMovies.ref().execute(); + final result = value.data; + expect(result.movies.length, 1); + + final movieId = result.movies[0].id; + + ref = MoviesConnector.instance.addDirectorToMovie.ref( + movieId: movieId, + addDirectorToMovieVariables: AddDirectorToMovieVariables( + personId: AddDirectorToMovieVariablesPersonId(id: 'personId'), + ), + ); + + await ref.execute(); + + final value2 = + await MoviesConnector.instance.listMovies.ref().execute(); + final result2 = value2.data; + expect(result2.movies.length, 1); + expect(result2.movies[0].directed_by.length, 1); + }); + + testWidgets('can delete a movie', (WidgetTester tester) async { + MutationRef ref = MoviesConnector.instance.createMovie.ref( + genre: 'Action', + title: 'The Matrix', + releaseYear: 1999, + rating: 4.5, + ); + + await ref.execute(); + + final value = await MoviesConnector.instance.listMovies.ref().execute(); + final result = value.data; + expect(result.movies.length, 1); + + final movieId = result.movies[0].id; + + ref = MoviesConnector.instance.deleteMovie.ref(id: movieId); + + await ref.execute(); + + final value2 = + await MoviesConnector.instance.listMovies.ref().execute(); + final result2 = value2.data; + expect(result2.movies.length, 0); + }); }, ); }