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('SignUpCubit', () {
|
||||
late AuthenticationRepositoryInterface authenticationRepository;
|
||||
late AuthenticationCubit authenticationCubit;
|
||||
late AuthenticationRepository authenticationRepository;
|
||||
late AuthenticationCubit<void> authenticationCubit;
|
||||
|
||||
setUp(() {
|
||||
authenticationRepository = MockAuthenticationRepository();
|
||||
@@ -50,9 +51,7 @@ void main() {
|
||||
email: any(named: 'email'),
|
||||
password: any(named: 'password'),
|
||||
),
|
||||
).thenAnswer((_) async {
|
||||
return 'uid';
|
||||
});
|
||||
).thenAnswer((_) async => 'uid');
|
||||
|
||||
when(
|
||||
() => authenticationCubit.start(),
|
||||
@@ -67,8 +66,7 @@ void main() {
|
||||
expect(
|
||||
SignUpCubit(
|
||||
authenticationRepository: authenticationRepository,
|
||||
authenticationCubit: authenticationCubit,
|
||||
entries: const FormData.empty(),
|
||||
formData: const FormData.empty(),
|
||||
).state,
|
||||
const SignUpState(data: FormData.empty()),
|
||||
);
|
||||
@@ -79,10 +77,9 @@ void main() {
|
||||
'emits [invalid] when email/password are invalid',
|
||||
build: () => SignUpCubit(
|
||||
authenticationRepository: authenticationRepository,
|
||||
authenticationCubit: authenticationCubit,
|
||||
entries: const FormData.empty(),
|
||||
formData: const FormData.empty(),
|
||||
),
|
||||
act: (SignUpCubit cubit) => cubit.emailChanged(invalidEmailString),
|
||||
act: (cubit) => cubit.emailChanged(invalidEmailString),
|
||||
expect: () => <SignUpState>[
|
||||
const SignUpState(
|
||||
email: invalidEmail,
|
||||
@@ -96,14 +93,13 @@ void main() {
|
||||
'emits [valid] when email/password are valid',
|
||||
build: () => SignUpCubit(
|
||||
authenticationRepository: authenticationRepository,
|
||||
authenticationCubit: authenticationCubit,
|
||||
entries: const FormData.empty(),
|
||||
formData: const FormData.empty(),
|
||||
),
|
||||
seed: () => const SignUpState(
|
||||
password: validPassword,
|
||||
data: FormData.empty(),
|
||||
),
|
||||
act: (SignUpCubit cubit) => cubit.emailChanged(validEmailString),
|
||||
act: (cubit) => cubit.emailChanged(validEmailString),
|
||||
expect: () => <SignUpState>[
|
||||
const SignUpState(
|
||||
email: validEmail,
|
||||
@@ -120,11 +116,9 @@ void main() {
|
||||
'emits [invalid] when email/password are invalid',
|
||||
build: () => SignUpCubit(
|
||||
authenticationRepository: authenticationRepository,
|
||||
authenticationCubit: authenticationCubit,
|
||||
entries: const FormData.empty(),
|
||||
formData: const FormData.empty(),
|
||||
),
|
||||
act: (SignUpCubit cubit) =>
|
||||
cubit.passwordChanged(invalidPasswordString),
|
||||
act: (cubit) => cubit.passwordChanged(invalidPasswordString),
|
||||
expect: () => <SignUpState>[
|
||||
const SignUpState(
|
||||
password: invalidPassword,
|
||||
@@ -138,14 +132,13 @@ void main() {
|
||||
'emits [valid] when email/password are valid',
|
||||
build: () => SignUpCubit(
|
||||
authenticationRepository: authenticationRepository,
|
||||
authenticationCubit: authenticationCubit,
|
||||
entries: const FormData.empty(),
|
||||
formData: const FormData.empty(),
|
||||
),
|
||||
seed: () => const SignUpState(
|
||||
email: validEmail,
|
||||
data: FormData.empty(),
|
||||
),
|
||||
act: (SignUpCubit cubit) => cubit.passwordChanged(validPasswordString),
|
||||
act: (cubit) => cubit.passwordChanged(validPasswordString),
|
||||
expect: () => <SignUpState>[
|
||||
const SignUpState(
|
||||
email: validEmail,
|
||||
@@ -162,10 +155,9 @@ void main() {
|
||||
'does nothing when status is not validated',
|
||||
build: () => SignUpCubit(
|
||||
authenticationRepository: authenticationRepository,
|
||||
authenticationCubit: authenticationCubit,
|
||||
entries: const FormData.empty(),
|
||||
formData: const FormData.empty(),
|
||||
),
|
||||
act: (SignUpCubit cubit) => cubit.signUpFormSubmitted(),
|
||||
act: (cubit) => cubit.signUpFormSubmitted(),
|
||||
expect: () => const <SignUpState>[],
|
||||
);
|
||||
|
||||
@@ -173,8 +165,7 @@ void main() {
|
||||
'calls signUp with correct email/password/confirmedPassword',
|
||||
build: () => SignUpCubit(
|
||||
authenticationRepository: authenticationRepository,
|
||||
authenticationCubit: authenticationCubit,
|
||||
entries: const FormData.empty(),
|
||||
formData: const FormData.empty(),
|
||||
),
|
||||
seed: () => const SignUpState(
|
||||
status: FormStatus.valid,
|
||||
@@ -182,7 +173,7 @@ void main() {
|
||||
password: validPassword,
|
||||
data: FormData.empty(),
|
||||
),
|
||||
act: (SignUpCubit cubit) => cubit.signUpFormSubmitted(),
|
||||
act: (cubit) => cubit.signUpFormSubmitted(),
|
||||
verify: (_) {
|
||||
verify(
|
||||
() => authenticationRepository.signUp(
|
||||
@@ -198,8 +189,7 @@ void main() {
|
||||
'when signUp succeeds',
|
||||
build: () => SignUpCubit(
|
||||
authenticationRepository: authenticationRepository,
|
||||
authenticationCubit: authenticationCubit,
|
||||
entries: const FormData.empty(),
|
||||
formData: const FormData.empty(),
|
||||
),
|
||||
seed: () => const SignUpState(
|
||||
status: FormStatus.valid,
|
||||
@@ -207,7 +197,7 @@ void main() {
|
||||
password: validPassword,
|
||||
data: FormData.empty(),
|
||||
),
|
||||
act: (SignUpCubit cubit) => cubit.signUpFormSubmitted(),
|
||||
act: (cubit) => cubit.signUpFormSubmitted(),
|
||||
expect: () => <SignUpState>[
|
||||
const SignUpState(
|
||||
status: FormStatus.submissionInProgress,
|
||||
@@ -237,8 +227,7 @@ void main() {
|
||||
},
|
||||
build: () => SignUpCubit(
|
||||
authenticationRepository: authenticationRepository,
|
||||
authenticationCubit: authenticationCubit,
|
||||
entries: const FormData.empty(),
|
||||
formData: const FormData.empty(),
|
||||
),
|
||||
seed: () => const SignUpState(
|
||||
status: FormStatus.valid,
|
||||
@@ -246,7 +235,7 @@ void main() {
|
||||
password: validPassword,
|
||||
data: FormData.empty(),
|
||||
),
|
||||
act: (SignUpCubit cubit) => cubit.signUpFormSubmitted(),
|
||||
act: (cubit) => cubit.signUpFormSubmitted(),
|
||||
expect: () => <SignUpState>[
|
||||
const SignUpState(
|
||||
status: FormStatus.submissionInProgress,
|
||||
|
||||
Reference in New Issue
Block a user