milestone/stable-1-reconcile-auth-3 #176
@ -26,25 +26,22 @@ import 'package:example_router/presentation/features/sign_up/blocs/custom_sign_u
 | 
			
		||||
import 'package:flutter/material.dart';
 | 
			
		||||
import 'package:flutter_bloc/flutter_bloc.dart';
 | 
			
		||||
import 'package:go_router/go_router.dart';
 | 
			
		||||
import 'package:wyatt_architecture/wyatt_architecture.dart';
 | 
			
		||||
import 'package:wyatt_authentication_bloc/wyatt_authentication_bloc.dart';
 | 
			
		||||
import 'package:wyatt_form_bloc/wyatt_form_bloc.dart';
 | 
			
		||||
import 'package:wyatt_type_utils/wyatt_type_utils.dart';
 | 
			
		||||
import 'package:wyatt_architecture/wyatt_architecture.dart';
 | 
			
		||||
 | 
			
		||||
FutureOrResult<int?> onAccountChanges(
 | 
			
		||||
  AuthenticationRepository<int> repo,
 | 
			
		||||
  AuthChangeEvent? authEvent,
 | 
			
		||||
) async {
 | 
			
		||||
  if (authEvent is SignInAuthChangeEvent || authEvent is RefreshAuthChangeEvent) {
 | 
			
		||||
    final id = Random().nextInt(1000);
 | 
			
		||||
    final token =
 | 
			
		||||
        await repo.getIdentityToken().fold((value) => value, (error) => 'null');
 | 
			
		||||
  final id = Random().nextInt(1000);
 | 
			
		||||
  final token =
 | 
			
		||||
      await repo.getIdentityToken().fold((value) => value, (error) => 'null');
 | 
			
		||||
 | 
			
		||||
    debugPrint('onAccountChanges: ${authEvent?.account}, type: ${authEvent.runtimeType}, token: $token, generatedId: $id');
 | 
			
		||||
    return Ok<int, AppException>(id);
 | 
			
		||||
  } else {
 | 
			
		||||
    return Err(ClientException('Not supported auth change logic'));
 | 
			
		||||
  }
 | 
			
		||||
  debugPrint(
 | 
			
		||||
      'onAccountChanges: ${authEvent?.account}, type: ${authEvent.runtimeType}, token: $token, generatedId: $id');
 | 
			
		||||
  return Ok<int, AppException>(id);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class App extends StatelessWidget {
 | 
			
		||||
 | 
			
		||||
@ -579,11 +579,11 @@ void main() {
 | 
			
		||||
              [
 | 
			
		||||
                FormInput(
 | 
			
		||||
                  AuthFormField.email,
 | 
			
		||||
                  const Email.dirty(validEmailString),
 | 
			
		||||
                  const Email.pure(),
 | 
			
		||||
                ),
 | 
			
		||||
                FormInput(
 | 
			
		||||
                  AuthFormField.password,
 | 
			
		||||
                  const Password.dirty(validPasswordString),
 | 
			
		||||
                  const Password.pure(),
 | 
			
		||||
                )
 | 
			
		||||
              ],
 | 
			
		||||
              name: AuthFormName.signInForm,
 | 
			
		||||
@ -595,11 +595,11 @@ void main() {
 | 
			
		||||
              [
 | 
			
		||||
                FormInput(
 | 
			
		||||
                  AuthFormField.email,
 | 
			
		||||
                  const Email.dirty(validEmailString),
 | 
			
		||||
                  const Email.pure(),
 | 
			
		||||
                ),
 | 
			
		||||
                FormInput(
 | 
			
		||||
                  AuthFormField.password,
 | 
			
		||||
                  const Password.dirty(validPasswordString),
 | 
			
		||||
                  const Password.pure(),
 | 
			
		||||
                )
 | 
			
		||||
              ],
 | 
			
		||||
              name: AuthFormName.signInForm,
 | 
			
		||||
@ -643,11 +643,11 @@ void main() {
 | 
			
		||||
              [
 | 
			
		||||
                FormInput(
 | 
			
		||||
                  AuthFormField.email,
 | 
			
		||||
                  const Email.dirty(validEmailString),
 | 
			
		||||
                  const Email.pure(),
 | 
			
		||||
                ),
 | 
			
		||||
                FormInput(
 | 
			
		||||
                  AuthFormField.password,
 | 
			
		||||
                  const Password.dirty(validPasswordString),
 | 
			
		||||
                  const Password.pure(),
 | 
			
		||||
                )
 | 
			
		||||
              ],
 | 
			
		||||
              name: AuthFormName.signInForm,
 | 
			
		||||
@ -659,11 +659,11 @@ void main() {
 | 
			
		||||
              [
 | 
			
		||||
                FormInput(
 | 
			
		||||
                  AuthFormField.email,
 | 
			
		||||
                  const Email.dirty(validEmailString),
 | 
			
		||||
                  const Email.pure(),
 | 
			
		||||
                ),
 | 
			
		||||
                FormInput(
 | 
			
		||||
                  AuthFormField.password,
 | 
			
		||||
                  const Password.dirty(validPasswordString),
 | 
			
		||||
                  const Password.pure(),
 | 
			
		||||
                )
 | 
			
		||||
              ],
 | 
			
		||||
              name: AuthFormName.signInForm,
 | 
			
		||||
 | 
			
		||||
@ -65,6 +65,13 @@ void main() {
 | 
			
		||||
        ),
 | 
			
		||||
      ).thenAnswer((_) async => Ok(account));
 | 
			
		||||
 | 
			
		||||
      when(
 | 
			
		||||
        () => authenticationRepository.signInWithEmailAndPassword(
 | 
			
		||||
          email: any(named: 'email'),
 | 
			
		||||
          password: any(named: 'password'),
 | 
			
		||||
        ),
 | 
			
		||||
      ).thenAnswer((_) async => Ok(account));
 | 
			
		||||
 | 
			
		||||
      when(
 | 
			
		||||
        () => authenticationRepository.formRepository,
 | 
			
		||||
      ).thenAnswer((_) => formRepository);
 | 
			
		||||
@ -258,13 +265,13 @@ void main() {
 | 
			
		||||
      );
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    group('submit', () {
 | 
			
		||||
    group('signUpWithEmailPassword', () {
 | 
			
		||||
      blocTest<SignUpCubit<int>, SignUpState>(
 | 
			
		||||
        'does nothing when status is not validated',
 | 
			
		||||
        build: () => SignUpCubit(
 | 
			
		||||
          authenticationRepository: authenticationRepository,
 | 
			
		||||
        ),
 | 
			
		||||
        act: (cubit) => cubit.submit(),
 | 
			
		||||
        act: (cubit) => cubit.signUpWithEmailPassword(),
 | 
			
		||||
        expect: () => const <SignUpState>[],
 | 
			
		||||
      );
 | 
			
		||||
 | 
			
		||||
@ -308,7 +315,7 @@ void main() {
 | 
			
		||||
          ),
 | 
			
		||||
          status: FormStatus.valid,
 | 
			
		||||
        ),
 | 
			
		||||
        act: (cubit) => cubit.submit(),
 | 
			
		||||
        act: (cubit) => cubit.signUpWithEmailPassword(),
 | 
			
		||||
        verify: (_) {
 | 
			
		||||
          verify(
 | 
			
		||||
            () => authenticationRepository.signUp(
 | 
			
		||||
@ -360,7 +367,7 @@ void main() {
 | 
			
		||||
          ),
 | 
			
		||||
          status: FormStatus.valid,
 | 
			
		||||
        ),
 | 
			
		||||
        act: (cubit) => cubit.submit(),
 | 
			
		||||
        act: (cubit) => cubit.signUpWithEmailPassword(),
 | 
			
		||||
        expect: () => <SignUpState>[
 | 
			
		||||
          SignUpState(
 | 
			
		||||
            form: WyattFormImpl(
 | 
			
		||||
@ -444,7 +451,7 @@ void main() {
 | 
			
		||||
          ),
 | 
			
		||||
          status: FormStatus.valid,
 | 
			
		||||
        ),
 | 
			
		||||
        act: (cubit) => cubit.submit(),
 | 
			
		||||
        act: (cubit) => cubit.signUpWithEmailPassword(),
 | 
			
		||||
        expect: () => <SignUpState>[
 | 
			
		||||
          SignUpState(
 | 
			
		||||
            form: WyattFormImpl(
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user