Skip to content

Commit

Permalink
test: Make eg.user more realistic about email and delivery email
Browse files Browse the repository at this point in the history
This better reflects the fact that a User object will often have
null `deliveryEmail`, and that when that's the case it will have
a server-generated fake email address in `email`.
  • Loading branch information
gnprice committed Dec 9, 2024
1 parent b7abde3 commit be4196e
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions test/example_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,8 @@ int _lastEmailSuffix = 1000;
/// 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`.
/// If `email` is not given, it defaults to `deliveryEmail` if given,
/// or else to a value resembling the Zulip server's generated fake emails.
User user({
int? userId,
String? deliveryEmail,
Expand All @@ -121,12 +120,12 @@ User user({
String? avatarUrl,
Map<int, ProfileFieldUserData>? profileData,
}) {
var effectiveDeliveryEmail = deliveryEmail ?? _nextEmail();
_checkPositive(userId, 'user ID');
final effectiveUserId = userId ?? _nextUserId();
return User(
userId: userId ?? _nextUserId(),
deliveryEmail: effectiveDeliveryEmail,
email: email ?? effectiveDeliveryEmail,
userId: effectiveUserId,
deliveryEmail: deliveryEmail,
email: email ?? deliveryEmail ?? 'user$effectiveUserId@${realmUrl.host}',
fullName: fullName ?? 'A user', // TODO generate example names
dateJoined: dateJoined ?? '2024-02-24T11:18+00:00',
isActive: isActive ?? true,
Expand Down

0 comments on commit be4196e

Please sign in to comment.