Skip to content

test: Generate random, increasing user IDs for example data by default #425

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
Dec 1, 2023

Conversation

chrisbobbe
Copy link
Collaborator

Like we did for message IDs in 13e54f6.

This time there aren't any (or anyway I didn't find any) call sites where we could simply remove a userId argument and the test would still work. I've made the one simplification to a test that seemed very easy and minimal.

Copy link
Member

@gnprice gnprice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, this appears in the new revision of #410. :-) I guess it's convenient to use this separate PR to review it.

One small comment — then please go ahead and merge. Thanks!

Comment on lines 35 to 46
userId: userId ?? 123, // TODO generate example IDs
userId: userId ?? _nextUserId(), // TODO generate example IDs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This TODO is resolved now, I think :-)

Comment on lines +33 to +34
/// If user ID `userId` is not given, it will be generated from a random
/// but increasing sequence.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My first thought was that user IDs don't need to be ordered like message IDs do. But I guess when writing lists of users in a DM conversation one needs them sorted (unless using some function that does the sorting itself), so it's convenient for the order to be deterministic.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, yeah, I guess the ordering isn't even necessary for my use case in #410, which prompted this PR. The eg.users there aren't being used to identify a DM conversation.

But in #410 I did find it nicer to let the caller omit a user ID, and for that we needed eg.user() to give unique user IDs, and for that it was convenient to follow the pattern of message IDs in example_data.dart.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. If for something else we want to generate random distinct IDs without constraining the ordering, zulip-mobile has a handy example we can follow, implemented by Ray years ago.

(Rereading it, I guess it can't just be transcribed from JS to Dart, because it relies on JS's sparse arrays. But a sparse array is basically just a map with int keys, plus an int for the length.)

Like we did for message IDs in 13e54f6.

This time there aren't any (or anyway I didn't find any) call sites
where we could simply remove a `userId` argument and the test would
still work. I've made the one simplification to a test that seemed
very easy and minimal.
@chrisbobbe chrisbobbe force-pushed the pr-test-random-user-ids branch from 5745c8f to bb78e6c Compare December 1, 2023 21:22
@chrisbobbe chrisbobbe merged commit bb78e6c into zulip:main Dec 1, 2023
@chrisbobbe
Copy link
Collaborator Author

Thanks for the review! Merged, with that fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants