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

Add some basic read marker tests #433

Merged
merged 1 commit into from
Mar 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
61 changes: 61 additions & 0 deletions tests/10apidoc/38room-read-marker.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
test "POST /rooms/:room_id/read_markers can create read marker",
requires => [ local_user_and_room_fixtures() ],

proves => [qw( can_post_room_markers )],

do => sub {
my ( $user, $room_id ) = @_;

# We need an event ID in the room. The ID of our own member event seems
# reasonable. Lets fetch it.
matrix_get_my_member_event( $user, $room_id )->then( sub {
my ( $member_event ) = @_;
my $event_id = $member_event->{event_id};

do_request_json_for( $user,
method => "POST",
uri => "/r0/rooms/$room_id/read_markers",

content => {
"m.fully_read" => $event_id,
},
);
})->then_done(1);
};


push our @EXPORT, qw( matrix_advance_room_read_marker matrix_advance_room_read_marker_synced );

sub matrix_advance_room_read_marker
{
my ( $user, $room_id, $event_id ) = @_;

do_request_json_for( $user,
method => "POST",
uri => "/r0/rooms/$room_id/read_markers",

content => {
"m.fully_read" => $event_id,
},
)->then_done();
}

sub matrix_advance_room_read_marker_synced
{
my ( $user, $room_id, $event_id ) = @_;

matrix_do_and_wait_for_sync( $user,
do => sub {
matrix_advance_room_read_marker( $user, $room_id, $event_id );
},
check => sub {
sync_room_contains( $_[0], $room_id, "account_data", sub {
my ( $read_marker ) = @_;

log_if_fail "Read marker", $read_marker;
$read_marker->{type} eq "m.fully_read" and
$read_marker->{content}{event_id} eq $event_id;
});
},
);
}
84 changes: 84 additions & 0 deletions tests/31sync/14read-markers.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
test "Read markers appear in incremental v2 /sync",
requires => [ local_user_fixture(), qw( can_sync ) ],

check => sub {
my ( $user ) = @_;

my ( $room_id, $event_id );

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

matrix_send_room_text_message( $user, $room_id, body => "hello" );
})->then( sub {
( $event_id ) = @_;

matrix_advance_room_read_marker_synced( $user, $room_id, $event_id );
})->then_done(1);
};


test "Read markers appear in initial v2 /sync",
requires => [ local_user_fixture(), qw( can_sync ) ],

check => sub {
my ( $user ) = @_;

my ( $room_id, $event_id );

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

matrix_send_room_text_message( $user, $room_id, body => "hello" );
})->then( sub {
( $event_id ) = @_;

matrix_advance_room_read_marker_synced( $user, $room_id, $event_id );
})->then( sub {
matrix_sync( $user );
})->then( sub {
my ( $body ) = @_;

my $room = $body->{rooms}{join}{$room_id};

my $account_data = $room->{account_data}{events};

@{ $account_data } == 1 or die "Expected a m.fully_read event";

log_if_fail "Account data:", $account_data;

my $read_marker = $account_data->[0];

$read_marker->{type} eq "m.fully_read" or die "Unexpected event type";
$read_marker->{content}{event_id} eq $event_id
or die "Expected to see a marker for $event_id";

Future->done(1);
});
};


test "Read markers can be updated",
requires => [ local_user_fixture(), qw( can_sync ) ],

check => sub {
my ( $user ) = @_;

my ( $room_id, $event_id );

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

matrix_send_room_text_message( $user, $room_id, body => "hello" );
})->then( sub {
( $event_id ) = @_;

matrix_advance_room_read_marker_synced( $user, $room_id, $event_id );
})->then( sub {
matrix_send_room_text_message( $user, $room_id, body => "hello2" );
})->then( sub {
( $event_id ) = @_;

matrix_advance_room_read_marker_synced( $user, $room_id, $event_id );
})->then_done(1);
};