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

Use correct start and stop to get the message #1083

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 30 additions & 8 deletions tests/10apidoc/34room-messages.pl
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ sub matrix_send_room_text_message
)
}

# This first sends a message, then does a /sync without since parameter.
# That /sync will most likely return the whole timeline for the room
# so we can't use it's prev_batch in the /messages API. So we send
# a 2nd message, and then do a /sync with since set to the previous
# /sync's next_batch. We can then fetch messages with the 2nd /sync's
# prev_batch that are before first /sync.
Comment on lines +131 to +136
Copy link
Member

Choose a reason for hiding this comment

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

normally we put this sort of comment inside the body of the test - see https://github.com/kroeckx/sytest/blob/room_message/tests/50federation/33room-get-missing-events.pl#L287-L303 for example. Please could you move it?

test "GET /rooms/:room_id/messages returns a message",
requires => [ local_user_and_room_fixtures(),
qw( can_send_message )],
Expand All @@ -138,12 +144,18 @@ sub matrix_send_room_text_message
my ( $user, $room_id ) = @_;

matrix_send_room_text_message( $user, $room_id,
body => "Here is the message content",
body => "Here is the first message",
)->then( sub {
matrix_sync( $user )
matrix_sync( $user );
})->then( sub {
matrix_send_room_text_message( $user, $room_id,
richvdh marked this conversation as resolved.
Show resolved Hide resolved
body => "Here is a second message",
)
})->then( sub {
matrix_sync_again( $user );
})->then( sub {
my ( $sync_body ) = @_;
my $token = $sync_body->{rooms}->{join}->{$room_id}->{timeline}->{prev_batch};
my $prev_batch = $sync_body->{rooms}->{join}->{$room_id}->{timeline}->{prev_batch};

do_request_json_for( $user,
method => "GET",
Expand All @@ -152,7 +164,7 @@ sub matrix_send_room_text_message
# With no params this does "forwards from END"; i.e. nothing useful
params => {
dir => "b",
from => $token,
from => $prev_batch,
},
)
})->then( sub {
Expand All @@ -164,6 +176,10 @@ sub matrix_send_room_text_message
scalar @{ $body->{chunk} } > 0 or
die "Expected some messages but got none at all\n";

assert_eq( $body->{chunk}[0]{type}, 'm.room.message');
assert_eq( $body->{chunk}[0]{content}{msgtype}, 'm.text');
assert_eq( $body->{chunk}[0]{content}{body}, 'Here is the first message');

Future->done(1);
});
};
Expand All @@ -176,12 +192,18 @@ sub matrix_send_room_text_message
my ( $user, $room_id ) = @_;

matrix_send_room_text_message( $user, $room_id,
body => "Here is the message content",
body => "Here is the first message",
)->then( sub {
matrix_sync( $user )
matrix_sync( $user );
})->then( sub {
matrix_send_room_text_message( $user, $room_id,
richvdh marked this conversation as resolved.
Show resolved Hide resolved
body => "Here is a second message",
)
})->then( sub {
matrix_sync_again( $user );
})->then( sub {
my ( $sync_body ) = @_;
my $token = $sync_body->{rooms}->{join}->{$room_id}->{timeline}->{prev_batch};
my $prev_batch = $sync_body->{rooms}->{join}->{$room_id}->{timeline}->{prev_batch};

do_request_json_for( $user,
method => "GET",
Expand All @@ -190,7 +212,7 @@ sub matrix_send_room_text_message
params => {
dir => "b",
filter => '{ "lazy_load_members" : true }',
from => $token,
from => $prev_batch,
},
)
})->then( sub {
Expand Down