Skip to content
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

Make the userdir synced not rely on being able to search for yourself #567

Merged
merged 12 commits into from
Mar 7, 2019
67 changes: 51 additions & 16 deletions tests/52user-directory/01public.pl
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,30 @@
check => sub {
my ( $user ) = @_;

my $room_id;
my $searching_user;

my $displayname = generate_random_displayname();
my $searching_displayname = generate_random_displayname();

matrix_set_displayname( $user, $displayname )
->then( sub {
matrix_create_user_on_server( $user->http,
displayname => $searching_displayname
Copy link
Member

Choose a reason for hiding this comment

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

nit: trailing commas are nice

);
})->then( sub {
( $searching_user ) = @_;

matrix_create_room( $user,
preset => "public_chat",
);
})->then( sub {
( $room_id ) = @_;

my ( $room_id ) = @_;
matrix_join_room( $searching_user, $room_id );
})->then( sub {
repeat_until_true {
do_request_json_for( $user,
do_request_json_for( $searching_user,
method => "POST",
uri => "/unstable/user_directory/search",
uri => "/r0/user_directory/search",
content => {
search_term => $displayname,
}
Expand All @@ -43,19 +51,23 @@
check => sub {
my ( $user ) = @_;

my $room_id;
my $searching_user;

my $displayname = generate_random_displayname();
my $searching_displayname = generate_random_displayname();

matrix_set_displayname( $user, $displayname )->then( sub {
matrix_create_user_on_server( $user->http,
displayname => $searching_displayname
);
})->then( sub {
( $searching_user ) = @_;

matrix_set_displayname( $user, $displayname )
->then( sub {
matrix_create_room( $user,
preset => "private_chat",
);
})->then( sub {
( $room_id ) = @_;

matrix_get_user_dir_synced( $user, $displayname );
matrix_get_user_dir_synced( $searching_user, $displayname );
})->then( sub {
my ( $body ) = @_;
my $results = $body->{results};
Expand Down Expand Up @@ -384,12 +396,20 @@
my ( $user ) = @_;

my $room_id;
my $searching_user;

my $displayname = generate_random_displayname();
my $second_displayname = generate_random_displayname();
my $searching_displayname = generate_random_displayname();

matrix_set_displayname( $user, $displayname )
->then( sub {
matrix_create_user_on_server( $user->http,
displayname => $searching_displayname
);
}) -> then( sub {
( $searching_user ) = @_;

log_if_fail "First displayname", $displayname;

matrix_create_room( $user,
Expand All @@ -398,6 +418,8 @@
})->then( sub {
( $room_id ) = @_;

matrix_join_room( $searching_user, $room_id );
})->then( sub {
matrix_get_user_dir_synced( $user, $displayname );
})->then( sub {
my ( $body ) = @_;
Expand Down Expand Up @@ -435,30 +457,43 @@ sub generate_random_displayname
}


# Get the user direectory after a change has been made. This creates a new user
# and then polls the user directory until we see it. This is to get around the
# Get the user directory after a change has been made. This creates two new users
# and then polls the user directory until one sees the other. This is to get around the
# fact that the user directory gets updated asynchronously.
sub matrix_get_user_dir_synced
{
my ( $user, $search_term ) = @_;

my $new_user;
my $searching_user;
my $room_id;

my $random_id = join "", map { chr 65 + rand 26 } 1 .. 20;
my $searching_random_id = join "", map { chr 65 + rand 26 } 1 .. 20;

matrix_create_user_on_server( $user->http,
displayname => $random_id
)->then( sub {
( $new_user ) = @_;

matrix_create_user_on_server( $user->http,
displayname => $searching_random_id
);
}) -> then( sub {
( $searching_user ) = @_;

matrix_create_room( $new_user,
preset => "public_chat",
);
})->then( sub {
( $room_id ) = @_;

matrix_join_room( $searching_user, $room_id );
})->then( sub {
repeat_until_true {
do_request_json_for( $new_user,
do_request_json_for( $searching_user,
method => "POST",
uri => "/unstable/user_directory/search",
uri => "/r0/user_directory/search",
content => {
search_term => $random_id,
}
Expand All @@ -474,7 +509,7 @@ sub matrix_get_user_dir_synced
})->then( sub {
do_request_json_for( $user,
method => "POST",
uri => "/unstable/user_directory/search",
uri => "/r0/user_directory/search",
content => {
search_term => $search_term,
}
Expand Down