This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
late MockGraphQLClient mockGraphQLClient; | |
setUp(() { | |
mockGraphQLClient = generateMockGraphQLClient(); | |
}); | |
Widget _buildTestScaffold() { | |
return GraphQLProvider( | |
client: ValueNotifier(mockGraphQLClient), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UserView extends HookWidget { | |
final String _userId; | |
UserView(this._userId); | |
@override | |
Widget build(BuildContext context) { | |
final query = useQuery$UserById( | |
Options$Query$UserById( | |
variables: Variables$Query$UserById( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
late MockGraphQLClient mockGraphQLClient; | |
setUp(() { | |
mockGraphQLClient = generateMockGraphQLClient(); | |
}); | |
group('UserRepository', () { | |
test('creates a profile', () async { | |
final result = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UserRepository { | |
late final GraphQLClient _graphQLClient; | |
UserRepository({ | |
GraphQLClient? graphQLClient, | |
}) { | |
_graphQLClient = graphQLClient ?? locator<GraphQLClient>(); | |
} | |
Future<String?> create(String id, String? email) async { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MockQueryResult<T> generateMockWatchQuery<T>(MockGraphQLClient graphQLClient) { | |
registerFallbackValue(_FakeWatchQueryOptions<T>()); | |
final query = MockObservableQuery<T>(); | |
final result = MockQueryResult<T>(); | |
when(query.close).thenReturn(QueryLifecycle.closed); | |
when(() => query.stream).thenAnswer((_) => Stream.value(result)); | |
when(() => query.latestResult).thenReturn(result); | |
when( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MockQueryResult<T> generateMockMutation<T>(MockGraphQLClient graphQLClient) { | |
registerFallbackValue(_FakeMutationOptions<T>()); | |
final result = MockQueryResult<T>(); | |
when(() => graphQLClient.mutate<T>(any())).thenAnswer((_) async => result); | |
final queryManager = graphQLClient.queryManager; | |
when(() => queryManager.mutate<T>(any())).thenAnswer((_) async => result); | |
return result; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MockQueryResult<T> generateMockQuery<T>(MockGraphQLClient graphQLClient) { | |
registerFallbackValue(_FakeQueryOptions<T>()); | |
final result = MockQueryResult<T>(); | |
when(() => graphQLClient.query<T>(any())).thenAnswer((_) async => result); | |
final queryManager = graphQLClient.queryManager; | |
when(() => queryManager.query<T>(any())).thenAnswer((_) async => result); | |
return result; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MockGraphQLClient generateMockGraphQLClient() { | |
final graphQLClient = MockGraphQLClient(); | |
final queryManager = MockQueryManager(); | |
when(() => graphQLClient.defaultPolicies).thenReturn(DefaultPolicies()); | |
when(() => graphQLClient.queryManager).thenReturn(queryManager); | |
return graphQLClient; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { auth, initializeApp } from 'firebase-admin'; | |
import { waitForCloudFunctionExecution } from '@helpers/wait'; | |
import { AdminFirestore } from '@test-helpers/types'; | |
import { Collections } from '@test-helpers/constants'; | |
import { getAdminApp, setup, teardown } from '@test-helpers/firestore'; | |
describe('create', () => { | |
const email = '[email protected]'; | |
const displayName = 'Test User'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { auth } from 'firebase-functions'; | |
import { getFirestore } from '../admin'; | |
export const create = auth.user().onCreate(async (userRecord) => { | |
const db = getFirestore(); | |
return db | |
.collection('users') | |
.doc(userRecord.uid) |
NewerOlder