55 lines
1.6 KiB
Dart
55 lines
1.6 KiB
Dart
import '../dto/results.dart';
|
|
import '../mappers/results.dart';
|
|
import '../models/verification.dart';
|
|
|
|
abstract interface class SimulationInfo {
|
|
bool get isSimulated;
|
|
}
|
|
|
|
abstract interface class VerificationService {
|
|
Future<VerificationResult> send({
|
|
required String email,
|
|
required String locale,
|
|
});
|
|
Future<VerificationResult> confirm({required String token});
|
|
}
|
|
|
|
/// Explicit preview tokens only. Never use this implementation in production.
|
|
class DummyVerificationService implements VerificationService, SimulationInfo {
|
|
const DummyVerificationService({
|
|
this.delay = const Duration(milliseconds: 600),
|
|
this.sendFailure,
|
|
});
|
|
@override
|
|
bool get isSimulated => true;
|
|
final Duration delay;
|
|
final VerificationError? sendFailure;
|
|
|
|
@override
|
|
Future<VerificationResult> send({
|
|
required String email,
|
|
required String locale,
|
|
}) async {
|
|
await Future<void>.delayed(delay);
|
|
if (sendFailure case final error?) throw VerificationException(error);
|
|
return VerificationMapper.fromDTO(const VerificationDTO(simulated: true));
|
|
}
|
|
|
|
@override
|
|
Future<VerificationResult> confirm({required String token}) async {
|
|
await Future<void>.delayed(delay);
|
|
switch (token) {
|
|
case 'demo-valid':
|
|
return VerificationMapper.fromDTO(
|
|
const VerificationDTO(simulated: true),
|
|
);
|
|
case 'demo-expired':
|
|
throw const VerificationException(VerificationError.expired);
|
|
case 'demo-internal':
|
|
throw const VerificationException(VerificationError.internal);
|
|
default:
|
|
throw const VerificationException(VerificationError.invalid);
|
|
}
|
|
}
|
|
}
|