Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions packages/celest_test/lib/celest_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,35 @@ final class CelestTester {

final VmService _vmService;

/// Auth-related test helpers.
late final CelestAuthTester auth = CelestAuthTester._(_vmService);

/// Closes the connection to the VM service.
Future<void> close() async {
await _vmService.dispose();
}
}

/// An OTP code sent by the server.
typedef Otp = ({String to, String code});

/// A helper class for running integration tests with Celest Auth.
final class CelestAuthTester {
CelestAuthTester._(this._vmService);

final VmService _vmService;

/// OTP codes sent to users during sign up/sign in.
Stream<Otp> get onSentOtp async* {
await for (final event in _vmService.onExtensionEvent) {
if (event.extensionKind != 'celest.cloud_auth.emailOtpSent') {
continue;
}
final data = event.extensionData!.data;
yield (
to: data['to'] as String,
code: data['code'] as String,
);
}
}
}
3 changes: 3 additions & 0 deletions services/celest_cloud_auth/lib/src/email/email_provider.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:developer' as developer;

import 'package:celest_cloud_auth/src/context.dart';
import 'package:celest_cloud_auth/src/otp/otp_provider.dart';

Expand All @@ -7,6 +9,7 @@ extension type const EmailOtpProvider._(OtpSender _send) implements Object {
const EmailOtpProvider([OtpSender send = _defaultSend]) : this._(send);

static Future<void> _defaultSend(Otp message) async {
developer.postEvent('celest.cloud_auth.emailOtpSent', message.toJson());
context.logger.info('Verification code for ${message.to}: ${message.code}');
}

Expand Down
4 changes: 4 additions & 0 deletions services/celest_cloud_auth/lib/src/otp/otp_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ typedef Otp = ({
String code,
});

extension OtpX on Otp {
Map<String, Object?> toJson() => {'to': to, 'code': code};
}

typedef OtpSender = Future<void> Function(Otp);