Skip to content

Commit

Permalink
Make the userdir synced not rely on being able to search for yourself (
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkowl authored Mar 7, 2019
1 parent 379dfe9 commit 709fc84
Showing 1 changed file with 51 additions and 16 deletions.
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
);
})->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

0 comments on commit 709fc84

Please sign in to comment.