fix(auth)!: add signInWithEmailAndPassword and signInAnonymously methods in SignInCubit #26
This commit is contained in:
@@ -65,6 +65,10 @@ void main() {
|
||||
),
|
||||
).thenAnswer((_) async => Ok(account));
|
||||
|
||||
when(
|
||||
() => authenticationRepository.signInAnonymously(),
|
||||
).thenAnswer((_) async => Ok(account));
|
||||
|
||||
when(
|
||||
() => authenticationRepository.formRepository,
|
||||
).thenAnswer((_) => formRepository);
|
||||
@@ -258,13 +262,38 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
group('submit', () {
|
||||
group('signInWithEmailAndPassword()', () {
|
||||
blocTest<SignInCubit<int>, SignInState>(
|
||||
'does nothing when status is not validated',
|
||||
build: () => SignInCubit(
|
||||
authenticationRepository: authenticationRepository,
|
||||
),
|
||||
act: (cubit) => cubit.submit(),
|
||||
act: (cubit) => cubit.signInWithEmailAndPassword(),
|
||||
expect: () => const <SignInState>[],
|
||||
);
|
||||
|
||||
blocTest<SignInCubit<int>, SignInState>(
|
||||
'does nothing when status is submitInProgress',
|
||||
build: () => SignInCubit(
|
||||
authenticationRepository: authenticationRepository,
|
||||
),
|
||||
seed: () => SignInState(
|
||||
form: WyattFormImpl(
|
||||
[
|
||||
FormInput(
|
||||
AuthFormField.email,
|
||||
const Email.dirty(validEmailString),
|
||||
),
|
||||
FormInput(
|
||||
AuthFormField.password,
|
||||
const Password.dirty(validPasswordString),
|
||||
)
|
||||
],
|
||||
name: AuthFormName.signInForm,
|
||||
),
|
||||
status: FormStatus.submissionInProgress,
|
||||
),
|
||||
act: (cubit) => cubit.signInWithEmailAndPassword(),
|
||||
expect: () => const <SignInState>[],
|
||||
);
|
||||
|
||||
@@ -308,7 +337,7 @@ void main() {
|
||||
),
|
||||
status: FormStatus.valid,
|
||||
),
|
||||
act: (cubit) => cubit.submit(),
|
||||
act: (cubit) => cubit.signInWithEmailAndPassword(),
|
||||
verify: (_) {
|
||||
verify(
|
||||
() => authenticationRepository.signInWithEmailAndPassword(
|
||||
@@ -360,7 +389,7 @@ void main() {
|
||||
),
|
||||
status: FormStatus.valid,
|
||||
),
|
||||
act: (cubit) => cubit.submit(),
|
||||
act: (cubit) => cubit.signInWithEmailAndPassword(),
|
||||
expect: () => <SignInState>[
|
||||
SignInState(
|
||||
form: WyattFormImpl(
|
||||
@@ -444,7 +473,170 @@ void main() {
|
||||
),
|
||||
status: FormStatus.valid,
|
||||
),
|
||||
act: (cubit) => cubit.submit(),
|
||||
act: (cubit) => cubit.signInWithEmailAndPassword(),
|
||||
expect: () => <SignInState>[
|
||||
SignInState(
|
||||
form: WyattFormImpl(
|
||||
[
|
||||
FormInput(
|
||||
AuthFormField.email,
|
||||
const Email.dirty(validEmailString),
|
||||
),
|
||||
FormInput(
|
||||
AuthFormField.password,
|
||||
const Password.dirty(validPasswordString),
|
||||
)
|
||||
],
|
||||
name: AuthFormName.signInForm,
|
||||
),
|
||||
status: FormStatus.submissionInProgress,
|
||||
),
|
||||
SignInState(
|
||||
form: WyattFormImpl(
|
||||
[
|
||||
FormInput(
|
||||
AuthFormField.email,
|
||||
const Email.dirty(validEmailString),
|
||||
),
|
||||
FormInput(
|
||||
AuthFormField.password,
|
||||
const Password.dirty(validPasswordString),
|
||||
)
|
||||
],
|
||||
name: AuthFormName.signInForm,
|
||||
),
|
||||
status: FormStatus.submissionFailure,
|
||||
)
|
||||
],
|
||||
);
|
||||
});
|
||||
|
||||
group('signInAnonymously()', () {
|
||||
blocTest<SignInCubit<int>, SignInState>(
|
||||
'does nothing when status is submitInProgress',
|
||||
build: () => SignInCubit(
|
||||
authenticationRepository: authenticationRepository,
|
||||
),
|
||||
seed: () => SignInState(
|
||||
form: WyattFormImpl(
|
||||
[
|
||||
FormInput(
|
||||
AuthFormField.email,
|
||||
const Email.dirty(validEmailString),
|
||||
),
|
||||
FormInput(
|
||||
AuthFormField.password,
|
||||
const Password.dirty(validPasswordString),
|
||||
)
|
||||
],
|
||||
name: AuthFormName.signInForm,
|
||||
),
|
||||
status: FormStatus.submissionInProgress,
|
||||
),
|
||||
act: (cubit) => cubit.signInAnonymously(),
|
||||
expect: () => const <SignInState>[],
|
||||
);
|
||||
|
||||
blocTest<SignInCubit<int>, SignInState>(
|
||||
'calls signInAnonymously',
|
||||
build: () => SignInCubit(
|
||||
authenticationRepository: authenticationRepository,
|
||||
),
|
||||
act: (cubit) => cubit.signInAnonymously(),
|
||||
verify: (_) {
|
||||
verify(
|
||||
() => authenticationRepository.signInAnonymously(),
|
||||
).called(1);
|
||||
},
|
||||
);
|
||||
|
||||
blocTest<SignInCubit<int>, SignInState>(
|
||||
'emits [submissionInProgress, submissionSuccess] '
|
||||
'when signInAnonymously succeeds',
|
||||
build: () => SignInCubit(
|
||||
authenticationRepository: authenticationRepository,
|
||||
),
|
||||
seed: () => SignInState(
|
||||
form: WyattFormImpl(
|
||||
[
|
||||
FormInput(
|
||||
AuthFormField.email,
|
||||
const Email.dirty(validEmailString),
|
||||
),
|
||||
FormInput(
|
||||
AuthFormField.password,
|
||||
const Password.dirty(validPasswordString),
|
||||
)
|
||||
],
|
||||
name: AuthFormName.signInForm,
|
||||
),
|
||||
status: FormStatus.valid,
|
||||
),
|
||||
act: (cubit) => cubit.signInAnonymously(),
|
||||
expect: () => <SignInState>[
|
||||
SignInState(
|
||||
form: WyattFormImpl(
|
||||
[
|
||||
FormInput(
|
||||
AuthFormField.email,
|
||||
const Email.dirty(validEmailString),
|
||||
),
|
||||
FormInput(
|
||||
AuthFormField.password,
|
||||
const Password.dirty(validPasswordString),
|
||||
)
|
||||
],
|
||||
name: AuthFormName.signInForm,
|
||||
),
|
||||
status: FormStatus.submissionInProgress,
|
||||
),
|
||||
SignInState(
|
||||
form: WyattFormImpl(
|
||||
[
|
||||
FormInput(
|
||||
AuthFormField.email,
|
||||
const Email.dirty(validEmailString),
|
||||
),
|
||||
FormInput(
|
||||
AuthFormField.password,
|
||||
const Password.dirty(validPasswordString),
|
||||
)
|
||||
],
|
||||
name: AuthFormName.signInForm,
|
||||
),
|
||||
status: FormStatus.submissionSuccess,
|
||||
)
|
||||
],
|
||||
);
|
||||
|
||||
blocTest<SignInCubit<int>, SignInState>(
|
||||
'emits [submissionInProgress, submissionFailure] '
|
||||
'when signInAnonymously fails',
|
||||
setUp: () {
|
||||
when(
|
||||
() => authenticationRepository.signInAnonymously(),
|
||||
).thenAnswer((_) async => Err(ServerException()));
|
||||
},
|
||||
build: () => SignInCubit(
|
||||
authenticationRepository: authenticationRepository,
|
||||
),
|
||||
seed: () => SignInState(
|
||||
form: WyattFormImpl(
|
||||
[
|
||||
FormInput(
|
||||
AuthFormField.email,
|
||||
const Email.dirty(validEmailString),
|
||||
),
|
||||
FormInput(
|
||||
AuthFormField.password,
|
||||
const Password.dirty(validPasswordString),
|
||||
)
|
||||
],
|
||||
name: AuthFormName.signInForm,
|
||||
),
|
||||
status: FormStatus.valid,
|
||||
),
|
||||
act: (cubit) => cubit.signInAnonymously(),
|
||||
expect: () => <SignInState>[
|
||||
SignInState(
|
||||
form: WyattFormImpl(
|
||||
|
||||
Reference in New Issue
Block a user