fix(authentication)!: use correct usecase and result
This commit is contained in:
parent
283bf80243
commit
cca7b29a6d
@ -27,34 +27,34 @@ class ExampleAuthenticationCubit extends AuthenticationCubit<int> {
|
|||||||
Result<Account, AppException> result) async {
|
Result<Account, AppException> result) async {
|
||||||
debugPrint('onReauthenticate');
|
debugPrint('onReauthenticate');
|
||||||
|
|
||||||
return const Ok(1);
|
return Ok(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
FutureOrResult<int?> onRefresh(Result<Account, AppException> result) {
|
FutureOrResult<int?> onRefresh(Result<Account, AppException> result) {
|
||||||
debugPrint('onRefresh');
|
debugPrint('onRefresh');
|
||||||
|
|
||||||
return const Ok(1);
|
return Ok(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
FutureOrResult<int?> onSignInFromCache(AuthenticationSession<int> session) {
|
FutureOrResult<int?> onSignInFromCache(AuthenticationSession<int> session) {
|
||||||
debugPrint('onSignInFromCache');
|
debugPrint('onSignInFromCache');
|
||||||
|
|
||||||
return const Ok(1);
|
return Ok(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
FutureOrResult<void> onSignOut() {
|
FutureOrResult<void> onSignOut() {
|
||||||
debugPrint('onSignOut');
|
debugPrint('onSignOut');
|
||||||
|
|
||||||
return const Ok(null);
|
return Ok(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
FutureOrResult<void> onDelete() {
|
FutureOrResult<void> onDelete() {
|
||||||
debugPrint('onDelete');
|
debugPrint('onDelete');
|
||||||
|
|
||||||
return const Ok(null);
|
return Ok(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ class ExampleSignInCubit extends SignInCubit<int> {
|
|||||||
Result<Account, AppException> result, WyattForm form) {
|
Result<Account, AppException> result, WyattForm form) {
|
||||||
debugPrint('onSignInWithEmailAndPassword: ${result.ok?.accessToken}');
|
debugPrint('onSignInWithEmailAndPassword: ${result.ok?.accessToken}');
|
||||||
|
|
||||||
return const Ok(1);
|
return Ok(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -38,7 +38,7 @@ class ExampleSignInCubit extends SignInCubit<int> {
|
|||||||
Result<Account, AppException> result, WyattForm form) {
|
Result<Account, AppException> result, WyattForm form) {
|
||||||
debugPrint('onSignInAnonymously');
|
debugPrint('onSignInAnonymously');
|
||||||
|
|
||||||
return const Ok(1);
|
return Ok(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -46,6 +46,6 @@ class ExampleSignInCubit extends SignInCubit<int> {
|
|||||||
Result<Account, AppException> result, WyattForm form) {
|
Result<Account, AppException> result, WyattForm form) {
|
||||||
debugPrint('onSignInWithGoogle');
|
debugPrint('onSignInWithGoogle');
|
||||||
|
|
||||||
return const Ok(1);
|
return Ok(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,6 @@ class ExampleSignUpCubit extends SignUpCubit<int> {
|
|||||||
Result<Account, AppException> result, WyattForm form) async {
|
Result<Account, AppException> result, WyattForm form) async {
|
||||||
debugPrint('onSignUpWithEmailAndPassword');
|
debugPrint('onSignUpWithEmailAndPassword');
|
||||||
|
|
||||||
return const Ok(1);
|
return Ok(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ class ExampleEditAccountCubit extends EditAccountCubit<int> {
|
|||||||
Result<Account, AppException> result, WyattForm form) async {
|
Result<Account, AppException> result, WyattForm form) async {
|
||||||
debugPrint('onEmailUpdated');
|
debugPrint('onEmailUpdated');
|
||||||
|
|
||||||
return const Ok(1);
|
return Ok(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -36,6 +36,6 @@ class ExampleEditAccountCubit extends EditAccountCubit<int> {
|
|||||||
Result<Account, AppException> result, WyattForm form) async {
|
Result<Account, AppException> result, WyattForm form) async {
|
||||||
debugPrint('onPasswordUpdated');
|
debugPrint('onPasswordUpdated');
|
||||||
|
|
||||||
return const Ok(1);
|
return Ok(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ import 'package:wyatt_authentication_bloc/src/domain/entities/account.dart';
|
|||||||
/// {@template authentication_cache_data_source}
|
/// {@template authentication_cache_data_source}
|
||||||
/// A data source that manages the cache strategy.
|
/// A data source that manages the cache strategy.
|
||||||
/// {@endtemplate}
|
/// {@endtemplate}
|
||||||
abstract class AuthenticationCacheDataSource<Data> extends BaseLocalDataSource {
|
abstract class AuthenticationCacheDataSource<Data> extends BaseDataSource {
|
||||||
/// {@macro authentication_cache_data_source}
|
/// {@macro authentication_cache_data_source}
|
||||||
const AuthenticationCacheDataSource();
|
const AuthenticationCacheDataSource();
|
||||||
|
|
||||||
|
@ -20,8 +20,7 @@ import 'package:wyatt_authentication_bloc/wyatt_authentication_bloc.dart';
|
|||||||
/// {@template authentication_session_data_source}
|
/// {@template authentication_session_data_source}
|
||||||
/// A data source that manages the current session.
|
/// A data source that manages the current session.
|
||||||
/// {@endtemplate}
|
/// {@endtemplate}
|
||||||
abstract class AuthenticationSessionDataSource<Data>
|
abstract class AuthenticationSessionDataSource<Data> extends BaseDataSource {
|
||||||
extends BaseLocalDataSource {
|
|
||||||
/// {@macro authentication_session_data_source}
|
/// {@macro authentication_session_data_source}
|
||||||
const AuthenticationSessionDataSource();
|
const AuthenticationSessionDataSource();
|
||||||
|
|
||||||
|
@ -22,8 +22,7 @@ import 'package:wyatt_authentication_bloc/src/domain/entities/account.dart';
|
|||||||
/// It is responsible for all the external communication with the authentication
|
/// It is responsible for all the external communication with the authentication
|
||||||
/// providers.
|
/// providers.
|
||||||
/// {@endtemplate}
|
/// {@endtemplate}
|
||||||
abstract class AuthenticationRemoteDataSource<Data>
|
abstract class AuthenticationRemoteDataSource<Data> extends BaseDataSource {
|
||||||
extends BaseRemoteDataSource {
|
|
||||||
/// {@macro authentication_remote_data_source}
|
/// {@macro authentication_remote_data_source}
|
||||||
const AuthenticationRemoteDataSource();
|
const AuthenticationRemoteDataSource();
|
||||||
|
|
||||||
|
@ -43,12 +43,12 @@ class EditAccountCubit<Data> extends BaseEditAccountCubit<Data>
|
|||||||
Result<Account, AppException> result,
|
Result<Account, AppException> result,
|
||||||
WyattForm form,
|
WyattForm form,
|
||||||
) =>
|
) =>
|
||||||
const Ok(null);
|
Ok(null);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
FutureOrResult<Data?> onPasswordUpdated(
|
FutureOrResult<Data?> onPasswordUpdated(
|
||||||
Result<Account, AppException> result,
|
Result<Account, AppException> result,
|
||||||
WyattForm form,
|
WyattForm form,
|
||||||
) =>
|
) =>
|
||||||
const Ok(null);
|
Ok(null);
|
||||||
}
|
}
|
||||||
|
@ -48,19 +48,19 @@ class SignInCubit<Data> extends BaseSignInCubit<Data>
|
|||||||
Result<Account, AppException> result,
|
Result<Account, AppException> result,
|
||||||
WyattForm form,
|
WyattForm form,
|
||||||
) =>
|
) =>
|
||||||
const Ok(null);
|
Ok(null);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
FutureOrResult<Data?> onSignInWithEmailAndPassword(
|
FutureOrResult<Data?> onSignInWithEmailAndPassword(
|
||||||
Result<Account, AppException> result,
|
Result<Account, AppException> result,
|
||||||
WyattForm form,
|
WyattForm form,
|
||||||
) =>
|
) =>
|
||||||
const Ok(null);
|
Ok(null);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
FutureOrResult<Data?> onSignInWithGoogle(
|
FutureOrResult<Data?> onSignInWithGoogle(
|
||||||
Result<Account, AppException> result,
|
Result<Account, AppException> result,
|
||||||
WyattForm form,
|
WyattForm form,
|
||||||
) =>
|
) =>
|
||||||
const Ok(null);
|
Ok(null);
|
||||||
}
|
}
|
||||||
|
@ -43,5 +43,5 @@ class SignUpCubit<Data> extends BaseSignUpCubit<Data>
|
|||||||
Result<Account, AppException> result,
|
Result<Account, AppException> result,
|
||||||
WyattForm form,
|
WyattForm form,
|
||||||
) =>
|
) =>
|
||||||
const Ok(null);
|
Ok(null);
|
||||||
}
|
}
|
||||||
|
@ -30,26 +30,26 @@ class TestAuthenticationCubit extends AuthenticationCubit<int> {
|
|||||||
TestAuthenticationCubit({required super.authenticationRepository});
|
TestAuthenticationCubit({required super.authenticationRepository});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
FutureOrResult<void> onDelete() async => const Ok(null);
|
FutureOrResult<void> onDelete() async => Ok(null);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
FutureOrResult<int?> onReauthenticate(
|
FutureOrResult<int?> onReauthenticate(
|
||||||
Result<Account, AppException> result,
|
Result<Account, AppException> result,
|
||||||
) async =>
|
) async =>
|
||||||
const Ok(null);
|
Ok(null);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
FutureOrResult<int?> onRefresh(Result<Account, AppException> result) async =>
|
FutureOrResult<int?> onRefresh(Result<Account, AppException> result) async =>
|
||||||
const Ok(null);
|
Ok(null);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
FutureOrResult<int?> onSignInFromCache(
|
FutureOrResult<int?> onSignInFromCache(
|
||||||
AuthenticationSession<int> session,
|
AuthenticationSession<int> session,
|
||||||
) async =>
|
) async =>
|
||||||
const Ok(null);
|
Ok(null);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
FutureOrResult<void> onSignOut() async => const Ok(null);
|
FutureOrResult<void> onSignOut() async => Ok(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
@ -92,7 +92,7 @@ void main() {
|
|||||||
build: () => TestAuthenticationCubit(
|
build: () => TestAuthenticationCubit(
|
||||||
authenticationRepository: authenticationRepository,
|
authenticationRepository: authenticationRepository,
|
||||||
),
|
),
|
||||||
seed: () => const AuthenticationState.unknown(),
|
seed: AuthenticationState.unknown,
|
||||||
expect: () => [AuthenticationState<int>.authenticated(session)],
|
expect: () => [AuthenticationState<int>.authenticated(session)],
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -108,7 +108,7 @@ void main() {
|
|||||||
build: () => TestAuthenticationCubit(
|
build: () => TestAuthenticationCubit(
|
||||||
authenticationRepository: authenticationRepository,
|
authenticationRepository: authenticationRepository,
|
||||||
),
|
),
|
||||||
seed: () => const AuthenticationState.unknown(),
|
seed: AuthenticationState.unknown,
|
||||||
expect: () => [const AuthenticationState<int>.unauthenticated()],
|
expect: () => [const AuthenticationState<int>.unauthenticated()],
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -119,7 +119,7 @@ void main() {
|
|||||||
setUp: () {
|
setUp: () {
|
||||||
when(
|
when(
|
||||||
() => authenticationRepository.signOut(),
|
() => authenticationRepository.signOut(),
|
||||||
).thenAnswer((_) async => const Ok(null));
|
).thenAnswer((_) async => Ok(null));
|
||||||
},
|
},
|
||||||
build: () => TestAuthenticationCubit(
|
build: () => TestAuthenticationCubit(
|
||||||
authenticationRepository: authenticationRepository,
|
authenticationRepository: authenticationRepository,
|
||||||
|
@ -84,7 +84,7 @@ void main() {
|
|||||||
'invokes sendEmailVerification,',
|
'invokes sendEmailVerification,',
|
||||||
setUp: () {
|
setUp: () {
|
||||||
when(() => authenticationRepository.sendEmailVerification())
|
when(() => authenticationRepository.sendEmailVerification())
|
||||||
.thenAnswer((_) async => const Ok(null));
|
.thenAnswer((_) async => Ok(null));
|
||||||
},
|
},
|
||||||
build: () => EmailVerificationCubit(
|
build: () => EmailVerificationCubit(
|
||||||
authenticationRepository: authenticationRepository,
|
authenticationRepository: authenticationRepository,
|
||||||
@ -100,12 +100,12 @@ void main() {
|
|||||||
'emits success',
|
'emits success',
|
||||||
setUp: () {
|
setUp: () {
|
||||||
when(() => authenticationRepository.sendEmailVerification())
|
when(() => authenticationRepository.sendEmailVerification())
|
||||||
.thenAnswer((_) async => const Ok(null));
|
.thenAnswer((_) async => Ok(null));
|
||||||
},
|
},
|
||||||
build: () => EmailVerificationCubit(
|
build: () => EmailVerificationCubit(
|
||||||
authenticationRepository: authenticationRepository,
|
authenticationRepository: authenticationRepository,
|
||||||
),
|
),
|
||||||
seed: () => const EmailVerificationState(),
|
seed: EmailVerificationState.new,
|
||||||
act: (cubit) => cubit.sendEmailVerification(),
|
act: (cubit) => cubit.sendEmailVerification(),
|
||||||
expect: () => [
|
expect: () => [
|
||||||
const EmailVerificationState(
|
const EmailVerificationState(
|
||||||
@ -121,12 +121,12 @@ void main() {
|
|||||||
'emits failure',
|
'emits failure',
|
||||||
setUp: () {
|
setUp: () {
|
||||||
when(() => authenticationRepository.sendEmailVerification())
|
when(() => authenticationRepository.sendEmailVerification())
|
||||||
.thenAnswer((_) async => const Err(ServerException('erreur')));
|
.thenAnswer((_) async => Err(const ServerException('erreur')));
|
||||||
},
|
},
|
||||||
build: () => EmailVerificationCubit(
|
build: () => EmailVerificationCubit(
|
||||||
authenticationRepository: authenticationRepository,
|
authenticationRepository: authenticationRepository,
|
||||||
),
|
),
|
||||||
seed: () => const EmailVerificationState(),
|
seed: EmailVerificationState.new,
|
||||||
act: (cubit) => cubit.sendEmailVerification(),
|
act: (cubit) => cubit.sendEmailVerification(),
|
||||||
expect: () => [
|
expect: () => [
|
||||||
const EmailVerificationState(
|
const EmailVerificationState(
|
||||||
@ -183,7 +183,7 @@ void main() {
|
|||||||
build: () => EmailVerificationCubit(
|
build: () => EmailVerificationCubit(
|
||||||
authenticationRepository: authenticationRepository,
|
authenticationRepository: authenticationRepository,
|
||||||
),
|
),
|
||||||
seed: () => const EmailVerificationState(),
|
seed: EmailVerificationState.new,
|
||||||
act: (cubit) => cubit.checkEmailVerification(),
|
act: (cubit) => cubit.checkEmailVerification(),
|
||||||
expect: () => [
|
expect: () => [
|
||||||
const EmailVerificationState(
|
const EmailVerificationState(
|
||||||
@ -206,7 +206,7 @@ void main() {
|
|||||||
build: () => EmailVerificationCubit(
|
build: () => EmailVerificationCubit(
|
||||||
authenticationRepository: authenticationRepository,
|
authenticationRepository: authenticationRepository,
|
||||||
),
|
),
|
||||||
seed: () => const EmailVerificationState(),
|
seed: EmailVerificationState.new,
|
||||||
act: (cubit) => cubit.checkEmailVerification(),
|
act: (cubit) => cubit.checkEmailVerification(),
|
||||||
expect: () => [
|
expect: () => [
|
||||||
const EmailVerificationState(
|
const EmailVerificationState(
|
||||||
@ -222,12 +222,12 @@ void main() {
|
|||||||
'emits failure on refresh error',
|
'emits failure on refresh error',
|
||||||
setUp: () {
|
setUp: () {
|
||||||
when(() => authenticationRepository.refresh())
|
when(() => authenticationRepository.refresh())
|
||||||
.thenAnswer((_) async => const Err(ServerException('erreur')));
|
.thenAnswer((_) async => Err(const ServerException('erreur')));
|
||||||
},
|
},
|
||||||
build: () => EmailVerificationCubit(
|
build: () => EmailVerificationCubit(
|
||||||
authenticationRepository: authenticationRepository,
|
authenticationRepository: authenticationRepository,
|
||||||
),
|
),
|
||||||
seed: () => const EmailVerificationState(),
|
seed: EmailVerificationState.new,
|
||||||
act: (cubit) => cubit.checkEmailVerification(),
|
act: (cubit) => cubit.checkEmailVerification(),
|
||||||
expect: () => [
|
expect: () => [
|
||||||
const EmailVerificationState(
|
const EmailVerificationState(
|
||||||
|
@ -57,7 +57,7 @@ void main() {
|
|||||||
() => authenticationRepository.sendPasswordResetEmail(
|
() => authenticationRepository.sendPasswordResetEmail(
|
||||||
email: any(named: 'email'),
|
email: any(named: 'email'),
|
||||||
),
|
),
|
||||||
).thenAnswer((_) async => const Ok(null));
|
).thenAnswer((_) async => Ok(null));
|
||||||
|
|
||||||
when(
|
when(
|
||||||
() => authenticationRepository.formRepository,
|
() => authenticationRepository.formRepository,
|
||||||
@ -157,7 +157,7 @@ void main() {
|
|||||||
authenticationRepository: authenticationRepository,
|
authenticationRepository: authenticationRepository,
|
||||||
),
|
),
|
||||||
act: (cubit) => cubit.submit(),
|
act: (cubit) => cubit.submit(),
|
||||||
expect: () => const <PasswordResetState>[],
|
expect: () => <PasswordResetState>[],
|
||||||
);
|
);
|
||||||
|
|
||||||
blocTest<PasswordResetCubit<int>, PasswordResetState>(
|
blocTest<PasswordResetCubit<int>, PasswordResetState>(
|
||||||
@ -272,7 +272,7 @@ void main() {
|
|||||||
() => authenticationRepository.sendPasswordResetEmail(
|
() => authenticationRepository.sendPasswordResetEmail(
|
||||||
email: any(named: 'email'),
|
email: any(named: 'email'),
|
||||||
),
|
),
|
||||||
).thenAnswer((_) async => const Err(ServerException()));
|
).thenAnswer((_) async => Err(const ServerException()));
|
||||||
when(
|
when(
|
||||||
() => formRepository.accessForm(AuthFormName.passwordResetForm),
|
() => formRepository.accessForm(AuthFormName.passwordResetForm),
|
||||||
).thenAnswer(
|
).thenAnswer(
|
||||||
|
@ -435,7 +435,7 @@ void main() {
|
|||||||
email: any(named: 'email'),
|
email: any(named: 'email'),
|
||||||
password: any(named: 'password'),
|
password: any(named: 'password'),
|
||||||
),
|
),
|
||||||
).thenAnswer((_) async => const Err(ServerException()));
|
).thenAnswer((_) async => Err(const ServerException()));
|
||||||
when(
|
when(
|
||||||
() => formRepository.accessForm(AuthFormName.signInForm),
|
() => formRepository.accessForm(AuthFormName.signInForm),
|
||||||
).thenAnswer(
|
).thenAnswer(
|
||||||
@ -615,7 +615,7 @@ void main() {
|
|||||||
setUp: () {
|
setUp: () {
|
||||||
when(
|
when(
|
||||||
() => authenticationRepository.signInAnonymously(),
|
() => authenticationRepository.signInAnonymously(),
|
||||||
).thenAnswer((_) async => const Err(ServerException()));
|
).thenAnswer((_) async => Err(const ServerException()));
|
||||||
},
|
},
|
||||||
build: () => SignInCubit(
|
build: () => SignInCubit(
|
||||||
authenticationRepository: authenticationRepository,
|
authenticationRepository: authenticationRepository,
|
||||||
|
@ -406,7 +406,7 @@ void main() {
|
|||||||
email: any(named: 'email'),
|
email: any(named: 'email'),
|
||||||
password: any(named: 'password'),
|
password: any(named: 'password'),
|
||||||
),
|
),
|
||||||
).thenAnswer((_) async => const Err(ServerException()));
|
).thenAnswer((_) async => Err(const ServerException()));
|
||||||
when(
|
when(
|
||||||
() => formRepository.accessForm(AuthFormName.signUpForm),
|
() => formRepository.accessForm(AuthFormName.signUpForm),
|
||||||
).thenAnswer(
|
).thenAnswer(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user