Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyokone committed Sep 11, 2024
1 parent 40f5059 commit 4514df9
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ query ListMoviesByPartialTitle($input: String!) @auth(level: PUBLIC) {
}
}

query ListPersons @auth(level: USER) {
person {
id
name
}
}

# List subset of fields for users
# query ListUsers @auth(level: PUBLIC) {
# users {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,51 +54,51 @@ void runQueryTests() {
expect(result.movies[0].title, 'The Matrix');
});

testWidgets('can add a person', (WidgetTester tester) async {
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 personId =
(await MoviesConnector.instance.listPersons.ref().execute())
.data
.people[0]
.id;

final value = await MoviesConnector.instance.listMovies.ref().execute();
final result = value.data;
expect(result.movies.length, 1);
});
expect(result.movies.length, 0);

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',
),
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 value2 =
await MoviesConnector.instance.listMovies.ref().execute();
final result2 = value2.data;
expect(result2.movies.length, 1);

final movieId = result.movies[0].id;
final movieId = result2.movies[0].id;

ref = MoviesConnector.instance.addDirectorToMovie.ref(
movieId: movieId,
addDirectorToMovieVariables: AddDirectorToMovieVariables(
personId: AddDirectorToMovieVariablesPersonId(id: 'personId'),
),
personId: AddDirectorToMovieVariablesPersonId(id: personId),
);

await ref.execute();

final value2 =
final value3 =
await MoviesConnector.instance.listMovies.ref().execute();
final result2 = value2.data;
expect(result2.movies.length, 1);
expect(result2.movies[0].directed_by.length, 1);
final result3 = value3.data;
expect(result3.movies.length, 1);
expect(result3.movies[0].directed_by.length, 1);
});

testWidgets('can add a director to a movie using id',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
part of movies;

class ListPersons {
String name = "ListPersons";
ListPersons({required this.dataConnect});

Deserializer<ListPersonsResponse> dataDeserializer = (String json) =>
ListPersonsResponse.fromJson(jsonDecode(json) as Map<String, dynamic>);

QueryRef<ListPersonsResponse, void> ref() {
return dataConnect.query(this.name, dataDeserializer, null, null);
}

FirebaseDataConnect dataConnect;
}

class ListPersonsPeople {
late String id;

late String name;

late List<ListPersonsPeopleDirectedMovies> directed_movies;

ListPersonsPeople.fromJson(Map<String, dynamic> json)
: id = json['id'],
name = json['name'],
directed_movies = (json['directed_movies'] as List<dynamic>)
.map((e) => ListPersonsPeopleDirectedMovies.fromJson(e))
.toList() {}

// TODO(mtewani): Fix up to create a map on the fly
Map<String, dynamic> toJson() {
Map<String, dynamic> json = {};

json['id'] = id;

json['name'] = name;

json['directed_movies'] = directed_movies.map((e) => e.toJson()).toList();

return json;
}

ListPersonsPeople({
required this.id,
required this.name,
required this.directed_movies,
}) {
// TODO(mtewani): Only show this if there are optional fields.
}
}

class ListPersonsPeopleDirectedMovies {
late String title;

ListPersonsPeopleDirectedMovies.fromJson(Map<String, dynamic> json)
: title = json['title'] {}

// TODO(mtewani): Fix up to create a map on the fly
Map<String, dynamic> toJson() {
Map<String, dynamic> json = {};

json['title'] = title;

return json;
}

ListPersonsPeopleDirectedMovies({
required this.title,
}) {
// TODO(mtewani): Only show this if there are optional fields.
}
}

class ListPersonsResponse {
late List<ListPersonsPeople> people;

ListPersonsResponse.fromJson(Map<String, dynamic> json)
: people = (json['people'] as List<dynamic>)
.map((e) => ListPersonsPeople.fromJson(e))
.toList() {}

// TODO(mtewani): Fix up to create a map on the fly
Map<String, dynamic> toJson() {
Map<String, dynamic> json = {};

json['people'] = people.map((e) => e.toJson()).toList();

return json;
}

ListPersonsResponse({
required this.people,
}) {
// TODO(mtewani): Only show this if there are optional fields.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ library movies;
import 'package:firebase_data_connect/firebase_data_connect.dart';
import 'dart:convert';

part 'list_movies.dart';

part 'list_movies_by_partial_title.dart';

part 'list_persons.dart';

part 'add_person.dart';

part 'add_director_to_movie.dart';
Expand All @@ -11,11 +17,19 @@ part 'create_movie.dart';

part 'delete_movie.dart';

part 'list_movies.dart';
class MoviesConnector {
ListMovies get listMovies {
return ListMovies(dataConnect: dataConnect);
}

part 'list_movies_by_partial_title.dart';
ListMoviesByPartialTitle get listMoviesByPartialTitle {
return ListMoviesByPartialTitle(dataConnect: dataConnect);
}

ListPersons get listPersons {
return ListPersons(dataConnect: dataConnect);
}

class MoviesConnector {
AddPerson get addPerson {
return AddPerson(dataConnect: dataConnect);
}
Expand All @@ -32,14 +46,6 @@ class MoviesConnector {
return DeleteMovie(dataConnect: dataConnect);
}

ListMovies get listMovies {
return ListMovies(dataConnect: dataConnect);
}

ListMoviesByPartialTitle get listMoviesByPartialTitle {
return ListMoviesByPartialTitle(dataConnect: dataConnect);
}

static ConnectorConfig connectorConfig = ConnectorConfig(
'us-west2',
'movies',
Expand Down

0 comments on commit 4514df9

Please sign in to comment.