Skip to content

Commit

Permalink
Replace most non-synced actions (#1249)
Browse files Browse the repository at this point in the history
As explained in #1247, this PR changes most non-synced versions with the synced version.
matrix_create_room_synced now also returns the room alias.
  • Loading branch information
S7evinK authored Jun 17, 2022
1 parent 8212ee9 commit 4784b7e
Show file tree
Hide file tree
Showing 72 changed files with 397 additions and 422 deletions.
10 changes: 6 additions & 4 deletions tests/10apidoc/30room-create.pl
Original file line number Diff line number Diff line change
Expand Up @@ -419,14 +419,16 @@ sub remote_room_alias_fixture
=head2 matrix_create_room_synced
matrix_create_room_synced( $creator, %params )->then( sub {
my ( $room_id ) = @_;
my ( $room_id, $room_alias ) = @_;
});
Creates a new room, and waits for it to appear in the /sync response.
The parameters are passed through to C<matrix_create_room>.
The resultant future completes with the room_id.
The resultant future completes with the room_id and a room_alias. If
C<room_alias_name> is present in C<%params>, an alias will be built with the given
alias and user's server name. Otherwise, it will return C<undef>.
=cut

Expand All @@ -440,7 +442,7 @@ sub matrix_create_room_synced
# The easiest way to do that is to send a sentinel message in the room and wait for
# that to turn up.
matrix_create_room( $user, %params )->then( sub {
my ( $room_id ) = @_;
my ( $room_id, $room_alias ) = @_;

matrix_do_and_wait_for_sync( $user,
do => sub {
Expand All @@ -461,6 +463,6 @@ sub matrix_create_room_synced
$_[0]->{event_id} eq $event_id
});
},
)->then_done( $room_id );
)->then_done( $room_id, $room_alias );
});
}
2 changes: 1 addition & 1 deletion tests/10apidoc/31room-state.pl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
setup => sub {
my ( $user, $room_alias_name ) = @_;

matrix_create_room( $user,
matrix_create_room_synced( $user,
room_alias_name => $room_alias_name,
visibility => "public",
);
Expand Down
4 changes: 2 additions & 2 deletions tests/10apidoc/32room-alias.pl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
setup => sub {
my ( $user ) = @_;

matrix_create_room( $user )->then( sub {
matrix_create_room_synced( $user )->then( sub {
my ( $room_id, undef ) = @_;
Future->done( $room_id ); # Don't return the alias
});
Expand Down Expand Up @@ -56,7 +56,7 @@
my ( $user, $room_alias ) = @_;
my ( $room_id );

matrix_create_room( $user )->then( sub {
matrix_create_room_synced( $user )->then( sub {
( $room_id ) = @_;

# the list should be empty initially
Expand Down
8 changes: 4 additions & 4 deletions tests/10apidoc/33room-members.pl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
setup => sub {
my ( $user, $room_alias_name ) = @_;

matrix_create_room( $user,
matrix_create_room_synced( $user,
room_alias_name => $room_alias_name,
);
},
Expand Down Expand Up @@ -242,7 +242,7 @@ sub matrix_join_room
do => sub {
my ( $joiner_to_leave, $room_id, undef ) = @_;

matrix_join_room( $joiner_to_leave, $room_id )
matrix_join_room_synced( $joiner_to_leave, $room_id )
->then( sub {
do_request_json_for( $joiner_to_leave,
method => "POST",
Expand Down Expand Up @@ -401,7 +401,7 @@ sub _invite_users
Future->needs_all(
( map {
my $user = $_;
matrix_invite_user_to_room( $creator, $user, $room_id );
matrix_invite_user_to_room_synced( $creator, $user, $room_id );
} @other_members)
);
}
Expand Down Expand Up @@ -465,7 +465,7 @@ sub matrix_create_and_join_room
my $with_invite = delete $options{with_invite};
my $with_alias = delete $options{with_alias};

matrix_create_room( $creator,
matrix_create_room_synced( $creator,
%options,
room_alias_name => $room_alias_name,
)->then( sub {
Expand Down
4 changes: 2 additions & 2 deletions tests/10apidoc/34room-messages.pl
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ sub matrix_send_room_text_message
check => sub {
my ( $user, $room_id ) = @_;

matrix_send_room_text_message( $user, $room_id,
matrix_send_room_text_message_synced( $user, $room_id,
body => "Here is the message content",
)->then( sub {
matrix_sync( $user )
Expand Down Expand Up @@ -175,7 +175,7 @@ sub matrix_send_room_text_message
check => sub {
my ( $user, $room_id ) = @_;

matrix_send_room_text_message( $user, $room_id,
matrix_send_room_text_message_synced( $user, $room_id,
body => "Here is the message content",
)->then( sub {
matrix_sync( $user )
Expand Down
2 changes: 1 addition & 1 deletion tests/30rooms/01state.pl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
setup => sub {
my ( $user ) = @_;

matrix_create_room( $user,
matrix_create_room_synced( $user,
visibility => "public",
);
},
Expand Down
4 changes: 2 additions & 2 deletions tests/30rooms/02members-local.pl
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
Future->needs_all(
map { flush_events_for( $_ ) } $creator, $local_user
)->then( sub {
matrix_create_room( $creator )
matrix_create_room_synced( $creator )
})->then( sub {
my ( $room_id ) = @_;

matrix_join_room( $local_user, $room_id )
matrix_join_room_synced( $local_user, $room_id )
->then_done( $room_id );
});
},
Expand Down
4 changes: 2 additions & 2 deletions tests/30rooms/03members-remote.pl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
setup => sub {
my ( $user, $room_alias_name ) = @_;

matrix_create_room( $user,
matrix_create_room_synced( $user,
room_alias_name => $room_alias_name,
);
},
Expand Down Expand Up @@ -255,7 +255,7 @@
check => sub {
my ( $creator, $remote_user, $room_alias_name ) = @_;

matrix_create_room( $creator,
matrix_create_room_synced( $creator,
room_alias_name => $room_alias_name,
creation_content => {
"m.federate" => JSON::false,
Expand Down
8 changes: 4 additions & 4 deletions tests/30rooms/04messages.pl
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
my ( $user, $room_id ) = @_;

( repeat {
matrix_send_room_text_message( $user, $room_id,
matrix_send_room_text_message_synced( $user, $room_id,
body => "Message number $_[0]"
)
} foreach => [ 1 .. 20 ] )->then( sub {
Expand Down Expand Up @@ -276,13 +276,13 @@
my ( $creator, $room_id, $room_alias, $remote_user ) = @_;

( repeat {
matrix_send_room_text_message( $creator, $room_id,
matrix_send_room_text_message_synced( $creator, $room_id,
body => "Message number $_[0]"
)
} foreach => [ 1 .. 20 ] )->then( sub {
matrix_sync( $remote_user )
})->then( sub {
matrix_join_room( $remote_user, $room_alias );
matrix_join_room_synced( $remote_user, $room_alias );
})->then( sub {
# We wait until we see our join to the room.
await_sync_timeline_contains( $remote_user, $room_id, check => sub {
Expand Down Expand Up @@ -338,7 +338,7 @@
assert_eq( $chunk->[4]{content}{body}, "Message number 11",
'chunk[4] content body' );

matrix_send_room_text_message( $creator, $room_id,
matrix_send_room_text_message_synced( $creator, $room_id,
body => "Marker message"
)
})->then( sub {
Expand Down
6 changes: 3 additions & 3 deletions tests/30rooms/05aliases.pl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@

my ( $room_id, $room_alias );

matrix_create_room( $user,
matrix_create_room_synced( $user,
room_alias_name => $room_alias_name,
)->then( sub {
( $room_id, $room_alias ) = @_;
Expand Down Expand Up @@ -122,7 +122,7 @@

my ( $room_id, $room_alias );

matrix_create_room( $user,
matrix_create_room_synced( $user,
room_alias_name => $room_alias_name,
)->then( sub {
( $room_id, $room_alias ) = @_;
Expand Down Expand Up @@ -162,7 +162,7 @@
# Create a second room with an alias on it.
my $other_alias_name = $room_alias_name . "2";

matrix_create_room( $user,
matrix_create_room_synced( $user,
room_alias_name => $other_alias_name,
)->then( sub {
my ( $other_room_id, $other_room_alias ) = @_;
Expand Down
30 changes: 15 additions & 15 deletions tests/30rooms/06invite.pl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ sub inviteonly_room_fixture
setup => sub {
my ( $creator ) = @_;

matrix_create_room( $creator,
matrix_create_room_synced( $creator,
preset => "private_chat",
)->then( sub {
my ( $room_id ) = @_;
Expand Down Expand Up @@ -46,7 +46,7 @@ sub inviteonly_room_fixture
do => sub {
my ( $creator, $invitee, $room_id ) = @_;

matrix_invite_user_to_room( $creator, $invitee, $room_id )
matrix_invite_user_to_room_synced( $creator, $invitee, $room_id )
->SyTest::pass_on_done( "Sent invite" )
->then( sub {
await_sync( $invitee, check => sub {
Expand All @@ -57,7 +57,7 @@ sub inviteonly_room_fixture
return 1;
})
})->then( sub {
matrix_join_room( $invitee, $room_id )
matrix_join_room_synced( $invitee, $room_id )
->SyTest::pass_on_done( "Joined room" )
})->then( sub {
matrix_get_room_state( $invitee, $room_id,
Expand Down Expand Up @@ -194,13 +194,13 @@ sub invited_user_can_reject_invite_for_empty_room
{
my ( $invitee, $creator, $room_id ) = @_;

matrix_invite_user_to_room( $creator, $invitee, $room_id )
matrix_invite_user_to_room_synced( $creator, $invitee, $room_id )
->then( sub {
# wait for the leave to come down to make sure we're testing an empty room
matrix_leave_room_synced( $creator, $room_id )
})
->then( sub {
matrix_leave_room( $invitee, $room_id )
matrix_leave_room_synced( $invitee, $room_id )
})->then( sub {
matrix_sync( $invitee )
})->then( sub {
Expand All @@ -227,12 +227,12 @@ sub invited_user_can_reject_invite_for_empty_room
do => sub {
my ( $invitee, $creator, $room_id ) = @_;

matrix_invite_user_to_room( $creator, $invitee, $room_id )
matrix_invite_user_to_room_synced( $creator, $invitee, $room_id )
->then( sub {
# wait for the leave to come down to make sure we're testing an empty room
matrix_leave_room_synced( $creator, $room_id );
})->then( sub {
matrix_leave_room( $invitee, $room_id );
matrix_leave_room_synced( $invitee, $room_id );
})->then( sub {
# there's nobody left who can look at the room state, but the
# important thing is that a /sync for the invitee should not include
Expand Down Expand Up @@ -270,7 +270,7 @@ sub invited_user_can_reject_invite_for_empty_room
content => { url => "http://something" },
),
)->then( sub {
matrix_invite_user_to_room( $creator, $invitee, $room_id );
matrix_invite_user_to_room_synced( $creator, $invitee, $room_id );
})->then( sub {
await_sync( $invitee, check => sub {
my ( $body ) = @_;
Expand Down Expand Up @@ -406,7 +406,7 @@ sub invited_user_can_reject_invite_for_empty_room
do => sub {
my ( $creator, $room_id, $invitee ) = @_;

matrix_join_room( $invitee, $room_id )->then( sub {
matrix_join_room_synced( $invitee, $room_id )->then( sub {
matrix_invite_user_to_room( $creator, $invitee, $room_id )
->main::expect_http_403;
});
Expand All @@ -421,7 +421,7 @@ sub invited_user_can_reject_invite_for_empty_room

my $room_id;

matrix_create_room( $user_1 )
matrix_create_room_synced( $user_1 )
->SyTest::pass_on_done( "User A created a room" )
->then( sub {
( $room_id ) = @_;
Expand All @@ -432,7 +432,7 @@ sub invited_user_can_reject_invite_for_empty_room
)->SyTest::pass_on_done( "User A set the join rules to 'invite'" )
})->then( sub {

matrix_invite_user_to_room( $user_1, $user_2, $room_id )
matrix_invite_user_to_room_synced( $user_1, $user_2, $room_id )
->SyTest::pass_on_done( "User A invited user B" )
})->then( sub {

Expand All @@ -444,7 +444,7 @@ sub invited_user_can_reject_invite_for_empty_room
})->SyTest::pass_on_done( "User B received the invite from A" )
})->then( sub {

matrix_join_room( $user_2, $room_id )
matrix_join_room_synced( $user_2, $room_id )
->SyTest::pass_on_done( "User B joined the room" )
})->then( sub {

Expand All @@ -455,7 +455,7 @@ sub invited_user_can_reject_invite_for_empty_room
})->SyTest::pass_on_done( "User A set user B's power level to 100" )
})->then( sub {

matrix_leave_room( $user_1, $room_id )
matrix_leave_room_synced( $user_1, $room_id )
->SyTest::pass_on_done( "User A left the room" )
})->then( sub {
await_sync_timeline_contains( $user_2, $room_id, check => sub {
Expand All @@ -465,7 +465,7 @@ sub invited_user_can_reject_invite_for_empty_room
})->SyTest::pass_on_done( "User B received the leave event" )
})->then( sub {

matrix_invite_user_to_room( $user_2, $user_1, $room_id )
matrix_invite_user_to_room_synced( $user_2, $user_1, $room_id )
->SyTest::pass_on_done( "User B invited user A back to the room" )
})->then( sub {

Expand All @@ -478,7 +478,7 @@ sub invited_user_can_reject_invite_for_empty_room
})->then( sub {

retry_until_success {
matrix_join_room( $user_1, $room_id )
matrix_join_room_synced( $user_1, $room_id )
}->SyTest::pass_on_done( "User A joined the room" )
})->then_done(1);
};
2 changes: 1 addition & 1 deletion tests/30rooms/08levels.pl
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ sub test_powerlevel
## try => sub {
## my ( $test_user, $room_id ) = @_;
##
## matrix_invite_user_to_room( $test_user, '@random-invitee:$BIND_HOST:8001', $room_id );
## matrix_invite_user_to_room_synced( $test_user, '@random-invitee:$BIND_HOST:8001', $room_id );
## };

test_powerlevel "setting 'm.room.name' respects room powerlevel",
Expand Down
4 changes: 2 additions & 2 deletions tests/30rooms/09eventstream.pl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
my $room_id;

# Have Alice create a new private room
matrix_create_room( $alice,
matrix_create_room_synced( $alice,
visibility => "private",
)->SyTest::pass_on_done( "Created a room" )
->then( sub {
Expand Down Expand Up @@ -52,7 +52,7 @@
my ( $user ) = @_;
my ( $room_id, @expected_event_ids );

matrix_create_room( $user,
matrix_create_room_synced( $user,
visibility => "private",
)
->then( sub {
Expand Down
2 changes: 1 addition & 1 deletion tests/30rooms/10redactions.pl
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ sub matrix_redact_event_synced
do => sub {
my ( $user1, $room1, $user2, $room2 ) = @_;

matrix_send_room_text_message( $user1, $room1,
matrix_send_room_text_message_synced( $user1, $room1,
body => "test"
)->then( sub {
my ( $event_id ) = @_;
Expand Down
Loading

0 comments on commit 4784b7e

Please sign in to comment.