forked from eatvio/eatvio_app
67 lines
2.2 KiB
Dart
67 lines
2.2 KiB
Dart
import 'package:eatvio_app/features/auth/models/credentials_model.dart';
|
|
import 'package:eatvio_app/features/auth/models/oauth_login_request.dart';
|
|
import 'package:eatvio_app/features/auth/models/oauth_model.dart';
|
|
import 'package:eatvio_app/features/auth/models/token_model.dart';
|
|
import 'package:eatvio_app/features/auth/repositories/auth_repository.dart';
|
|
import 'package:eatvio_app/features/auth/services/auth_service.dart';
|
|
/// Fixture-based replacement for [AuthRepository].
|
|
///
|
|
/// - Records every credential payload that would be sent to the backend.
|
|
/// - Returns data loaded from fixture files so QA/backenders can see
|
|
/// exactly what is exchanged.
|
|
class FixtureAuthRepository extends AuthRepository {
|
|
FixtureAuthRepository({
|
|
required this.tokenFixture,
|
|
}) : super(authService: _NoopAuthService());
|
|
|
|
final TokenModel tokenFixture;
|
|
|
|
final List<CredentialsCall> credentialCalls = <CredentialsCall>[];
|
|
List<Map<String, String>> get credentialPayloads => credentialCalls.map((call) => call.toJson()).toList(growable: false);
|
|
|
|
Duration responseDelay = Duration.zero;
|
|
Object? error;
|
|
|
|
@override
|
|
Future<TokenModel> getTokenByCredentials(String email, String password) async {
|
|
credentialCalls.add(CredentialsCall(email: email, password: password));
|
|
if (responseDelay > Duration.zero) {
|
|
await Future.delayed(responseDelay);
|
|
}
|
|
if (error != null) {
|
|
throw error!;
|
|
}
|
|
return tokenFixture;
|
|
}
|
|
}
|
|
|
|
class CredentialsCall {
|
|
const CredentialsCall({required this.email, required this.password});
|
|
|
|
final String email;
|
|
final String password;
|
|
|
|
Map<String, String> toJson() => <String, String>{
|
|
'email': email,
|
|
'password': password,
|
|
};
|
|
}
|
|
|
|
class _NoopAuthService implements AuthService {
|
|
@override
|
|
Future<TokenModel> getTokenByCredentials({required CredentialsModel credentials}) {
|
|
throw UnimplementedError('Use FixtureAuthRepository override instead.');
|
|
}
|
|
|
|
@override
|
|
Future<TokenModel> signInViaSocialMedia({required OAuthLoginRequest body}) {
|
|
throw UnimplementedError('Not implemented in fixture.');
|
|
}
|
|
|
|
@override
|
|
Future<Map<String, Object?>> signUpViaSocialMedia({required OAuthModel body}) {
|
|
throw UnimplementedError('Not implemented in fixture.');
|
|
}
|
|
}
|
|
|