test(authentication): update tests

This commit is contained in:
2023-04-13 23:24:11 +02:00
parent 0c876e829e
commit 8ed9e86db2
6 changed files with 255 additions and 124 deletions
@@ -39,15 +39,21 @@ void main() {
setUp(() {
authenticationRepository = MockAuthenticationRepository();
when(
() => authenticationRepository.getAccount(),
).thenAnswer((_) async => Ok(account));
account = MockAccount();
when(() => authenticationRepository.sessionStream()).thenAnswer(
(_) => Stream.fromIterable([
SessionWrapper<int>(
event: SignedInFromCacheEvent(account: account),
session: Session<int>(account: account, data: 10),
)
]),
);
when(
() => authenticationRepository.refresh(),
).thenAnswer((_) async => const Ok(null));
).thenAnswer((_) async => Ok(account));
account = MockAccount();
when(
() => account.emailVerified,
).thenAnswer((_) => true);
@@ -129,7 +135,7 @@ void main() {
setUp: () {
when(
() => authenticationRepository.refresh(),
).thenAnswer((_) async => const Ok(null));
).thenAnswer((_) async => Ok(account));
},
build: () => EmailVerificationCubit(
authenticationRepository: authenticationRepository,
@@ -145,7 +151,7 @@ void main() {
setUp: () {
when(
() => authenticationRepository.refresh(),
).thenAnswer((_) async => const Ok(null));
).thenAnswer((_) async => Ok(account));
when(() => account.emailVerified).thenAnswer((_) => false);
},
build: () => EmailVerificationCubit(
@@ -161,7 +167,7 @@ void main() {
'emits success with true if verified',
setUp: () {
when(() => authenticationRepository.refresh())
.thenAnswer((_) async => const Ok(null));
.thenAnswer((_) async => Ok(account));
},
build: () => EmailVerificationCubit(
authenticationRepository: authenticationRepository,
@@ -183,7 +189,7 @@ void main() {
'emits success with false if not verified',
setUp: () {
when(() => authenticationRepository.refresh())
.thenAnswer((_) async => const Ok(null));
.thenAnswer((_) async => Ok(account));
when(() => account.emailVerified).thenAnswer((_) => false);
},
build: () => EmailVerificationCubit(
@@ -222,28 +228,6 @@ void main() {
)
],
);
blocTest<EmailVerificationCubit<int>, EmailVerificationState>(
'emits failure on get account error',
setUp: () {
when(() => authenticationRepository.getAccount())
.thenAnswer((_) async => Err(ServerException('erreur')));
},
build: () => EmailVerificationCubit(
authenticationRepository: authenticationRepository,
),
seed: () => const EmailVerificationState(),
act: (cubit) => cubit.checkEmailVerification(),
expect: () => [
const EmailVerificationState(
status: FormStatus.submissionInProgress,
),
const EmailVerificationState(
errorMessage: 'erreur',
status: FormStatus.submissionFailure,
)
],
);
});
});
}