feat(auth): add reactive repo + extra data + router examples + tests
This commit is contained in:
@@ -21,9 +21,10 @@ import 'package:wyatt_authentication_bloc/wyatt_authentication_bloc.dart';
|
||||
import 'package:wyatt_form_bloc/wyatt_form_bloc.dart';
|
||||
|
||||
class MockAuthenticationRepository extends Mock
|
||||
implements AuthenticationRepositoryInterface {}
|
||||
implements AuthenticationRepository {}
|
||||
|
||||
class MockAuthenticationCubit extends Mock implements AuthenticationCubit {}
|
||||
class MockAuthenticationCubit extends Mock
|
||||
implements AuthenticationCubit<void> {}
|
||||
|
||||
void main() {
|
||||
const String invalidEmailString = 'invalid';
|
||||
@@ -39,8 +40,8 @@ void main() {
|
||||
const Password validPassword = Password.dirty(validPasswordString);
|
||||
|
||||
group('SignInCubit', () {
|
||||
late AuthenticationRepositoryInterface authenticationRepository;
|
||||
late AuthenticationCubit authenticationCubit;
|
||||
late AuthenticationRepository authenticationRepository;
|
||||
late AuthenticationCubit<void> authenticationCubit;
|
||||
|
||||
setUp(() {
|
||||
authenticationRepository = MockAuthenticationRepository();
|
||||
@@ -62,7 +63,6 @@ void main() {
|
||||
expect(
|
||||
SignInCubit(
|
||||
authenticationRepository: authenticationRepository,
|
||||
authenticationCubit: authenticationCubit,
|
||||
).state,
|
||||
const SignInState(),
|
||||
);
|
||||
@@ -73,9 +73,8 @@ void main() {
|
||||
'emits [invalid] when email/password are invalid',
|
||||
build: () => SignInCubit(
|
||||
authenticationRepository: authenticationRepository,
|
||||
authenticationCubit: authenticationCubit,
|
||||
),
|
||||
act: (SignInCubit cubit) => cubit.emailChanged(invalidEmailString),
|
||||
act: (cubit) => cubit.emailChanged(invalidEmailString),
|
||||
expect: () => const <SignInState>[
|
||||
SignInState(email: invalidEmail, status: FormStatus.invalid),
|
||||
],
|
||||
@@ -85,10 +84,9 @@ void main() {
|
||||
'emits [valid] when email/password are valid',
|
||||
build: () => SignInCubit(
|
||||
authenticationRepository: authenticationRepository,
|
||||
authenticationCubit: authenticationCubit,
|
||||
),
|
||||
seed: () => const SignInState(password: validPassword),
|
||||
act: (SignInCubit cubit) => cubit.emailChanged(validEmailString),
|
||||
act: (cubit) => cubit.emailChanged(validEmailString),
|
||||
expect: () => const <SignInState>[
|
||||
SignInState(
|
||||
email: validEmail,
|
||||
@@ -104,10 +102,8 @@ void main() {
|
||||
'emits [invalid] when email/password are invalid',
|
||||
build: () => SignInCubit(
|
||||
authenticationRepository: authenticationRepository,
|
||||
authenticationCubit: authenticationCubit,
|
||||
),
|
||||
act: (SignInCubit cubit) =>
|
||||
cubit.passwordChanged(invalidPasswordString),
|
||||
act: (cubit) => cubit.passwordChanged(invalidPasswordString),
|
||||
expect: () => const <SignInState>[
|
||||
SignInState(
|
||||
password: invalidPassword,
|
||||
@@ -120,10 +116,9 @@ void main() {
|
||||
'emits [valid] when email/password are valid',
|
||||
build: () => SignInCubit(
|
||||
authenticationRepository: authenticationRepository,
|
||||
authenticationCubit: authenticationCubit,
|
||||
),
|
||||
seed: () => const SignInState(email: validEmail),
|
||||
act: (SignInCubit cubit) => cubit.passwordChanged(validPasswordString),
|
||||
act: (cubit) => cubit.passwordChanged(validPasswordString),
|
||||
expect: () => const <SignInState>[
|
||||
SignInState(
|
||||
email: validEmail,
|
||||
@@ -139,9 +134,8 @@ void main() {
|
||||
'does nothing when status is not validated',
|
||||
build: () => SignInCubit(
|
||||
authenticationRepository: authenticationRepository,
|
||||
authenticationCubit: authenticationCubit,
|
||||
),
|
||||
act: (SignInCubit cubit) => cubit.signInWithEmailAndPassword(),
|
||||
act: (cubit) => cubit.signInWithEmailAndPassword(),
|
||||
expect: () => const <SignInState>[],
|
||||
);
|
||||
|
||||
@@ -149,14 +143,13 @@ void main() {
|
||||
'calls signInWithEmailAndPassword with correct email/password',
|
||||
build: () => SignInCubit(
|
||||
authenticationRepository: authenticationRepository,
|
||||
authenticationCubit: authenticationCubit,
|
||||
),
|
||||
seed: () => const SignInState(
|
||||
status: FormStatus.valid,
|
||||
email: validEmail,
|
||||
password: validPassword,
|
||||
),
|
||||
act: (SignInCubit cubit) => cubit.signInWithEmailAndPassword(),
|
||||
act: (cubit) => cubit.signInWithEmailAndPassword(),
|
||||
verify: (_) {
|
||||
verify(
|
||||
() => authenticationRepository.signInWithEmailAndPassword(
|
||||
@@ -172,14 +165,13 @@ void main() {
|
||||
'when signInWithEmailAndPassword succeeds',
|
||||
build: () => SignInCubit(
|
||||
authenticationRepository: authenticationRepository,
|
||||
authenticationCubit: authenticationCubit,
|
||||
),
|
||||
seed: () => const SignInState(
|
||||
status: FormStatus.valid,
|
||||
email: validEmail,
|
||||
password: validPassword,
|
||||
),
|
||||
act: (SignInCubit cubit) => cubit.signInWithEmailAndPassword(),
|
||||
act: (cubit) => cubit.signInWithEmailAndPassword(),
|
||||
expect: () => const <SignInState>[
|
||||
SignInState(
|
||||
status: FormStatus.submissionInProgress,
|
||||
@@ -207,14 +199,13 @@ void main() {
|
||||
},
|
||||
build: () => SignInCubit(
|
||||
authenticationRepository: authenticationRepository,
|
||||
authenticationCubit: authenticationCubit,
|
||||
),
|
||||
seed: () => const SignInState(
|
||||
status: FormStatus.valid,
|
||||
email: validEmail,
|
||||
password: validPassword,
|
||||
),
|
||||
act: (SignInCubit cubit) => cubit.signInWithEmailAndPassword(),
|
||||
act: (cubit) => cubit.signInWithEmailAndPassword(),
|
||||
expect: () => const <SignInState>[
|
||||
SignInState(
|
||||
status: FormStatus.submissionInProgress,
|
||||
|
||||
Reference in New Issue
Block a user