Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyokone committed Sep 11, 2024
1 parent 1212800 commit 4326a8b
Showing 1 changed file with 103 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> 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',
Expand All @@ -19,6 +27,10 @@ void runQueryTests() {
);
});

setUp(() async {
await deleteAllMovies();
});

testWidgets('can query', (WidgetTester tester) async {
final value = await MoviesConnector.instance.listMovies.ref().execute();

Expand Down Expand Up @@ -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);
});
},
);
}

0 comments on commit 4326a8b

Please sign in to comment.