File tree Expand file tree Collapse file tree 3 files changed +34
-0
lines changed
services/celest_cloud_auth/lib/src Expand file tree Collapse file tree 3 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -35,8 +35,35 @@ final class CelestTester {
3535
3636 final VmService _vmService;
3737
38+ /// Auth-related test helpers.
39+ late final CelestAuthTester auth = CelestAuthTester ._(_vmService);
40+
3841 /// Closes the connection to the VM service.
3942 Future <void > close () async {
4043 await _vmService.dispose ();
4144 }
4245}
46+
47+ /// An OTP code sent by the server.
48+ typedef Otp = ({String to, String code});
49+
50+ /// A helper class for running integration tests with Celest Auth.
51+ final class CelestAuthTester {
52+ CelestAuthTester ._(this ._vmService);
53+
54+ final VmService _vmService;
55+
56+ /// OTP codes sent to users during sign up/sign in.
57+ Stream <Otp > get onSentOtp async * {
58+ await for (final event in _vmService.onExtensionEvent) {
59+ if (event.extensionKind != 'celest.cloud_auth.emailOtpSent' ) {
60+ continue ;
61+ }
62+ final data = event.extensionData! .data;
63+ yield (
64+ to: data['to' ] as String ,
65+ code: data['code' ] as String ,
66+ );
67+ }
68+ }
69+ }
Original file line number Diff line number Diff line change 1+ import 'dart:developer' as developer;
2+
13import 'package:celest_cloud_auth/src/context.dart' ;
24import 'package:celest_cloud_auth/src/otp/otp_provider.dart' ;
35
@@ -7,6 +9,7 @@ extension type const EmailOtpProvider._(OtpSender _send) implements Object {
79 const EmailOtpProvider ([OtpSender send = _defaultSend]) : this ._(send);
810
911 static Future <void > _defaultSend (Otp message) async {
12+ developer.postEvent ('celest.cloud_auth.emailOtpSent' , message.toJson ());
1013 context.logger.info ('Verification code for ${message .to }: ${message .code }' );
1114 }
1215
Original file line number Diff line number Diff line change @@ -3,4 +3,8 @@ typedef Otp = ({
33 String code,
44});
55
6+ extension OtpX on Otp {
7+ Map <String , Object ?> toJson () => {'to' : to, 'code' : code};
8+ }
9+
610typedef OtpSender = Future <void > Function (Otp );
You can’t perform that action at this time.
0 commit comments