Skip to content

Commit be4196e

Browse files
committed
test: Make eg.user more realistic about email and delivery email
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`.
1 parent b7abde3 commit be4196e

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

test/example_data.dart

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,8 @@ int _lastEmailSuffix = 1000;
106106
/// other data in the test, or if the IDs need to increase in a different order
107107
/// from the calls to [user].
108108
///
109-
/// If `deliveryEmail` is not given, it will be generated from a
110-
/// random sequence of distinct strings.
111-
/// If `email` is not given, it will be set to `deliveryEmail`.
109+
/// If `email` is not given, it defaults to `deliveryEmail` if given,
110+
/// or else to a value resembling the Zulip server's generated fake emails.
112111
User user({
113112
int? userId,
114113
String? deliveryEmail,
@@ -121,12 +120,12 @@ User user({
121120
String? avatarUrl,
122121
Map<int, ProfileFieldUserData>? profileData,
123122
}) {
124-
var effectiveDeliveryEmail = deliveryEmail ?? _nextEmail();
125123
_checkPositive(userId, 'user ID');
124+
final effectiveUserId = userId ?? _nextUserId();
126125
return User(
127-
userId: userId ?? _nextUserId(),
128-
deliveryEmail: effectiveDeliveryEmail,
129-
email: email ?? effectiveDeliveryEmail,
126+
userId: effectiveUserId,
127+
deliveryEmail: deliveryEmail,
128+
email: email ?? deliveryEmail ?? 'user$effectiveUserId@${realmUrl.host}',
130129
fullName: fullName ?? 'A user', // TODO generate example names
131130
dateJoined: dateJoined ?? '2024-02-24T11:18+00:00',
132131
isActive: isActive ?? true,

0 commit comments

Comments
 (0)