Skip to content

test: Use random email in eg.user #940

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 16, 2024
Merged
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
10 changes: 9 additions & 1 deletion test/example_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,21 @@ GetServerSettingsResult serverSettings({
int _nextUserId() => (_lastUserId += 1 + Random().nextInt(100));
int _lastUserId = 1000;

/// A random email address, different from previously generated ones.
String _nextEmail() => 'mail${_lastEmailSuffix += Random().nextInt(1000)}@example.com';
int _lastEmailSuffix = 1000;

/// Construct an example user.
///
/// If user ID `userId` is not given, it will be generated from a random
/// but increasing sequence.
/// Use an explicit `userId` only if the ID needs to correspond to some
/// other data in the test, or if the IDs need to increase in a different order
/// from the calls to [user].
///
/// If `deliveryEmail` is not given, it will be generated from a
/// random sequence of distinct strings.
/// If `email` is not given, it will be set to `deliveryEmail`.
User user({
int? userId,
String? deliveryEmail,
Expand All @@ -87,7 +95,7 @@ User user({
String? avatarUrl,
Map<int, ProfileFieldUserData>? profileData,
}) {
var effectiveDeliveryEmail = deliveryEmail ?? '[email protected]'; // TODO generate example emails
var effectiveDeliveryEmail = deliveryEmail ?? _nextEmail();
_checkPositive(userId, 'user ID');
return User(
userId: userId ?? _nextUserId(),
Expand Down