Skip to content

Commit 34da52f

Browse files
gnpricechrisbobbe
authored andcommitted
test: Use random topic in eg.streamMessage
This avoids a test accidentally coming to depend on the particular topic name that `eg.streamMessage` happens to choose by default. Discussed previously at: zulip#787 (comment) For convenience, we preserve the fact that successive calls to `eg.streamMessage` without a `topic` argument will get the same topic each time. (This saves various test cases from having to specify the topic just to ensure all their messages have some common topic.)
1 parent db7324b commit 34da52f

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

test/example_data.dart

+14-1
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,15 @@ int _lastMessageId = 1000;
320320

321321
const defaultStreamMessageStreamId = 123;
322322

323+
/// The default topic used by [streamMessage].
324+
///
325+
/// Tests generally shouldn't need this information directly.
326+
/// Instead, either
327+
/// * use [StreamMessage.topic] to read off an example message's topic;
328+
/// * or pick an example topic, and pass it both to [streamMessage]
329+
/// and wherever else the same topic is needed.
330+
final _defaultTopic = 'example topic ${Random().nextInt(1000)}';
331+
323332
/// Construct an example stream message.
324333
///
325334
/// If the message ID `id` is not given, it will be generated from a random
@@ -331,6 +340,10 @@ const defaultStreamMessageStreamId = 123;
331340
/// The message will be in `stream` if given. Otherwise,
332341
/// an example stream with ID `defaultStreamMessageStreamId` will be used.
333342
///
343+
/// If `topic` is not given, a default topic name is used.
344+
/// The default is randomly chosen, but remains the same
345+
/// for subsequent calls to this function.
346+
///
334347
/// See also:
335348
/// * [dmMessage], to construct an example direct message.
336349
StreamMessage streamMessage({
@@ -363,7 +376,7 @@ StreamMessage streamMessage({
363376
'flags': flags ?? [],
364377
'id': id ?? _nextMessageId(),
365378
'last_edit_timestamp': lastEditTimestamp,
366-
'subject': topic ?? 'example topic',
379+
'subject': topic ?? _defaultTopic,
367380
'submessages': submessages ?? [],
368381
'timestamp': timestamp ?? 1678139636,
369382
'type': 'stream',

0 commit comments

Comments
 (0)