Skip to content

Commit 86b8c57

Browse files
gnpricechrisbobbe
authored andcommitted
test [nfc]: Make all user IDs positive
Zulip user IDs are positive integers. So avoiding zero here helps keep the test data realistic. This follows up on 739fa84 (in #828), which made a similar fix for one test case.
1 parent 0a9cf7f commit 86b8c57

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

test/example_data.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import 'package:zulip/model/store.dart';
1010
import 'model/test_store.dart';
1111
import 'stdlib_checks.dart';
1212

13+
void _checkPositive(int? value, String description) {
14+
assert(value == null || value > 0, '$description should be positive');
15+
}
16+
1317
////////////////////////////////////////////////////////////////
1418
// Realm-wide (or server-wide) metadata.
1519
//
@@ -81,6 +85,7 @@ User user({
8185
Map<int, ProfileFieldUserData>? profileData,
8286
}) {
8387
var effectiveDeliveryEmail = deliveryEmail ?? '[email protected]'; // TODO generate example emails
88+
_checkPositive(userId, 'user ID');
8489
return User(
8590
userId: userId ?? _nextUserId(),
8691
deliveryEmail: effectiveDeliveryEmail,
@@ -555,6 +560,7 @@ UpdateMessageFlagsRemoveEvent updateMessageFlagsRemoveEvent(
555560
Iterable<Message> messages, {
556561
int? selfUserId,
557562
}) {
563+
_checkPositive(selfUserId, 'user ID');
558564
return UpdateMessageFlagsRemoveEvent(
559565
id: 0,
560566
flag: flag,

test/model/autocomplete_test.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ void main() {
224224
test('MentionAutocompleteView yield between batches of 1000', () async {
225225
const narrow = ChannelNarrow(1);
226226
final store = eg.store();
227-
for (int i = 0; i < 2500; i++) {
227+
for (int i = 1; i <= 2500; i++) {
228228
await store.addUser(eg.user(userId: i, email: 'user$i@example.com', fullName: 'User $i'));
229229
}
230230
final view = MentionAutocompleteView.init(store: store, narrow: narrow);
@@ -247,7 +247,7 @@ void main() {
247247
test('MentionAutocompleteView new query during computation replaces old', () async {
248248
const narrow = ChannelNarrow(1);
249249
final store = eg.store();
250-
for (int i = 0; i < 1500; i++) {
250+
for (int i = 1; i <= 1500; i++) {
251251
await store.addUser(eg.user(userId: i, email: 'user$i@example.com', fullName: 'User $i'));
252252
}
253253
final view = MentionAutocompleteView.init(store: store, narrow: narrow);
@@ -258,7 +258,7 @@ void main() {
258258

259259
await Future(() {});
260260
check(done).isFalse();
261-
view.query = MentionAutocompleteQuery('User 0');
261+
view.query = MentionAutocompleteQuery('User 234');
262262

263263
// …new query goes through all batches
264264
await Future(() {});
@@ -267,22 +267,22 @@ void main() {
267267
check(done).isTrue(); // new result is set
268268
check(view.results).single
269269
.isA<UserMentionAutocompleteResult>()
270-
.userId.equals(0);
270+
.userId.equals(234);
271271

272272
// new result sticks; it isn't clobbered with old query's result
273273
for (int i = 0; i < 10; i++) { // for good measure
274274
await Future(() {});
275275
check(view.results).single
276276
.isA<UserMentionAutocompleteResult>()
277-
.userId.equals(0);
277+
.userId.equals(234);
278278
}
279279
});
280280

281281
test('MentionAutocompleteView mutating store.users while in progress does not '
282282
'prevent query from finishing', () async {
283283
const narrow = ChannelNarrow(1);
284284
final store = eg.store();
285-
for (int i = 0; i < 2500; i++) {
285+
for (int i = 1; i <= 2500; i++) {
286286
await store.addUser(eg.user(userId: i, email: 'user$i@example.com', fullName: 'User $i'));
287287
}
288288
final view = MentionAutocompleteView.init(store: store, narrow: narrow);

test/widgets/recent_dm_conversations_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ void main() {
8484
testWidgets('fling to scroll down', (tester) async {
8585
final List<User> users = [];
8686
final List<DmMessage> messages = [];
87-
for (int i = 0; i < 30; i++) {
87+
for (int i = 1; i <= 30; i++) {
8888
final user = eg.user(userId: i, fullName: 'User ${i.toString()}');
8989
users.add(user);
9090
messages.add(eg.dmMessage(from: eg.selfUser, to: [user]));
@@ -247,7 +247,7 @@ void main() {
247247
group('group', () {
248248
List<User> usersList(int count) {
249249
final result = <User>[];
250-
for (int i = 0; i < count; i++) {
250+
for (int i = 1; i <= count; i++) {
251251
result.add(eg.user(userId: i, fullName: 'User ${i.toString()}'));
252252
}
253253
return result;

0 commit comments

Comments
 (0)